# Session Start Pattern Every LLM agent session should follow this canonical startup sequence. Skipping steps leads to lost context, missed messages, and forgotten tasks. ## The Pattern ``` 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 ``` ## Implementation ### Step 1: Recall All Memories > [!CRITICAL] > This is the most important call. Without it, you have no memory of past > sessions. ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/memory/recall ``` Returns plain-text summary of all memories, sorted by priority. ### Step 2: Poll for Unread Chat Messages ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ https://synapse.schaefer.zone/chat/poll ``` Returns unread messages from the human. **Automatically marks them as read.** ### Step 3: Check In-Progress Tasks ```bash curl -H "Authorization: Bearer YOUR_MIND_KEY" \ "https://synapse.schaefer.zone/mind/tasks?status=in_progress" ``` Returns tasks you were working on last session. ### Step 4: Build Context Combine the three responses into your system prompt: ```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 ``` ### Step 5: Process Pending Items ``` 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 ``` ## Complete Example ```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... ``` ## Common Mistakes > [!WARNING] > - **Skipping recall** — you start with no context, repeat past mistakes > - **Forgetting to poll chat** — human's messages go unanswered > - **Ignoring active tasks** — work is forgotten mid-execution > - **Storing nothing** — session produces no persistent value ## Variations ### Minimal pattern (low-context LLMs) For LLMs with small context windows, skip the full recall: ```bash # Just get stats, not full content curl -H "Authorization: Bearer $KEY" .../memory/stats ``` Then search for specific topics as needed: ```bash curl -H "Authorization: Bearer $KEY" ".../memory/search?q=current+project" ``` ### Aggressive pattern (long-running agents) For agents that run for hours, add periodic re-recall: ```python while working: if time.time() - last_recall > 3600: # every hour memories = recall() last_recall = time.time() # ... do work ... ``` ## Next Steps - [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)