# Context management

> How PentAGI keeps long flows within the model's context window by summarizing older parts of each agent's chain, and the settings that tune it.

Long [flows](https://pentagi.com/docs/glossary/#flow) produce more conversation than any model can hold. PentAGI keeps each [agent](https://pentagi.com/docs/glossary/#agent)'s chain within bounds with **chain summarization**: after every agent turn, older sections are condensed while the most recent ones stay in full unless they outgrow their size limits. If PentAGI knows the model's context window — from its built-in model catalogs, or from a custom endpoint whose model list reports it — and the chain still does not fit, it is compacted once more right before the model call. Ollama models and others with an unknown window get no such step, so lower the sizes below for a model with a small context.

```mermaid
flowchart TD
  accTitle: Chain summarization steps after each agent turn and before each model call
  A[Agent turn finished] --> B[Condense each older section into one summary]
  B --> C[Keep the recent sections within their size limits]
  C --> D[Summarize old question-answer pairs]
  D --> E{Next model call: fits the context window?}
  E -->|Yes| F[Send the chain]
  E -->|No| G[Compact to the window size]
  G --> F
```

## [Tuning](https://pentagi.com/docs/concepts/context/#tuning)

The defaults suit most models. Agents and the interactive [assistant](https://pentagi.com/docs/glossary/#assistant) have separate settings; the assistant keeps more recent history.

| Setting                                            | Agents                            | Assistant                                   |
| -------------------------------------------------- | --------------------------------- | ------------------------------------------- |
| Cap the recent sections                            | `SUMMARIZER_PRESERVE_LAST=true`   | `ASSISTANT_SUMMARIZER_PRESERVE_LAST=true`   |
| Recent section size limit                          | `SUMMARIZER_LAST_SEC_BYTES=51200` | `ASSISTANT_SUMMARIZER_LAST_SEC_BYTES=76800` |
| Largest single [tool](https://pentagi.com/docs/glossary/#tool) result | `SUMMARIZER_MAX_BP_BYTES=16384`   | `ASSISTANT_SUMMARIZER_MAX_BP_BYTES=16384`   |
| Question-answer sections kept                      | `SUMMARIZER_MAX_QA_SECTIONS=10`   | `ASSISTANT_SUMMARIZER_MAX_QA_SECTIONS=7`    |
| Size of those sections                             | `SUMMARIZER_MAX_QA_BYTES=65536`   | `ASSISTANT_SUMMARIZER_MAX_QA_BYTES=76800`   |
| Recent sections not condensed                      | `SUMMARIZER_KEEP_QA_SECTIONS=1`   | `ASSISTANT_SUMMARIZER_KEEP_QA_SECTIONS=3`   |

With `false`, the recent sections have no size limit of their own, and the single tool result limit does not apply either.

`SUMMARIZER_USE_QA` enables the question-answer strategy (on by default) and `SUMMARIZER_SUM_MSG_HUMAN_IN_QA` also summarizes your own messages inside it (off by default). Both apply to agents only: the assistant always uses the strategy and never summarizes your messages.