> For the complete documentation index, see [llms.txt](https://docs.uptiq.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uptiq.ai/platform/platform-resources/agent-executor/context-and-compaction.md). Agents can also search and read this documentation through its [MCP server](https://docs.uptiq.ai/~gitbook/mcp).

# Context and Auto-compaction

Read the context usage ring, and summarize long conversations with Auto-compaction.

## Monitor conversation context <a href="#monitor-conversation-context" id="monitor-conversation-context"></a>

The context window is how much the model can consider at once. Context includes instructions, the tools available, the conversation's messages and tool activity, not just what you type.

1. Send a message in the agent playground, a widget chat or the assistant.
2. After the reply, find the context usage ring beside the chat box.
3. Hover over the ring to see how full the context is and what takes it up.
4. Check the percentage after later turns to see how the conversation grows.

The percentage is measured against the model's actual context size, not a fixed size. In the assistant, the ring shows the main agent's context, not a sub-agent's.

| Category               | What it counts                                  |
| ---------------------- | ----------------------------------------------- |
| **System prompt**      | Instructions and context that guide the model   |
| **Tools**              | Definitions of the tools available to the model |
| **Summary**            | A kept summary of earlier conversation content  |
| **User messages**      | Messages the user sent                          |
| **Assistant messages** | The agent's replies                             |
| **Tool calls**         | Requests the agent made to tools                |
| **Tool results**       | What the tools returned                         |

Model thinking isn't counted as kept conversation content. Where supported, run usage details show reasoning tokens separately. For models reached through OpenRouter, cached input isn't counted twice; the corrected token figures don't change the credits charged for those replies.

## Manage long conversations with Auto-compaction <a href="#auto-compaction" id="auto-compaction"></a>

**Auto-compaction** summarizes older conversation content so the agent can keep working as the context fills. It doesn't remove the full chat history from your view. It is in beta, marked with a **Beta** badge, and its tooltip says it may not work as expected. It is off by default for new and existing agents.

### Turn Auto-compaction on or off <a href="#turn-auto-compaction-on-or-off" id="turn-auto-compaction-on-or-off"></a>

1. Open **Agent Config** > **Agent Behaviour** and find **Auto-compaction**. It appears only on executor versions that support it.
2. Turn the switch on.
3. Set **Compaction threshold** from 50% to 85%, in steps of 5. The default is 85%.
4. Save.
5. Reopen the settings to check that the switch and threshold were kept.

To turn it off, turn the switch off and save. The setting is carried with agent export, import and publishing. See [Agent Behavior](https://docs.uptiq.ai/platform/console/agent-builder/build/agent-behavior.md#auto-compaction).

### View a compaction summary <a href="#view-a-compaction-summary" id="view-a-compaction-summary"></a>

When the context reaches the threshold, the agent summarizes the older conversation and keeps about the newest 15,000 tokens word for word. The summary keeps the goal, the user's requirements, decisions, work in progress, next actions, key facts and open requests.

1. While it summarizes, live progress shows **Compacting the conversation**.
2. The next reply includes **Conversation compacted · View summary**.
3. Select that line to open **Agent Reasoning**.
4. Open **Compacted the conversation** to read the summary and how long compaction took.

The full conversation stays visible to you, and the agent can still read older tool results in full. A running tool or sub-agent doesn't block compaction: its call is kept so its result can still be used. A later compaction updates the kept summary.

### Recovery limits <a href="#recovery-limits" id="recovery-limits"></a>

Compaction is skipped:

* Right after a previous compaction, until there is a new reply.
* When there is too little content to summarize.
* After two failed summaries in the same run.

If summarizing fails and the context reaches 95%, the oldest material can be left out of the model's input to reduce its size. The visible chat history isn't deleted. If the provider still rejects a request as too long, the agent reduces the context further and retries once.

After a long conversation is summarized, restate any critical requirement if the agent seems to have lost it.

***

{% columns %}
{% column width="83.33333333333334%" %}

<p align="right"><em>Maintained by</em> <mark style="color:green;">Abhishek Paul</mark><br><code>AI-assisted, human-approved</code></p>
{% endcolumn %}

{% column width="16.666666666666664%" %}

<div align="left"><img src="https://1326225582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0qmgQjJ5aArDTj2ACFHG%2Fuploads%2Fgit-blob-d034645b4f8f8ee661985f5306b60ded3289653c%2Fmaintainer-abhishek-paul.png?alt=media" alt="" width="60"></div>
{% endcolumn %}
{% endcolumns %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.uptiq.ai/platform/platform-resources/agent-executor/context-and-compaction.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
