Skip to main content

세션 시작 패턴

모든 LLM 에이전트가 따라야 할 정규화된 세션 시작 시퀀스.


세션 시작 패턴

모든 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단계: 모든 메모리 회상

이것이 가장 중요한 호출입니다. 이것 없이는 과거 세션에 대한 메모리가 없습니다.
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/memory/recall

우선순위로 정렬된 모든 메모리의 일반 텍스트 요약을 반환합니다.

2단계: 읽지 않은 채팅 메시지 폴링

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/chat/poll

사람이 보낸 읽지 않은 메시지를 반환합니다. 자동으로 읽음으로 표시합니다.

3단계: 진행 중인 작업 확인

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     "https://synapse.schaefer.zone/mind/tasks?status=in_progress"

지난 세션에 작업 중이던 작업을 반환합니다.

4단계: 컨텍스트 구축

세 가지 응답을 시스템 프롬프트에 결합:

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

완전한 예시

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...

일반적인 실수

변형

최소 패턴 (저컨텍스트 LLM)

컨텍스트 창이 작은 LLM의 경우, 전체 회상 건너뛰기:

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

필요에 따라 특정 주제 검색:

curl -H "Authorization: Bearer $KEY" ".../memory/search?q=current+project"

적극적 패턴 (장기 실행 에이전트)

시간 동안 실행되는 에이전트의 경우, 주기적 재회상 추가:

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

다음 단계