Skip to main content

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

PieceNotes
System promptYour system_prompt and related injects
Tool schemasLarger when many modules are granted
Conversation historyGrows every turn
Memory snapshotGoals / 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

app.yaml
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:

app.yaml
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):

app.yaml
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

StrategyBehaviour
summarizeOlder turns become a short summary; recent turns stay
truncateDrops oldest turns until pressure is acceptable

Tips for app authors

  • Prefer auto_compact: true for chat apps unless you need a custom hook.
  • Use a smaller keep_recent / keep_last on long-running background agents.
  • Grant fewer tools if tool schemas dominate the window (discovery).