Context management
Model context windows are finite. Digitorn helps you keep long chats under the limit with compaction settings in YAML.
What fills the context
| Piece | Notes |
|---|---|
| System prompt | Your system_prompt and related injects |
| Tool schemas | Larger when many modules are granted |
| Conversation history | Grows every turn |
| Memory snapshot | Goals / facts when memory is enabled |
When token pressure (used / max) crosses your threshold, compaction rewrites older history so recent messages stay intact.
Configure under runtime.context or brain.context
runtime:
context:
max_tokens: 200000 # 0 = auto from the provider when possible
output_reserved: 4096 # room left for the model reply
strategy: summarize # truncate | summarize
keep_recent: 10 # recent messages kept verbatim
compression_trigger: 0.75 # pressure that starts compaction
summary_max_tokens: 1024
auto_compact: true # inject a default compact hook
Per-agent override:
agents:
- id: main
brain:
context:
max_tokens: 32000
strategy: summarize
keep_recent: 8
Full field list: App configuration.
Explicit compact hook
brain.context.keep_recent configures how many recent messages
to preserve. On a hook action, the field name is
keep_last (not keep_recent):
runtime:
hooks:
- id: compact_when_full
"on": turn_end
condition:
type: context_pressure
threshold: 0.75
action:
type: compact_context
strategy: summarize
keep_last: 10
If you already declare a compact_context hook, Digitorn does
not add a second auto-compact hook on top.
Strategies
| Strategy | Behaviour |
|---|---|
summarize | Older turns become a short summary; recent turns stay |
truncate | Drops oldest turns until pressure is acceptable |
Tips for app authors
- Prefer
auto_compact: truefor chat apps unless you need a custom hook. - Use a smaller
keep_recent/keep_laston long-running background agents. - Grant fewer tools if tool schemas dominate the window (discovery).
Related
- Project memory -
memory_indexand the context builtins - App config - context
- Hooks
- YAML building blocks