Appearance
Context Management
Every request Iris sends to an LLM has a fixed token limit — the model's context window. Context management is the set of mechanisms Iris uses to keep that request within bounds while preserving as much relevant history as possible.
This page covers how the token budget is calculated, how conversation history is loaded against that budget, how tool output pruning reclaims space invisibly, and how compaction summarizes old turns when the window fills up.
Token Budget Calculation
Before loading any history, Iris calculates how many tokens are available. The formula is:
available tokens = (context window × token_budget_ratio) - system prompt tokens - context tail tokens - tool definition tokensThe context tail is rendered before history is loaded, so recalled memories, calendar events, and cross-thread briefs all come out of the same budget.
The token estimate uses a chars/3 heuristic: ceil(mb_strlen($text) / 3). It's fast and errs conservatively (it over-counts prose a little).
Config keys
| Key | Default | Effect |
|---|---|---|
context.window | 200000 | The context window size (in tokens) of your configured model |
context.token_budget_ratio | 0.70 | Fraction of the context window allocated to conversation history |
Set context.window to match the model you're using. The default model, Claude Sonnet 5.5, has a 1M token context window, so set context.window to 1000000 to take advantage of the full capacity. On Anthropic's 1M models that size is the default, with no beta header or extra setting. The default of 200K is deliberately conservative: it keeps per-request token usage down and stays safe on 200K models like Haiku 4.5. Anthropic's context window reference lists the window for every model.
On a 200K window, after accounting for a typical system prompt and tool definitions (~10K tokens combined), you'll have ~130K tokens for conversation history. On a 1M window, that grows to ~690K tokens — roughly 5× more conversation depth.
TIP
To allow more history at the cost of less headroom for responses, raise context.token_budget_ratio to 0.80 or 0.85. This can help on smaller context windows during long tool-heavy sessions.
History Loading
Iris loads history from the latest summary boundary forward, not the entire thread. Everything at or before that boundary is represented by the conversation summary (see Compaction); everything after it is sent as raw turns. Within that raw range, Iris still fills the token budget newest-first, so the model always sees the most recent turns.
Loading from a fixed boundary instead of a sliding window has a payoff beyond token savings: the front of the history stays byte-identical turn over turn, which is what lets Anthropic cache it. See Cache Breakpoints.
How history loading works:
- Find the thread's anchor — the highest
end_message_idacross its summaries (0 if none) - Query conversations after the anchor, newest-first, up to
context.conversation_load_limit(500) - Accumulate token estimates until the budget is exhausted, pruning tool output along the way. A replayed image counts as
images.replay.tokens_per_imagetokens - Reverse the selected messages to chronological order before passing to the LLM
The newest message always goes in, even if it alone exceeds the budget.
User messages in this range carry their image attachments again, within the images.replay caps; an image over the cap, or one whose file can't be read, is sent as its one-line [Image: ...] description instead (or [Image] if it has no description yet). Which images are replayed depends only on the images in the range, so it changes only when a new image arrives or an old one leaves the range. When a new image pushes an older one over the cap, the cached history is rewritten once from that older message on. See Images Settings.
If the raw range since the anchor outgrows the budget, that's the signal to compact: the oldest turns get summarized and the anchor moves forward.
Config keys
| Key | Default | Effect |
|---|---|---|
context.token_budget_ratio | 0.70 | Controls how many tokens are available for history |
context.conversation_load_limit | 500 | Most messages loaded from the database per request |
images.replay.tokens_per_image | 4800 | Budget estimate for each replayed image |
Tool Output Pruning
Even with budget-based loading, tool outputs from older turns can waste tokens. A read_file call that returned 5,000 characters of file content is useful context when it happens — but ten turns later, the agent probably doesn't need all of that content verbatim.
Pruning truncates long tool results and tool arguments in the LLM request, ending each cut value with [truncated]. It happens while history is loaded, so the token estimates reflect what's actually sent, and it's invisible to you: full content is always retained in the database.
What gets pruned
A turn is one user message plus all subsequent assistant messages and tool result messages until the next user message. Pruning has two tiers, split by context.prune_protect_turns:
| Turns | Tool results | Tool arguments |
|---|---|---|
The most recent prune_protect_turns (2) | Cut to protected_result_max (10,000) characters | Cut to protected_result_max (10,000) characters |
| Everything older | Cut to old_result_preview (200) characters | Cut to old_argument_preview (1,000) characters |
Anything under its limit passes through untouched, so a 500-character result in a recent turn is sent as-is while a 50,000-character shell output is cut to 10,000. Only string arguments are cut; other argument values are always sent verbatim. Arguments get a higher limit than results in older turns because they record what Iris did (a file path, an edit), which matters more for coherence than what it saw.
Config keys
| Key | Default | Effect |
|---|---|---|
context.prune_protect_turns | 2 | Number of recent turns that only get the protected cap |
context.protected_result_max | 10000 | Character cap per tool result and argument in protected turns |
context.old_result_preview | 200 | Character cap per tool result in older turns |
context.old_argument_preview | 1000 | Character cap per tool argument in older turns |
The invariant: database content is always preserved
Pruning operates exclusively on in-memory Prism message objects. It never modifies the conversations table. You can always inspect the full tool output of any past turn directly in the database — pruning only affects what's sent to the LLM for a given request.
IMPORTANT
Full conversation content — including all tool outputs — is always retained in the database regardless of pruning or compaction state.
Compaction
When the context window fills up despite pruning, Iris compacts the conversation. Compaction summarizes older turns into a structured narrative, freeing the window for new activity.
When compaction triggers
After every reply, Iris queues a SummarizeConversation job for the thread. The job estimates the size of the raw history since the anchor (message text plus tool calls and results, before pruning) and compares it to the model's context window:
if estimated_history_tokens > context_window × compaction_threshold → compactAt the default compaction_threshold of 0.75, compaction triggers when the unsummarized history passes 75% of the window — before it overflows, not after. It measures the live history size, not a stored token count, so it keeps working once prompt caching shrinks the billed input down to just the tail. The job also compacts when the thread has more than summarization.threshold (40) unsummarized messages, whatever their size.
History loading backs this up. If the budget left any unsummarized messages out of a request, Iris queues the same job. If it left out more than 20, Iris runs one summarization pass synchronously before sending the request and reloads history from the new anchor, and the chat shows a compaction notice.
What the summary includes
Compaction generates a structured ConversationSummary. These fields carry the most weight for picking a long task back up:
| Field | Description |
|---|---|
summary | 150–300 word narrative of the conversation segment |
accomplishments | Completed tasks and outcomes from this segment |
key_decisions | Choices made and conclusions reached |
relevant_files | Files touched, modified, or referenced |
active_goals | Open goals or tasks still in progress |
emotional_thread | How the emotional tone evolved through this segment |
relationship_dynamics | Shifts in formality, rapport, and trust |
evolving_themes | Topics that developed or transformed across turns |
Recent messages are kept verbatim: the newest summarization.protect_recent messages are never pulled into a summary, and compaction only affects the messages being summarized, not the tail that will still appear in full.
For a deeper look at what summaries capture and how the summary chain works, see Summarization.
Config keys
| Key | Default | Effect |
|---|---|---|
context.compaction_threshold | 0.75 | Fraction of the context window the unsummarized history must pass to trigger compaction |
summarization.threshold | 40 | Unsummarized message count that also triggers compaction |
summarization.trim_target_ratio | 0.75 | Each compaction summarizes the oldest messages until the rest fits in this fraction of context.window × context.token_budget_ratio |
summarization.protect_recent | 10 | Most recent messages never summarized |
When the request is still too large
There's no further fallback inside Iris. If a request still doesn't fit (for example, a single huge message on a small context.window), the provider rejects it, the message is marked failed, and the chat shows: "The conversation is too long for the model's context window. Try starting a new conversation or asking Iris to work in smaller steps."
Walkthrough: A Long Tool-Heavy Conversation
Here's how the full lifecycle plays out in practice.
Setup: You're running on a 200K context model. System prompt + tool definitions occupy ~10K tokens. The budget ratio is 0.70, so ~130K tokens are available for history.
Turns 1–5: Early conversation, tools used freely
The budget check shows 130K tokens available. History loading grabs all 5 turns, with plenty of room to spare. The 2 most recent turns keep up to 10,000 characters per tool result; turns 1–3 have each tool result cut to a 200-character preview. But this is invisible: turns 1–3 still appear in the database in full.
Turns 6–20: Tool-heavy accumulation
You ask Iris to explore a large codebase — multiple read_file calls, grep searches, shell commands. Each turn produces thousands of characters of tool output. History loading can still fit all 20 turns because pruning shrinks the effective token cost of older turns. The protected window (last 2 turns) keeps long tool output; everything older is a short preview.
After turn 20: Compaction triggers
When Iris finishes replying to turn 20, the queued summarization job estimates the raw history since the anchor, full tool output included, and finds it past the 150K threshold. It summarizes the oldest unsummarized messages — enough of them to bring the remaining history back down to 75% of the 140K budget — into a ConversationSummary covering turns 1–15, capturing accomplishments (files explored, patterns found), relevant files (the ones you looked at), active goals (the refactoring task still in progress), and emotional thread (curiosity, some frustration at a confusing module). The 10 newest messages (turns 16–20) are protected, and the anchor moves to the end of turn 15.
When you send turn 21, the LLM sees:
- The new summary injected via the system prompt
- Turns 16–20, pruned by the same two tiers
- Your new message (turn 21)
Turn 22 onward: Conversation continues
The context is spacious again. History loading now fits turns 16–21 plus any new turns. As the conversation grows, the cycle repeats: pruning reclaims token space turn by turn, and compaction fires again when the raw history creeps back up past 75% of the window.
What you see: Nothing. The conversation flows naturally. Iris remembers the files you explored and the goals you set even after they've been summarized away from the raw message list.
Cross-References
- Summarization — what conversation summaries capture and how the summary chain works
- Configuration: Context Management — full reference for all config keys:
context.token_budget_ratio,context.compaction_threshold,context.prune_protect_turns, and the pruning caps - Cache Breakpoints — how the loaded history is cached between turns