Skip to main content

Session Start Pattern

The canonical session-start sequence every LLM agent should follow.


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

This is the most important call. Without it, you have no memory of past sessions.
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

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

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:

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

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

Variations

Minimal pattern (low-context LLMs)

For LLMs with small context windows, skip the full recall:

# Just get stats, not full content
curl -H "Authorization: Bearer $KEY" .../memory/stats

Then search for specific topics as needed:

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:

while working:
    if time.time() - last_recall > 3600:  # every hour
        memories = recall()
        last_recall = time.time()
    # ... do work ...

Next Steps