$ ssh clawdbot.space --loading...
$ ssh clawdbot.space --loading...
Master token budgeting to keep your agent fast, accurate, and cost-effective.
Every LLM has a context window limit. When your agent exceeds it, responses degrade β hallucinations increase, instructions get forgotten, and costs skyrocket. This guide teaches you to manage context like a pro: what to keep, what to compress, and what to offload.
Every token in your context window costs money on every API call. A bloated 100K context at $15/M tokens = $1.50 per request.
LLMs perform worse with irrelevant context. Studies show accuracy drops 20-30% when context is cluttered with irrelevant information.
Larger context = slower responses. Time-to-first-token increases proportionally with context size.
| Component | Tokens | Priority | Notes |
|---|---|---|---|
| SOUL.md | ~500-2K | Always loaded | Agent identity and core instructions. Keep concise. |
| AGENTS.md | ~300-1K | Always loaded | Role definitions. Grows with multi-agent setups. |
| memory.md | ~1K-10K | Always loaded | Biggest culprit for bloat. Must be actively managed. |
| Active conversation | ~2K-50K | Dynamic | Current chat history. Auto-managed by sliding window. |
| Tool results | ~1K-20K | Per-call | Web scrapes, file reads, search results. Can explode quickly. |
Review memory.md every week. Remove outdated facts, merge duplicates, and move structured data to SQLite. Target: under 2K tokens.
openclaw memory status # Check current token count
Not everything needs to be in context always. Use @include directives to load sections conditionally based on the current task.
# In SOUL.md: @include(coding-rules.md) when task.type == 'code' @include(writing-style.md) when task.type == 'write'
Web scrapes can be 10K+ tokens. Use the built-in summarizer to compress results before injecting into context.
openclaw config set tools.web.summarize true openclaw config set tools.web.max_tokens 2000
Limit how many previous messages stay in context. Older messages get summarized automatically.
openclaw config set context.sliding_window 20 openclaw config set context.summary_after 10
Use SQLite or vector databases for large knowledge bases. Query on-demand instead of keeping everything in context.
openclaw memory index --to sqlite # Queries memory only when relevant
| Component | Budget | Tip |
|---|---|---|
| SOUL.md | 800 | One page max. Every word must earn its place. |
| AGENTS.md | 500 | Brief role descriptions. Details go in per-agent files. |
| memory.md | 1,500 | Top 30 facts only. Structured data β SQLite. |
| Conversation history | 8,000 | 20-message sliding window with auto-summarization. |
| Tool results | 3,000 | Summarize all web/file results. Cap per-tool output. |
| Reserved for response | 4,000 | Always leave room for the model to think and respond. |