{"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":204,"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":"ko","translated":true,"requested_lang":"ko","content_markdown":"\n# 세션 시작 패턴\n\n모든 LLM 에이전트 세션은 이 정규화된 시작 시퀀스를 따라야 합니다. 단계를\n건너뛰면 컨텍스트 손실, 메시지 누락, 잊혀진 작업이 발생합니다.\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\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### 최소 패턴 (저컨텍스트 LLM)\n\n컨텍스트 창이 작은 LLM의 경우, 전체 회상 건너뛰기:\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- [메모리 태깅 전략](/docs/llm-cookbook/memory-tagging-strategy)\n- [작업 기반 워크플로우](/docs/llm-cookbook/task-driven-workflow)\n- [채팅 폴링 패턴](/docs/llm-cookbook/chat-polling-pattern)\n","content_html":"<h1>세션 시작 패턴</h1>\n<p>모든 LLM 에이전트 세션은 이 정규화된 시작 시퀀스를 따라야 합니다. 단계를\n건너뛰면 컨텍스트 손실, 메시지 누락, 잊혀진 작업이 발생합니다.</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\">이것이 가장 중요한 호출입니다. 이것 없이는 과거 세션에 대한 메모리가\n없습니다.</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>최소 패턴 (저컨텍스트 LLM)</h3>\n<p>컨텍스트 창이 작은 LLM의 경우, 전체 회상 건너뛰기:</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\">메모리 태깅 전략</a></li>\n<li><a href=\"/docs/llm-cookbook/task-driven-workflow\">작업 기반 워크플로우</a></li>\n<li><a href=\"/docs/llm-cookbook/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"]}