Skip to main content

Context Management

Strongly agents handle arbitrarily long conversations without exceeding the model's context limit. What happens to history that no longer fits is the policy you pick: Window drops it, Summarise and Hierarchical summarise it with the agent's own model. No message is ever cut in half. You pick the policy at build time and adjust later in Agent Settings → Context Policy.

Three policies, plus two knobs. That's the whole set.

Pick a policy​

Window​

Keep the most recent turns up to the token budget and drop older turns. Nothing is summarised: once the conversation passes the budget, the oldest whole turns are dropped down to the last Keep recent turns turns, and further while they alone are over the budget. The latest turn is always sent whole, even when it alone is over the budget. The agent is told that older messages were dropped, so it says so instead of guessing. This is the platform default.

  • Cost: lowest -- no summarisation call.
  • Recall: recent turns only; dropped turns are gone.
  • Pick this for: short conversational agents, support triage, one-shot Q&A.

Summarise​

Roll older turns into one running summary and keep the recent tail verbatim. Each new batch of older turns is summarised once and added to the summary; when the summary passes 40% of the budget, its oldest half is rewritten shorter.

  • Cost: medium -- one summarisation pass when the budget tightens.
  • Recall: good. Decisions made earlier survive into the summary.
  • Pick this for: personal assistants, long threads, anything where earlier context matters later. This is Iris's default.

Hierarchical​

Three tiers -- recent turns verbatim, a summarised middle, and the oldest history as titles only (one line per topic, keeping its ids and numbers exactly). When the summarised middle passes 30% of the budget, its oldest half becomes titles; when the titles pass 10%, they are merged into fewer.

  • Cost: highest.
  • Recall: best.
  • Pick this for: research assistants and multi-day operational threads.

The two knobs​

KnobWhat it doesSensible default
Token budgetMax tokens sent to the model each turn: the agent's instructions (its system prompt), its tool definitions (a turn whose instructions and tools alone exceed the budget is refused, naming the sizes), the summary or titles carried for older history, the kept turns and the new message.70% of your model's context window
Keep recent turnsHow many recent turns before the new message stay verbatim when older history is dropped or summarised (fewer when they alone are over the budget). A turn is a user message and every reply to it.12-20

The wizard auto-fills the token budget based on the primary model you picked. You can override it, up to the model's context window: a larger budget is marked and cannot be saved, and switching to a model whose window is smaller than the budget asks you to lower the budget first.

Long replies and large tool results​

Nothing in a run is cut off:

  • A reply cut off at the agent's max tokens is continued from where it stopped, up to three times in a row; then the run's context is compacted once and the reply tried again. If it still cannot finish, the run ends with an error saying so, never with a partial answer.
  • A tool call whose arguments are not valid JSON (or that was cut off mid-call) is never run. The model is told which tool and which parameters it expects, and calls it again.
  • A tool result too large for the context reaches the model as a summary and a handle; the model reads any page of the full result with its tool_result_read tool.
  • A summary that cannot be made (for example the AI Gateway is down) ends the run with that error (Summarise and Hierarchical). The conversation is left whole.

Inside a long run​

A run that calls many tools keeps fitting the model too:

  • Compaction during the run. Before each model call, when the run's context nears the token budget (counted from the AI Gateway's own measure of the last call, never less), the earlier part of the run is summarised (Window: older whole messages are dropped, older turns first, then the run's earlier steps with their results; the message and the latest step always stay) and the run goes on.
  • One recovery from an overflow. If the model still reports that the request does not fit its window, the run's context is compacted once more, to a fifth of its size (Window: half of it is dropped), and the call is tried again. If it still does not fit, the run ends with that reason.
  • One summary shape. Every summary is written under the same headings: Goal, State (done, in progress, blocked), Next and Resources (every id, name, URL or path the work touched, exactly).
  • Outdated reads. When the agent reads the same thing again (the same workflow, execution, file or page, with the same arguments), the older copy in its context is replaced by a note that points to the newer result, so it never acts on stale state.
  • A prompt that is cached. The agent's system prompt is the same on every turn. What is chosen for each message (the date, preferences, applicable rules, recalled memories, relevant skills) is sent with the message, after the conversation, so the AI Gateway's prompt caching serves the rest from cache.

When edits take effect​

A saved context policy reaches a running agent when you click Apply changes in the Settings header, which stays highlighted until you do.

See also​