Compaction and Reset
Last updated
How a long run is kept inside the model's window, and what reset and remove clear.
In-run compaction
Beyond the stored tiers,
internal/agents/exec/compact keeps a single long run inside the model's window. Each step is a separate stage, applied in order and only as far as needed:| Stage | Trigger | Effect |
|---|---|---|
CheckThreshold(model) | Every iteration after the first, against the previous send's input tokens | Token budget for the current model — 80 % of its context window. Since v1.0.11 the window comes from a live table fetched once per hour from https://llm-io.agenvoy.com/ and keyed by vendor + model, replacing the hard-coded per-family sizes; a model missing from the table falls back to 128 K. Since v1.0.25 a copilot@ model missing from the table uses the max_context_window_tokens that Copilot's own /models endpoint reports (fetched in the background, refreshed every 24 h) instead of the former flat 256 K. Since v1.3.0 a limit learned from an overflow error replaces the table value when it is smaller (or stands in for a model the table lacks), and deepseek deepseek-flash is fixed at 1,048,576 input tokens. Since v1.3.1 each run warms the table in the background instead of waiting on it, and a failed fetch is retried after 5 minutes |
ExtractContextHistories (ExtractOldHistories before v1.2.1) | Budget exceeded, first time in the run | Fold older conversation turns into the rolling summary |
ToolHistory | Budget exceeded again, or there were no older turns to fold | Summarize the oldest tool-call exchanges into text |
TrimRatio → TrimFallback | Provider returns a context-length error | Since v1.3.0 the error first records the model's real limit, then history is cut to 80 % of its size and resent. Since v1.3.1 a decision model first drops the tool steps it judges, with a confidence of at least 0.7, the request no longer needs — never the latest step or a write_todo call; then TrimFallback drops the oldest exchange (two conversation messages at a time, then the oldest tool-call step with its results) until the target is met. Removed in v1.3.0: the v1.1.1 pass that ran ExtractContextHistories → ToolHistory first |
RawToolFallback | Model switch mid-run | Convert tool history to plain text so the new model can read it |
Manual compaction runs from the TUI (
/compact; the /memory command was removed, reset is now /reset) or POST /v1/session/:id/memory. That one endpoint takes an action: compact drops older messages and returns removed, summary rebuilds the rolling summary and returns count, and reset clears the conversation — mode: "summary" keeps the rolling summary, mode: "all" wipes it too. In the TUI, /compact and /reset open one popup with three tabs: summary (read-only view of the current rolling summary, since v1.1.1), compact and reset; /compact opens on the compact tab, /reset on the reset tab.Search routing
match parameter | Source | Use case |
|---|---|---|
semantic (default) | ToriiDB VSearch | "What did we discuss about X?" — meaning-based |
keyword | SQLite FTS5 (archive) + ToriiDB substring (recent) | "Find messages containing 'sandbox'" — exact text |
Cross-session error memory
Tool failures and the fix that resolved them persist across sessions in
error_memory with 90-day TTL. Only records written with outcome=resolved are stored; failed / abandoned writes are discarded, so abandoned strategies are no longer kept. On hit (either via keyword Contains or db.VSearch), the entry's TTL is refreshed via db.Expire.When the same tool name fails in a future session,
toolCall.go automatically queries error_memory and appends up to 3 related records to the failed tool result as related_errors; the agent applies the recorded fix.A record's recorded action can be edited from the web dashboard's Lessons view (
PATCH /v1/torii/error, which rewrites action and keeps the TTL); GET /v1/torii/error lists records.Reset / remove behavior
| Operation | history.json | ToriiDB DBSessionHist | SQLite (messages + meta) | summary.json |
|---|---|---|---|---|
| Compact (auto) | Trimmed to 80% | Entries < cutoff removed | Untouched (already has all data) | Untouched |
Reset (/reset, mode=summary) | Deleted | Cleared | Cleared | Preserved |
Reset (mode=all) | Deleted | Cleared | Cleared | Deleted |
| Remove session | Directory deleted | Cleared | Cleared | Directory deleted |