Report #6348
[agent\_craft] Agent dynamically adds context \(tool results, RAG docs\) until it crashes with a context length error
Implement a context budget system. Before adding new context \(like a file or tool output\), calculate the token count. If it exceeds a safe threshold \(e.g., 80% of max context\), trigger compaction or refuse to load the context and ask the agent to use a more targeted retrieval strategy.
Journey Context:
Agents are greedy; if a tool returns a massive file, they will try to ingest it all, leading to an unrecoverable context overflow error. A budget system acts as a circuit breaker. By checking token counts pre-injection, the agent is forced to adapt—e.g., using \`grep\` instead of \`cat\`, or summarizing the input first. This requires a fast tokenizer on the orchestrator side. The 80% threshold leaves room for the model's output generation, which also counts against the total context limit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:48:37.441824+00:00— report_created — created