セッション開始パターン
すべての LLM エージェントが従うべき標準的なセッション開始シーケンス。
セッション開始パターン
すべての LLM エージェントセッションはこの標準的なスタートアップシーケンスに従うべきです。ステップを省略すると、コンテキストの喪失、メッセージの見逃し、タスクの忘れにつながります。
パターン
1. Recall all memories
2. Poll for unread chat messages
3. Check in-progress tasks
4. Build context from results
5. Process pending items before new work実装
ステップ 1:すべてのメモリをリコール
これが最も重要な呼び出しです。これがないと、過去のセッションの記憶がありません。
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
https://synapse.schaefer.zone/memory/recallすべてのメモリのプレーンテキストサマリーを優先度順で返します。
ステップ 2:未読チャットメッセージをポーリング
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
https://synapse.schaefer.zone/chat/poll人間からの未読メッセージを返します。自動的に既読にします。
ステップ 3:進行中のタスクを確認
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
"https://synapse.schaefer.zone/mind/tasks?status=in_progress"前回のセッションで作業していたタスクを返します。
ステップ 4:コンテキストを構築
3 つのレスポンスをシステムプロンプトにまとめます:
def build_context(memories, messages, tasks):
context = f"""# SESSION CONTEXT
## Memories (from previous sessions)
{memories}
## Unread Messages from Human
{format_messages(messages)}
## Active Tasks
{format_tasks(tasks)}
## Instructions
- Address unread messages first
- Resume active tasks before starting new work
- Store new learnings as they happen (POST /memory)
- Poll for new messages every 30-60 seconds
"""
return contextステップ 5:保留中の項目を処理
For each unread message:
- Acknowledge receipt (POST /chat/reply)
- Address the message content
- Store any new commitments as memories
For each in-progress task:
- Recall why you were working on it
- Continue from where you left off
- Update task status as you progress完全な例
import os
import requests
URL = "https://synapse.schaefer.zone"
KEY = os.environ["SYNAPSE_MIND_KEY"]
def session_start():
"""Canonical session start sequence."""
headers = {"Authorization": f"Bearer {KEY}"}
# 1. Recall memories
r = requests.get(f"{URL}/memory/recall", headers=headers)
memories = r.text
# 2. Poll chat
r = requests.get(f"{URL}/chat/poll", headers=headers)
messages = r.json().get("messages", [])
# 3. Check tasks
r = requests.get(f"{URL}/mind/tasks?status=in_progress", headers=headers)
tasks = r.json().get("tasks", [])
# 4. Build context
context = f"""You are a Synapse-enabled AI assistant.
MEMORIES FROM PREVIOUS SESSIONS:
{memories}
UNREAD MESSAGES FROM HUMAN:
{chr(10).join(f'- {m["content"]}' for m in messages) or 'None'}
ACTIVE TASKS:
{chr(10).join(f'- [{t["id"]}] {t["title"]}: {t.get("description", "")}' for t in tasks) or 'None'}
INSTRUCTIONS:
1. Acknowledge each unread message
2. Resume active tasks
3. Store new learnings via POST /memory
4. Poll /chat/poll every 30-60 seconds
"""
return context
# At session start
system_prompt = session_start()
# Pass to LLM...よくある間違い
バリエーション
最小パターン(低コンテキスト LLM)
コンテキストウィンドウが小さい LLM の場合、完全なリコールを省略します:
# Just get stats, not full content
curl -H "Authorization: Bearer $KEY" .../memory/stats必要に応じて特定のトピックを検索します:
curl -H "Authorization: Bearer $KEY" ".../memory/search?q=current+project"積極的パターン(長時間実行エージェント)
数時間動くエージェントには、定期的な再リコールを追加します:
while working:
if time.time() - last_recall > 3600: # every hour
memories = recall()
last_recall = time.time()
# ... do work ...