How memory works
Memory in Mycel has two layers:-
Persistence — every message, tool call, and result is stored in SQLite using a LangGraph
AsyncSqliteSavercheckpointer. Resuming a Thread replays the full history. -
Context management —
MemoryMiddlewareautomatically trims and compacts history before every model call, transparently keeping the context window usable.
Pruning
Pruning trims large tool results to prevent individual outputs from consuming too much context.Soft trim — results longer than
soft_trim_chars are truncated but kept.Hard clear — results longer than hard_clear_threshold are removed entirely.Protected recents — the last
protect_recent tool messages are never trimmed, so the agent always has its working context.| Field | Default | Description |
|---|---|---|
soft_trim_chars | 3,000 | Trim results longer than this (chars) |
hard_clear_threshold | 10,000 | Clear results longer than this |
protect_recent | 3 | Keep last N tool messages untrimmed |
trim_tool_results | true | Enable trimming |
Compaction
Compaction summarizes old conversation history via the LLM when the context window fills. This lets agents work on very long tasks without losing meaningful context. Trigger conditions (both must be met):- Conversation has at least
min_messagesmessages - Context window is more than 70% full
keep_recent_tokens tokens, then replaces the old history with the summary.
Default settings:
| Field | Default | Description |
|---|---|---|
reserve_tokens | 16,384 | Reserve for new messages |
keep_recent_tokens | 20,000 | Keep recent tokens verbatim |
min_messages | 20 | Minimum messages before trigger |
Spill buffer
For tools that produce very large outputs (e.g.,Grep on a large codebase), the spill buffer automatically writes the output to a temp file instead of inlining it in the conversation.
Storage
| Database | Location | Contents |
|---|---|---|
| Thread history | ~/.leon/leon.db | Messages, tool calls, results (LangGraph checkpoints) |
| Sandbox state | ~/.leon/sandbox.db | Session leases, metrics |
| Chat messages | ~/.leon/chat.db | Entity-Chat social layer messages |
Thread history is append-only. Rolling back a Thread moves the active checkpoint pointer — it doesn’t delete intermediate history.
Disable compaction or pruning
- Disable compaction
- Disable pruning