Skip to content

Context management

Talon automatically handles context window limits. When the accumulated conversation approaches the provider’s limit, the daemon rotates the session: it compresses what happened, stores the result in memory, and starts a fresh session with that context injected. The agent never sees the boundary.

After each agent run, Talon checks the token usage. If the context is getting full, it triggers a rotation:

  1. Talon sends the agent’s reply back to the channel
  2. Talon persists that outbound message to the transcript
  3. The configured summarizer compresses the current transcript
  4. The result is written to memory_items
  5. The session ID is cleared; the next run starts a fresh session
  6. On the next run, Talon assembles the context:
    • The latest session summary
    • The last N messages verbatim (configurable)

The thing is, rotation is no longer on the critical path for user-visible replies. If a turn crosses the threshold, the user still gets the answer immediately instead of waiting on the summarizer call.

Context management is configured per provider under agentRunner.providers.<name>.contextManagement:

agentRunner:
providers:
claude-code:
enabled: true
command: claude
contextWindowTokens: 200000
contextManagement:
enabled: true
triggerMetric: cache_read_input_tokens
thresholdRatio: 0.5
recentMessageCount: 10
summarizer: session-summarizer
OptionDefaultDescription
enabledfalseEnable or disable context rotation for this provider. Set to false to keep unlimited context (useful for Claude Max subscribers)
triggerMetric—Token metric to monitor: input_tokens, cache_read_input_tokens, cache_creation_input_tokens, or cache_total_input_tokens
thresholdRatio—Fraction of contextWindowTokens that triggers rotation (0–1)
recentMessageCount10How many recent messages to inject verbatim after rotation
summarizer—Sub-agent name for history compression (session-summarizer for legacy summaries, session-observer for observational memory)
reflectionThresholdChars40000Size of the observation log, in characters, that triggers session-reflector. Only applies with summarizer: session-observer

When enabled is true, triggerMetric, thresholdRatio, and summarizer are required. Config load fails without them.

Set contextManagement.enabled: false to disable rotation entirely. This is useful for:

  • Claude Max subscribers with unlimited context
  • Short-lived conversations that never approach the limit
  • Debugging where you want the full transcript preserved
agentRunner:
providers:
claude-code:
contextManagement:
enabled: false

The old top-level context block has been removed. Talon refuses to load a config that still has it and tells you to migrate to agentRunner.providers.<name>.contextManagement. A per-persona context key is not part of the persona schema.

One legacy form still loads. A provider-level rotationThreshold without a contextManagement block is converted at load time:

agentRunner:
providers:
claude-code:
rotationThreshold: 0.5 # becomes contextManagement.thresholdRatio

Talon turns this into an enabled contextManagement block with recentMessageCount: 10 and summarizer: session-summarizer. The trigger metric is cache_read_input_tokens for provider names that contain claude, and input_tokens for all others.

Some providers run several model steps in one turn and report both cumulative usage and the usage of the final step. Talon keeps cumulative usage for accounting, but it checks the final step against the rotation threshold. A tool-heavy turn does not rotate only because its cumulative input crossed the threshold.

Resumed Codex CLI sessions are the exception. For a resumed session, the final step only covers the new turn, and the rest are cache hits. Talon therefore checks the cumulative usage that Codex reports for the whole session. A resumed session now rotates when the session itself crosses the threshold, even if each single call stays below it.

When Talon starts a fresh session without rotation

Section titled “When Talon starts a fresh session without rotation”
  • Model or effort change. Talon restores a resumable session only for the same provider, model, and configured reasoningEffort. After a change, the next run starts a fresh session with the stored context injected.
  • Cross-thread delivery. When channel_send or channel_broadcast stores an outbound message on a thread other than the thread of the current run, Talon rotates the session of the recipient thread. This is the scheduled-task case. The next run on the recipient thread starts fresh, so the agent sees the scheduled message in its recent messages. The cost is one cache miss per delivery.
  • Scheduled runs. A scheduled run is a one-shot run. It does not restore or store a provider session, gets no prior transcript, and never triggers rotation. See Scheduling.

The legacy session-summarizer sub-agent reads the full transcript and produces one structured summary covering:

  • Key topics discussed
  • Decisions made
  • Open questions
  • Relevant facts

That summary is injected into the next session. It is compact and reliable, but each new rotation replaces the previous summary.

Observational memory is the alternative mode. When summarizer: session-observer, Talon appends dated observations instead of overwriting a single summary blob. Each rotation adds a compact decision log with priority markers, plus currentTask and suggestedContinuation metadata so the next run can pick up the interrupted work cleanly.

Example:

Date: 2026-04-08
- 🔴 20:12 User wants docs updated for PRs #179, #189, and #176
- 🟡 20:18 Existing main worktree has unrelated edits; use a separate worktree
- 🔴 20:31 Providers, memory, and context docs updated together

When the observation log grows past reflectionThresholdChars (default 40000 characters), session-reflector merges and prunes older entries so the log stays dense enough to keep injecting.

To enable observational memory:

personas:
- name: assistant
subagents:
- session-observer
- session-reflector
- memory-groomer
- memory-retriever
agentRunner:
providers:
claude-code:
contextManagement:
enabled: true
triggerMetric: cache_read_input_tokens
thresholdRatio: 0.5
recentMessageCount: 10
summarizer: session-observer

Without session-observer and session-reflector in the persona’s subagents list, Talon cannot run the observational-memory path at runtime.

Session summaries, observations, and named memory entries accumulate in memory_items over time. The memory-groomer sub-agent consolidates them: it reads the thread’s stored memory, merges redundant entries, and prunes anything no longer relevant. Schedule it to run periodically:

# fires at 3am daily
- cronExpr: "0 3 * * *"
promptFile: memory-grooming

If other tasks keep operational state in memory, pass protectedKeyPrefixes so the groomer skips those keys. See Memory.

Every agent run receives a cache-friendly time window injected into the context:

Current time: between 17:50 and 18:00 on Wednesday 2026-04-02 (CEST, UTC+02:00). If you need precise time you can use the bash-tool.

The 10-minute window stays stable long enough for provider-side prompt caching to work. If the exact second matters, the prompt now explicitly tells the model to use a shell time command instead of guessing.

The context assembled for each run includes:

[system prompt]
[personality fragments]
[current time]
[stored context from the selected compression mode]
[last N messages verbatim]
[current message]

The agent never receives explicit notification that a session rotation occurred. The summary is presented as part of the normal context.

Talon frames the stored context as prior-conversation state and tags replayed turns as [previous turn, user]: ... instead of User: and Assistant: role markers. This keeps the agent from reading old turns as live instructions. The replayed messages are the turns after the most recent rotation, up to recentMessageCount. Earlier turns are already in the summary or the observations.