Quick start: multi-turn conversation
thread_id links runs into a conversation. AFK automatically persists messages between runs.
What gets stored
What’s NOT stored automatically: Raw LLM provider responses or internal
framework temporaries. Only conversation-visible records and explicit state
writes are persisted.
State lifecycle
Resume interrupted runs
If a run is interrupted (crash, timeout, pause for approval), resume from the last checkpoint:Compact long threads
Over time, conversation threads grow and consume tokens. Use compaction to trim old events:Memory backends
AFK ships with four backends. All implement theMemoryStore protocol.
- In-memory (default)
- SQLite
- PostgreSQL
- Redis
State lives in process memory. Fast, no setup, but lost on restart.Use for: Development, testing, short-lived scripts.
Connection pooling for Redis
For production Redis deployments, use connection pooling for better performance:Environment-based selection
Set environment variables to auto-select a backend without code changes:Custom backends
Implement theMemoryStore abstract class to add support for any database:
Long-term memory
Beyond conversation events, AFK supports persistent long-term memories scoped per user and purpose:Vector search
Backends that support vector search (SQLite, Postgres) can find semantically similar memories:Text search
All backends support basic text search across memory content:Design guidelines
- Always use
thread_idfor conversations. Without it, each run starts fresh. - Compact threads proactively. Don’t wait until you hit token limits. A good rule: compact when the thread exceeds ~500 events.
- Use checkpoints for long-running agents. If a run might take minutes, checkpoints let you resume on failure.
- Don’t store secrets in memory. Thread events are persisted and may be readable.
- Choose the right backend. In-memory for dev, SQLite for local persistence, Postgres/Redis for production.
- Use scopes for long-term memory. Organize memories by purpose (
preferences,knowledge,history) to keep queries efficient.
Next steps
Core Runner
Resume and compact APIs on the Runner.
System Prompts
Template prompts with context from memory.