{"title":"सत्र शुरुआत पैटर्न","slug":"session-start-pattern","category":"llm-cookbook","summary":"वह कैनोनिकल सत्र-शुरुआत अनुक्रम जिसका पालन हर LLM एजेंट को करना चाहिए।","audience":["llm"],"tags":["cookbook","session","pattern","startup"],"difficulty":"beginner","updated":"2026-06-27","word_count":268,"read_minutes":1,"llm_context":"ALWAYS at session start: 1) GET /memory/recall, 2) GET /chat/poll, 3) GET /mind/tasks?status=in_progress\nBuild system prompt from recall output.\nProcess unread chat messages before doing new work.\nResume any in_progress tasks before starting new ones.\nStore new learnings as they happen — don't wait until session end.\n","lang":"hi","translated":true,"requested_lang":"hi","content_markdown":"\n# सत्र शुरुआत पैटर्न\n\nहर LLM एजेंट सत्र को इस कैनोनिकल स्टार्टअप अनुक्रम का पालन करना चाहिए। चरण छोड़ने से संदर्भ खो जाता है, संदेश छूट जाते हैं, और कार्य भूल जाते हैं।\n\n## पैटर्न\n\n```\n1. Recall all memories\n2. Poll for unread chat messages\n3. Check in-progress tasks\n4. Build context from results\n5. Process pending items before new work\n```\n\n## कार्यान्वयन\n\n### चरण 1: सभी मेमोरीज़ रिकॉल करें\n\n> [!CRITICAL]\n> यह सबसे महत्वपूर्ण कॉल है। इसके बिना, आपके पास पिछले सत्रों की कोई मेमोरी नहीं है।\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/memory/recall\n```\n\nसभी मेमोरीज़ का प्लेन-टेक्स्ट सारांश, प्राथमिकता अनुसार क्रमबद्ध लौटाता है।\n\n### चरण 2: अपठित चैट संदेशों के लिए पोल करें\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/chat/poll\n```\n\nमानव से अपठित संदेश लौटाता है। **स्वचालित रूप से उन्हें पढ़ा हुआ चिह्नित करता है।**\n\n### चरण 3: प्रगति में कार्य जाँचें\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     \"https://synapse.schaefer.zone/mind/tasks?status=in_progress\"\n```\n\nवे कार्य लौटाता है जिन पर आप पिछले सत्र में काम कर रहे थे।\n\n### चरण 4: संदर्भ बनाएँ\n\nतीनों रिस्पॉन्स को अपने सिस्टम प्रॉम्प्ट में मिलाएँ:\n\n```python\ndef build_context(memories, messages, tasks):\n    context = f\"\"\"# SESSION CONTEXT\n\n## Memories (from previous sessions)\n{memories}\n\n## Unread Messages from Human\n{format_messages(messages)}\n\n## Active Tasks\n{format_tasks(tasks)}\n\n## Instructions\n- Address unread messages first\n- Resume active tasks before starting new work\n- Store new learnings as they happen (POST /memory)\n- Poll for new messages every 30-60 seconds\n\"\"\"\n    return context\n```\n\n### चरण 5: लंबित आइटम प्रोसेस करें\n\n```\nFor each unread message:\n  - Acknowledge receipt (POST /chat/reply)\n  - Address the message content\n  - Store any new commitments as memories\n\nFor each in-progress task:\n  - Recall why you were working on it\n  - Continue from where you left off\n  - Update task status as you progress\n```\n\n## संपूर्ण उदाहरण\n\n```python\nimport os\nimport requests\n\nURL = \"https://synapse.schaefer.zone\"\nKEY = os.environ[\"SYNAPSE_MIND_KEY\"]\n\ndef session_start():\n    \"\"\"Canonical session start sequence.\"\"\"\n    headers = {\"Authorization\": f\"Bearer {KEY}\"}\n    \n    # 1. Recall memories\n    r = requests.get(f\"{URL}/memory/recall\", headers=headers)\n    memories = r.text\n    \n    # 2. Poll chat\n    r = requests.get(f\"{URL}/chat/poll\", headers=headers)\n    messages = r.json().get(\"messages\", [])\n    \n    # 3. Check tasks\n    r = requests.get(f\"{URL}/mind/tasks?status=in_progress\", headers=headers)\n    tasks = r.json().get(\"tasks\", [])\n    \n    # 4. Build context\n    context = f\"\"\"You are a Synapse-enabled AI assistant.\n\nMEMORIES FROM PREVIOUS SESSIONS:\n{memories}\n\nUNREAD MESSAGES FROM HUMAN:\n{chr(10).join(f'- {m[\"content\"]}' for m in messages) or 'None'}\n\nACTIVE TASKS:\n{chr(10).join(f'- [{t[\"id\"]}] {t[\"title\"]}: {t.get(\"description\", \"\")}' for t in tasks) or 'None'}\n\nINSTRUCTIONS:\n1. Acknowledge each unread message\n2. Resume active tasks\n3. Store new learnings via POST /memory\n4. Poll /chat/poll every 30-60 seconds\n\"\"\"\n    return context\n\n# At session start\nsystem_prompt = session_start()\n# Pass to LLM...\n```\n\n## सामान्य गलतियाँ\n\n> [!WARNING]\n> - **रिकॉल छोड़ना** — आप बिना संदर्भ के शुरू करते हैं, पिछली गलतियाँ दोहराते हैं\n> - **चैट पोल भूलना** — मानव के संदेश अनुत्तरित रह जाते हैं\n> - **सक्रिय कार्य अनदेखा करना** — कार्य निष्पादन के बीच भूल जाते हैं\n> - **कुछ भी स्टोर न करना** — सत्र कोई परसिस्टेंट मूल्य उत्पन्न नहीं करता\n\n## विविधताएँ\n\n### न्यूनतम पैटर्न (कम-संदर्भ LLMs)\n\nछोटी संदर्भ विंडो वाले LLMs के लिए, पूर्ण रिकॉल छोड़ें:\n\n```bash\n# Just get stats, not full content\ncurl -H \"Authorization: Bearer $KEY\" .../memory/stats\n```\n\nफिर आवश्यकतानुसार विशिष्ट विषयों के लिए खोजें:\n\n```bash\ncurl -H \"Authorization: Bearer $KEY\" \".../memory/search?q=current+project\"\n```\n\n### आक्रामक पैटर्न (लंबे समय तक चलने वाले एजेंट्स)\n\nघंटों तक चलने वाले एजेंट्स के लिए, आवधिक पुनः-रिकॉल जोड़ें:\n\n```python\nwhile working:\n    if time.time() - last_recall > 3600:  # every hour\n        memories = recall()\n        last_recall = time.time()\n    # ... do work ...\n```\n\n## अगले कदम\n\n- [Memory Tagging Strategy](/docs/llm-cookbook/memory-tagging-strategy)\n- [Task-Driven Workflow](/docs/llm-cookbook/task-driven-workflow)\n- [Chat Polling Pattern](/docs/llm-cookbook/chat-polling-pattern)\n","content_html":"<h1>सत्र शुरुआत पैटर्न</h1>\n<p>हर LLM एजेंट सत्र को इस कैनोनिकल स्टार्टअप अनुक्रम का पालन करना चाहिए। चरण छोड़ने से संदर्भ खो जाता है, संदेश छूट जाते हैं, और कार्य भूल जाते हैं।</p>\n<h2>पैटर्न</h2>\n<pre><code class=\"hljs language-plaintext\">1. Recall all memories\n2. Poll for unread chat messages\n3. Check in-progress tasks\n4. Build context from results\n5. Process pending items before new work</code></pre><h2>कार्यान्वयन</h2>\n<h3>चरण 1: सभी मेमोरीज़ रिकॉल करें</h3>\n<div class=\"callout callout-critical\">यह सबसे महत्वपूर्ण कॉल है। इसके बिना, आपके पास पिछले सत्रों की कोई मेमोरी नहीं है।</div><pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/memory/recall</code></pre><p>सभी मेमोरीज़ का प्लेन-टेक्स्ट सारांश, प्राथमिकता अनुसार क्रमबद्ध लौटाता है।</p>\n<h3>चरण 2: अपठित चैट संदेशों के लिए पोल करें</h3>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/chat/poll</code></pre><p>मानव से अपठित संदेश लौटाता है। <strong>स्वचालित रूप से उन्हें पढ़ा हुआ चिह्नित करता है।</strong></p>\n<h3>चरण 3: प्रगति में कार्य जाँचें</h3>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/mind/tasks?status=in_progress&quot;</span></code></pre><p>वे कार्य लौटाता है जिन पर आप पिछले सत्र में काम कर रहे थे।</p>\n<h3>चरण 4: संदर्भ बनाएँ</h3>\n<p>तीनों रिस्पॉन्स को अपने सिस्टम प्रॉम्प्ट में मिलाएँ:</p>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">build_context</span>(<span class=\"hljs-params\">memories, messages, tasks</span>):\n    context = <span class=\"hljs-string\">f&quot;&quot;&quot;# SESSION CONTEXT\n\n## Memories (from previous sessions)\n<span class=\"hljs-subst\">{memories}</span>\n\n## Unread Messages from Human\n<span class=\"hljs-subst\">{format_messages(messages)}</span>\n\n## Active Tasks\n<span class=\"hljs-subst\">{format_tasks(tasks)}</span>\n\n## Instructions\n- Address unread messages first\n- Resume active tasks before starting new work\n- Store new learnings as they happen (POST /memory)\n- Poll for new messages every 30-60 seconds\n&quot;&quot;&quot;</span>\n    <span class=\"hljs-keyword\">return</span> context</code></pre><h3>चरण 5: लंबित आइटम प्रोसेस करें</h3>\n<pre><code class=\"hljs language-plaintext\">For each unread message:\n  - Acknowledge receipt (POST /chat/reply)\n  - Address the message content\n  - Store any new commitments as memories\n\nFor each in-progress task:\n  - Recall why you were working on it\n  - Continue from where you left off\n  - Update task status as you progress</code></pre><h2>संपूर्ण उदाहरण</h2>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import</span> os\n<span class=\"hljs-keyword\">import</span> requests\n\nURL = <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone&quot;</span>\nKEY = os.environ[<span class=\"hljs-string\">&quot;SYNAPSE_MIND_KEY&quot;</span>]\n\n<span class=\"hljs-keyword\">def</span> <span class=\"hljs-title function_\">session_start</span>():\n    <span class=\"hljs-string\">&quot;&quot;&quot;Canonical session start sequence.&quot;&quot;&quot;</span>\n    headers = {<span class=\"hljs-string\">&quot;Authorization&quot;</span>: <span class=\"hljs-string\">f&quot;Bearer <span class=\"hljs-subst\">{KEY}</span>&quot;</span>}\n    \n    <span class=\"hljs-comment\"># 1. Recall memories</span>\n    r = requests.get(<span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/memory/recall&quot;</span>, headers=headers)\n    memories = r.text\n    \n    <span class=\"hljs-comment\"># 2. Poll chat</span>\n    r = requests.get(<span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/chat/poll&quot;</span>, headers=headers)\n    messages = r.json().get(<span class=\"hljs-string\">&quot;messages&quot;</span>, [])\n    \n    <span class=\"hljs-comment\"># 3. Check tasks</span>\n    r = requests.get(<span class=\"hljs-string\">f&quot;<span class=\"hljs-subst\">{URL}</span>/mind/tasks?status=in_progress&quot;</span>, headers=headers)\n    tasks = r.json().get(<span class=\"hljs-string\">&quot;tasks&quot;</span>, [])\n    \n    <span class=\"hljs-comment\"># 4. Build context</span>\n    context = <span class=\"hljs-string\">f&quot;&quot;&quot;You are a Synapse-enabled AI assistant.\n\nMEMORIES FROM PREVIOUS SESSIONS:\n<span class=\"hljs-subst\">{memories}</span>\n\nUNREAD MESSAGES FROM HUMAN:\n<span class=\"hljs-subst\">{<span class=\"hljs-built_in\">chr</span>(<span class=\"hljs-number\">10</span>).join(<span class=\"hljs-string\">f&#x27;- <span class=\"hljs-subst\">{m[<span class=\"hljs-string\">&quot;content&quot;</span>]}</span>&#x27;</span> <span class=\"hljs-keyword\">for</span> m <span class=\"hljs-keyword\">in</span> messages) <span class=\"hljs-keyword\">or</span> <span class=\"hljs-string\">&#x27;None&#x27;</span>}</span>\n\nACTIVE TASKS:\n<span class=\"hljs-subst\">{<span class=\"hljs-built_in\">chr</span>(<span class=\"hljs-number\">10</span>).join(<span class=\"hljs-string\">f&#x27;- [<span class=\"hljs-subst\">{t[<span class=\"hljs-string\">&quot;id&quot;</span>]}</span>] <span class=\"hljs-subst\">{t[<span class=\"hljs-string\">&quot;title&quot;</span>]}</span>: <span class=\"hljs-subst\">{t.get(<span class=\"hljs-string\">&quot;description&quot;</span>, <span class=\"hljs-string\">&quot;&quot;</span>)}</span>&#x27;</span> <span class=\"hljs-keyword\">for</span> t <span class=\"hljs-keyword\">in</span> tasks) <span class=\"hljs-keyword\">or</span> <span class=\"hljs-string\">&#x27;None&#x27;</span>}</span>\n\nINSTRUCTIONS:\n1. Acknowledge each unread message\n2. Resume active tasks\n3. Store new learnings via POST /memory\n4. Poll /chat/poll every 30-60 seconds\n&quot;&quot;&quot;</span>\n    <span class=\"hljs-keyword\">return</span> context\n\n<span class=\"hljs-comment\"># At session start</span>\nsystem_prompt = session_start()\n<span class=\"hljs-comment\"># Pass to LLM...</span></code></pre><h2>सामान्य गलतियाँ</h2>\n<div class=\"callout callout-warn\"></div><h2>विविधताएँ</h2>\n<h3>न्यूनतम पैटर्न (कम-संदर्भ LLMs)</h3>\n<p>छोटी संदर्भ विंडो वाले LLMs के लिए, पूर्ण रिकॉल छोड़ें:</p>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Just get stats, not full content</span>\ncurl -H <span class=\"hljs-string\">&quot;Authorization: Bearer <span class=\"hljs-variable\">$KEY</span>&quot;</span> .../memory/stats</code></pre><p>फिर आवश्यकतानुसार विशिष्ट विषयों के लिए खोजें:</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer <span class=\"hljs-variable\">$KEY</span>&quot;</span> <span class=\"hljs-string\">&quot;.../memory/search?q=current+project&quot;</span></code></pre><h3>आक्रामक पैटर्न (लंबे समय तक चलने वाले एजेंट्स)</h3>\n<p>घंटों तक चलने वाले एजेंट्स के लिए, आवधिक पुनः-रिकॉल जोड़ें:</p>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-keyword\">while</span> working:\n    <span class=\"hljs-keyword\">if</span> time.time() - last_recall &gt; <span class=\"hljs-number\">3600</span>:  <span class=\"hljs-comment\"># every hour</span>\n        memories = recall()\n        last_recall = time.time()\n    <span class=\"hljs-comment\"># ... do work ...</span></code></pre><h2>अगले कदम</h2>\n<ul>\n<li><a href=\"/docs/llm-cookbook/memory-tagging-strategy\">Memory Tagging Strategy</a></li>\n<li><a href=\"/docs/llm-cookbook/task-driven-workflow\">Task-Driven Workflow</a></li>\n<li><a href=\"/docs/llm-cookbook/chat-polling-pattern\">Chat Polling Pattern</a></li>\n</ul>\n","urls":{"html":"/docs/llm-cookbook/session-start-pattern","text":"/docs/llm-cookbook/session-start-pattern?format=text","json":"/docs/llm-cookbook/session-start-pattern?format=json","llm":"/docs/llm-cookbook/session-start-pattern?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}