# 세션 시작 패턴 모든 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] > - **회상 건너뛰기** — 컨텍스트 없이 시작, 과거 실수 반복 > - **채팅 폴링 잊기** — 사람의 메시지가 답장 없이 남음 > - **활성 작업 무시** — 실행 중간에 작업이 잊혀짐 > - **아무것도 저장하지 않기** — 세션이 영구적 가치를 생성하지 않음 ## 변형 ### 최소 패턴 (저컨텍스트 LLM) 컨텍스트 창이 작은 LLM의 경우, 전체 회상 건너뛰기: ```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 ... ``` ## 다음 단계 - [메모리 태깅 전략](/docs/llm-cookbook/memory-tagging-strategy) - [작업 기반 워크플로우](/docs/llm-cookbook/task-driven-workflow) - [채팅 폴링 패턴](/docs/llm-cookbook/chat-polling-pattern)