Context System
How OpenClaw manages conversation context
How OpenClaw manages conversation context
Context is the information the agent uses to understand and respond to your messages. OpenClaw automatically loads relevant context, manages token usage, and compacts context when needed to stay within model limits.
Context includes:
System prompt order matters. LLMs weight the first (and last) tokens in the context window most heavily. So your agent's identity—SOUL.md, AGENTS.md—should go first in the system prompt. Putting operational instructions or long memory dumps before the soul dilutes it and can hurt behavior. For more on why identity matters and how to design it, see Soul & Agent Identity.
OpenClaw automatically loads context:
The agent loads only relevant context:
LLM models have context limits measured in tokens:
Workspace files (AGENTS.md, SOUL.md, TOOLS.md, etc.) are loaded into context at the start of each turn. There is a per-file character limit (default 20,000 characters). If a file exceeds it, OpenClaw keeps the first ~70% and the last ~20%, and drops the middle. No error or warning is shown—your agent may be running on incomplete instructions. If a rule in AGENTS.md seems ignored, it may be in the truncated middle. Check in chat: type /context list; if you see TRUNCATED next to a file, it was cut. Put your most important rules at the top of each file. To allow longer files, increase bootstrapMaxChars (per file) and bootstrapTotalMaxChars (all bootstrap files combined) in config.
Tokens are used for:
When context approaches token limits, OpenClaw compacts it:
Each session maintains its own context:
Different sessions don't share context:
Most token spend is input (system prompt, history, tool definitions). If the agent re-reads a huge AGENTS.md or SOUL.md every turn, costs climb. Keep core identity and critical rules in SOUL.md and AGENTS.md; move long reference material into the memory folder and let the agent fetch what it needs via semantic search. That way each turn only injects relevant excerpts instead of the full manual.