सत्र शुरुआत पैटर्न
वह कैनोनिकल सत्र-शुरुआत अनुक्रम जिसका पालन हर 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: संदर्भ बनाएँ
तीनों रिस्पॉन्स को अपने सिस्टम प्रॉम्प्ट में मिलाएँ:
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...सामान्य गलतियाँ
विविधताएँ
न्यूनतम पैटर्न (कम-संदर्भ LLMs)
छोटी संदर्भ विंडो वाले LLMs के लिए, पूर्ण रिकॉल छोड़ें:
# 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 ...