> ## Documentation Index
> Fetch the complete documentation index at: https://koreai.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Context size, compaction, and budgets

As a conversation runs, the model's context grows: more customer turns, agent replies, tool calls, and tool results. The runtime shrinks that context so it stays within model limits. It compresses large tool results, replaces older tool results with placeholders, and shortens earlier turns. You can tune these compaction policies per agent, per project, or per tool.

This page lists the default budgets, shows where to set them, and explains how to find out why a prompt grew too large.

To learn which values reach the model in the first place (visibility modes and `## Current Context`), see [How a turn is built](https://koreai.mintlify.site/agent-platform/context-and-prompts.md).

## Size limits and compaction

Three policies set how much the model reads on a turn:

* `tool_results`: how tool output is shaped, on this turn and on later turns.
* `prior_turns`: how earlier turns in the conversation history are compacted.
* `prompt_context`: how `## Current Context` values are sized and projected.

The platform merges them in this order. A later source overrides an earlier one:

1. Platform defaults.
2. The voice low-latency profile (voice channels only).
3. Project settings.
4. The agent's `EXECUTION.compaction`.
5. Per-tool hints.

These policies do not cap the total size of the conversation history. A long conversation keeps growing unless you set bounds. The platform can also summarize older messages when the history nears the model's context window. See [Automatic history summarization](#automatic-history-summarization).

### Default values

| Policy | Setting | Default | Voice latency profile |
| - | - | - | - |
| `tool_results` | `strategy` | `summarize` | `structured` |
| | `max_chars` | 102,400 | 16,000 |
| | `structured_threshold` | 10,000 | 4,000 |
| | `keep_recent` | 2 | 1 |
| | `max_description_length` | 200 | 80 |
| | `summary_timeout_ms` | 5,000 (1,000 to 30,000) | 1,500 |
| `prior_turns` | `strategy` | `compact` | `compact` |
| | `assistant_preview_chars` | 200 | 120 |
| `prompt_context` | `value_max_chars` | 8,000 (40,000 max) | 6,000 |
| | `total_max_chars` | 24,000 (100,000 max) | 16,000 |
| | `auto_tool_result_value_max_chars` | 4,000 | 2,000 |
| | `projection_strategy` | `preview` | `preview` |
| | `include_complete_small_tool_results` | `true` | `true` |

### Tool-result strategies

The `tool_results.strategy` setting decides how the runtime shrinks a large tool result.

| Strategy | Effect |
| - | - |
| `none` | The result passes through unchanged. |
| `truncate` | The runtime cuts the result at `max_chars`. It does not look at the result's structure. |
| `structured` | The runtime removes fields that are not essential, shortens long descriptions, and then cuts at `max_chars`. Use `essential_fields` to name the fields to keep. |
| `summarize` (default) | A model call summarizes a result above `structured_threshold`. If the summary fails or times out (`summary_timeout_ms`), the runtime falls back to structural compression. |

### Prior-turn strategies

| Strategy | Effect on earlier turns |
| - | - |
| `none` | This step changes nothing. A result that the runtime already shortened when it saved it to history stays shortened. |
| `placeholder` | Each earlier tool result is replaced by `[Prior turn result — summarized]`. |
| `compact` (default) | As `placeholder`, and each reply that followed a tool result is shortened to `assistant_preview_chars`. The agent's latest reply is kept whole if it is 2,000 characters or less. |
| `summarize` | Behaves the same as `compact`. No model call is made for this strategy. |

### Projection strategies for Current Context

The platform replaces a `## Current Context` value that is over its limit with a marker object (`_contextLimited: true`). The marker holds the original type and size, and one of three levels of detail:

* `preview` (default): the first part of the value, as text.
* `summary`: the value's shape. It shows types, lengths, and key names, with up to 3 sample array items and up to 8 sample object keys.
* `metadata`: type and size only.

When `include_complete_small_tool_results` is `true` (the default), an earlier tool result that fits its limit stays whole. Set it to `false` to project every earlier tool result with the strategy above.

### Where to set compaction policies

* **Per agent, in ABL** -- the `EXECUTION.compaction` block. See [Compaction policy overrides](https://koreai.mintlify.site/agent-platform/abl/reference/agent-declaration.md#compaction-policy-overrides) for the full property reference.
* **Per project** -- the project runtime configuration, set by API or project import. Studio's Runtime Config tab exposes these controls only for the voice latency profile overrides; the project-wide section is not editable from Studio.
* **Per tool** -- `compaction: essential_fields`, `summary_timeout_ms`, and, for knowledge bases, `max_search_tokens`. See [Result compaction](https://koreai.mintlify.site/agent-platform/abl/reference/tools.md#result-compaction).

```yaml expandable=true theme={null}
EXECUTION:
  models:
    summarization: gpt-4.1-mini
  compaction:
    tool_results:
      strategy: summarize
      max_chars: 32000
      structured_threshold: 8000
      keep_recent: 2
      essential_fields:
        search_orders: [id, status, total, createdAt]
      summarize_prompt: "Keep order IDs, totals and statuses."
    prior_turns:
      strategy: compact
      assistant_preview_chars: 300
    prompt_context:
      value_max_chars: 8000
      total_max_chars: 24000
      auto_tool_result_value_max_chars: 4000
      projection_strategy: preview
```

> [!NOTE]
>
> The compaction policy is resolved once per conversation. In a multi-agent project, set compaction at the project level, or set it the same way on every agent in a handoff chain -- it is not re-resolved on handoff.

> [!NOTE]
>
> These limits do not cover memory sections (`## Session Memory`, `## Granted Memory`, `## Gather Progress`). Keep declared memory small, and set `MODEL_VISIBLE: false` on values the model does not need. See [Memory and state](https://koreai.mintlify.site/agent-platform/memory-and-state.md). For one large tool result, use a `MODEL_CONTEXT` view instead of a higher size limit. It is exact and costs no extra model call.

### Automatic history summarization

The platform can summarize older messages when the history nears the model's context window. It keeps the most recent messages (at least 10) and replaces the older ones with one summary message that starts with `[Conversation Summary]`. The check runs before each model call.

* **Off by default.** An operator turns it on with the platform setting `SESSION_COMPACTION_ENABLED`.
* **Trigger.** The estimated history size reaches 80% of the model's context window. An agent can change the ratio with `compaction_threshold` (0.0 to 1.0) in `EXECUTION`. See [Configuration properties](https://koreai.mintlify.site/agent-platform/abl/reference/agent-declaration.md#configuration-properties).
* **Cost.** Each summary is one extra model call.

## Controlling context size

You control three things: which values may enter the prompt, how large each piece may be, and how long tool output stays around. Most parts of the prompt have a default size limit you can change. Two parts have none -- the conversation history and declared session memory -- so uncontrolled growth usually starts there. Most cuts leave a marker you can find in a trace; knowledge-base chunk drops and the structural shortening of long lists before a summary do not.

### Where context grows

| Source | Grows with | Default limit | Your lever |
| - | - | - | - |
| Conversation history | Every turn | No token cap. [Automatic summarization](#automatic-history-summarization) is off by default. | `prior_turns` (previews of earlier replies), a response `MODEL_CONTEXT` on rich responses, `history: last_n` or `summary_only` on handoffs |
| Declared session memory (`## Session Memory`, `## Granted Memory`, `## Gather Progress`) | The size of the values you store | None | Declare only what the model needs. Keep large objects in tool results or persistent memory. Use `MODEL_VISIBLE: false` for values the model does not need, and `RESET: per_activation` for scratch values. |
| `## Current Context` | The number of values visible | 8,000 per value, 24,000 in total | Explicit visibility mode, named references instead of `{{context}}`, `prompt_context` budgets |
| Tool results, this turn | The size of the API payload | Summarized above 10,000 characters; 102,400 at most | `MODEL_CONTEXT` first, then the `tool_results` strategy and `essential_fields`. Avoid `strategy: none` on unbounded APIs. |
| Tool calls in history | Tool use per turn | The history keeps the 6 most recent tool turns. Results become a marker. | Hide bulky arguments with `default_source: runtime` |
| Knowledge-base results | Chunk count and size | 40,000 tokens when more than 10 chunks come back | `max_search_tokens`, Top K, Similarity threshold -- see [Tool-level search settings](https://koreai.mintlify.site/agent-platform/knowledge.md#tool-level-search-settings) |
| Explicit mode | Each declared value | A value can appear in both `## Session Memory` and `## Current Context` | Keep declared memory small |
| Recall and notes | Cross-channel recall, resolved-intent ledgers, recall instructions | 20 recalled messages by default (1 to 100); 8 ledger entries | Recall settings; keep `INSTRUCTION` text short |

### Where context gets cut

| Cut point | Default | Marker in the trace | Lever |
| - | - | - | - |
| One `## Current Context` value | 8,000 characters | `_contextLimited: true` with a preview, summary, or size | `value_max_chars` (up to 40,000), `projection_strategy` |
| The whole `## Current Context` block | 24,000 characters | Values left out are listed by name | `total_max_chars` (up to 100,000) |
| An earlier tool result in Current Context | 4,000 characters | `_contextLimited`, plus a `## Prior Tool Result Context` note | `auto_tool_result_value_max_chars` |
| A tool result this turn | Summarized above 10,000 characters; cut at 102,400 | `"_summarized": true` or `...[truncated: N chars, showing first M]` | `MODEL_CONTEXT`, `structured_threshold`, `max_chars`, `strategy` |
| An older result within a long turn | Only the last 2 rounds stay whole | `[Result available — see earlier in conversation]` | `keep_recent` |
| Tool results on later turns | Always replaced | `**COMPACTED FOR CHAT HISTORY**`, `[Prior turn result — summarized]` | Save what you need with `on_result: SET` |
| Earlier tool-backed replies | 200-character preview | `[Prior response: "…"]` | `assistant_preview_chars`, or `prior_turns: placeholder` |
| A `MODEL_CONTEXT` view | 16,000 characters or 1,000 items | An "unavailable" marker -- the view fails rather than being cut | Select fewer fields |
| Knowledge-base results | The token budget | Whole chunks dropped from the end | `max_search_tokens` |
| Handoff history | Full by default | The receiver's history starts later | `history:` -- see [History strategies](https://koreai.mintlify.site/agent-platform/abl/reference/multi-agent-and-supervisor.md#history-strategies) |

### A budget recipe for a production agent

1. Declare `BEHAVIOR: role:` so only declared and granted values reach `## Current Context`.
2. Give every tool with a large or nested result a `MODEL_CONTEXT`, and save the fields later turns need with `on_result: SET`.
3. Keep declared session memory to small scalars. Use `RESET:` for scratch values.
4. Use `history: last_n` or `summary_only` with a summary on handoffs in long conversations. Pass state with `pass`, not history.
5. Set `max_search_tokens` on every knowledge base, lower for voice.
6. Set compaction once at the project level so every agent in a handoff chain uses the same budgets, then tune each agent only where needed.
7. Run a 20-turn test conversation, then check the trace's Request view and the session Overview's Token Breakdown for growth from turn to turn.

### Debugging a bloated or truncated prompt

Open a session's Traces tab, pick an LLM step, and open its Request view (see [LLM step request and response](https://koreai.mintlify.site/agent-platform/sessions.md#llm-step-request-and-response)). Search `systemPrompt` and `messages` for `_contextLimited`, `truncated`, `_summarized`, `COMPACTED FOR CHAT HISTORY`, and `Prior response`. Also look for `Prior turn result`, `Result available`, and an "unavailable" marker.

Knowledge-base results leave no marker in the trace, so compare their size against `max_search_tokens` directly. If the prompt is large and none of these markers explain it, the size is coming from conversation history or a memory section, and the levers in [Where context grows](#where-context-grows) apply.

## Common mistakes

* **Declared memory is not size-limited.** To keep one declared value away from the model, set `MODEL_VISIBLE: false` on it. An explicit `{{value}}` reference in prompt text still shows it. See [How a turn is built](https://koreai.mintlify.site/agent-platform/context-and-prompts.md#keeping-a-value-out-of-the-prompt).
* **History has no automatic token cap.** A long conversation needs `prior_turns`, `MODEL_CONTEXT`, and handoff history settings to stay bounded. Automatic summarization helps only if an operator turns it on.
* **Compaction settings do not refresh on handoff.** The platform resolves them once per conversation, the first time it needs them. This is usually the agent that starts the conversation. Set the same values across a handoff chain. Do not rely on the receiving agent's own settings.
* **The automatic first knowledge-base search is off by default.** It runs only when the knowledge tool sets `kb_fast_path: on`. When it is on, control the size of its results with `max_search_tokens`.
* **`model_context` on a shared tool file is ignored.** Put it on the agent's copy of the tool.
* **One missing field breaks a `model_context` view.** List only fields that every result carries. Otherwise the model gets "Authored tool model context unavailable" in place of the result. Keep the view short, because it stays whole in every later request, up to 16,000 characters.
* **Raising limits hides the real fault.** If a needed value disappears, fix its storage or handoff first. See [Context, memory, and handoffs](https://koreai.mintlify.site/agent-platform/best-practices/context-memory-handoffs.md).
* **Studio edits project compaction only inside the voice profile.** Set the project-wide section by API or project import.

***

**Related articles:**

* [How a turn is built](https://koreai.mintlify.site/agent-platform/context-and-prompts.md) -- visibility modes and what reaches `## Current Context` in the first place.
* [Compaction policy overrides](https://koreai.mintlify.site/agent-platform/abl/reference/agent-declaration.md#compaction-policy-overrides) -- the full `EXECUTION.compaction` property reference.
* [Result compaction](https://koreai.mintlify.site/agent-platform/abl/reference/tools.md#result-compaction) and [Store result](https://koreai.mintlify.site/agent-platform/abl/reference/tools.md#store-result) -- per-tool compaction and `last_<tool>_result`.
* [Tuning for latency](https://koreai.mintlify.site/agent-platform/latency-and-speed.md) -- smaller, stable prompts as a speed lever.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.