docs/en/memory/context.mdx
Conversation context is the Agent's short-term memory, containing all messages in the current session (user input, Agent replies, tool calls and results). Proper context management is critical for the Agent's reasoning quality and cost control.
Each conversation turn consists of:
User message → Agent thinking → Tool call → Tool result → ... → Agent final reply
A single turn may include multiple tool calls (controlled by agent_max_steps). All tool calls and results are retained in context until compressed or trimmed.
| Parameter | Description | Default |
|---|---|---|
agent_max_context_tokens | Maximum context token budget | 50000 |
agent_max_context_turns | Maximum conversation turns in context | 20 |
agent_max_steps | Maximum decision steps per turn (tool call count) | 15 |
Configurable via config.json or the /config chat command.
When context exceeds limits, the system automatically compresses to free space. The process has multiple stages:
Before each decision loop, the system checks tool call results in historical turns. Results exceeding 20,000 characters are truncated, keeping only the beginning and end with a truncation notice. Current turn results are not affected.
When conversation turns exceed agent_max_context_turns:
After turn trimming, if tokens still exceed the budget:
When the model API returns a context overflow error:
Conversation messages are persisted to a local database, automatically restored after service restart. Restore strategy:
max(3, max_context_turns / 6) turnsUse these commands in chat to manage context:
| Command | Description |
|---|---|
/context | View current context statistics (message count, role distribution, total characters) |
/context clear | Clear current session context |
/config agent_max_context_tokens 80000 | Adjust context token budget |
/config agent_max_context_turns 30 | Adjust context turn limit |