Modello di inizio sessione
La sequenza canonica di inizio sessione che ogni agente LLM dovrebbe seguire.
Modello di inizio sessione
Ogni sessione di agente LLM dovrebbe seguire questa sequenza canonica di avvio. Saltare i passi porta a contesto perso, messaggi mancati e attività dimenticate.
Il modello
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 workImplementazione
Passo 1: richiami tutte le memorie
Questa è la chiamata più importante. Senza di essa, non ha memoria delle
sessioni passate.
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
https://synapse.schaefer.zone/memory/recallRestituisce un riassunto in testo semplice di tutte le memorie, ordinate per priorità.
Passo 2: polling dei messaggi chat non letti
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
https://synapse.schaefer.zone/chat/pollRestituisce i messaggi non letti dall'umano. Li contrassegna automaticamente come letti.
Passo 3: verifichi le attività in corso
curl -H "Authorization: Bearer YOUR_MIND_KEY" \
"https://synapse.schaefer.zone/mind/tasks?status=in_progress"Restituisce le attività su cui stava lavorando nella sessione precedente.
Passo 4: costruisca il contesto
Combini le tre risposte nel suo prompt di sistema:
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 contextPasso 5: elabori gli item in sospeso
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 progressEsempio completo
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...Errori comuni
Variazioni
Modello minimale (LLM a basso contesto)
Per LLM con finestre di contesto piccole, salti il richiamo completo:
# Just get stats, not full content
curl -H "Authorization: Bearer $KEY" .../memory/statsPoi cerchi argomenti specifici quando necessario:
curl -H "Authorization: Bearer $KEY" ".../memory/search?q=current+project"Modello aggressivo (agenti long-running)
Per agenti che girano per ore, aggiunga un re-richiamo periodico:
while working:
if time.time() - last_recall > 3600: # every hour
memories = recall()
last_recall = time.time()
# ... do work ...