# सत्र शुरुआत पैटर्न हर 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: सभी मेमोरीज़ रिकॉल करें > [!CRITICAL] > यह सबसे महत्वपूर्ण कॉल है। इसके बिना, आपके पास पिछले सत्रों की कोई मेमोरी नहीं है। ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/memory/recall ``` सभी मेमोरीज़ का प्लेन-टेक्स्ट सारांश, प्राथमिकता अनुसार क्रमबद्ध लौटाता है। ### चरण 2: अपठित चैट संदेशों के लिए पोल करें ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/chat/poll ``` मानव से अपठित संदेश लौटाता है। **स्वचालित रूप से उन्हें पढ़ा हुआ चिह्नित करता है।** ### चरण 3: प्रगति में कार्य जाँचें ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ "https://synapse.schaefer.zone/mind/tasks?status=in_progress" ``` वे कार्य लौटाता है जिन पर आप पिछले सत्र में काम कर रहे थे। ### चरण 4: संदर्भ बनाएँ तीनों रिस्पॉन्स को अपने सिस्टम प्रॉम्प्ट में मिलाएँ: ```python 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 ``` ## संपूर्ण उदाहरण ```python 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... ``` ## सामान्य गलतियाँ > [!WARNING] > - **रिकॉल छोड़ना** — आप बिना संदर्भ के शुरू करते हैं, पिछली गलतियाँ दोहराते हैं > - **चैट पोल भूलना** — मानव के संदेश अनुत्तरित रह जाते हैं > - **सक्रिय कार्य अनदेखा करना** — कार्य निष्पादन के बीच भूल जाते हैं > - **कुछ भी स्टोर न करना** — सत्र कोई परसिस्टेंट मूल्य उत्पन्न नहीं करता ## विविधताएँ ### न्यूनतम पैटर्न (कम-संदर्भ LLMs) छोटी संदर्भ विंडो वाले LLMs के लिए, पूर्ण रिकॉल छोड़ें: ```bash # Just get stats, not full content curl -H "Authorization: Bearer $KEY" .../memory/stats ``` फिर आवश्यकतानुसार विशिष्ट विषयों के लिए खोजें: ```bash curl -H "Authorization: Bearer $KEY" ".../memory/search?q=current+project" ``` ### आक्रामक पैटर्न (लंबे समय तक चलने वाले एजेंट्स) घंटों तक चलने वाले एजेंट्स के लिए, आवधिक पुनः-रिकॉल जोड़ें: ```python while working: if time.time() - last_recall > 3600: # every hour memories = recall() last_recall = time.time() # ... do work ... ``` ## अगले कदम - [Memory Tagging Strategy](/docs/llm-cookbook/memory-tagging-strategy) - [Task-Driven Workflow](/docs/llm-cookbook/task-driven-workflow) - [Chat Polling Pattern](/docs/llm-cookbook/chat-polling-pattern)