RFC: Let Your Agent Control Its Own Context Compaction
A new RFC in the OpenClaw repository (#28845) proposes a fundamental shift in how context compaction works: instead of the system automatically deciding when and how to compact conversation history, agents would get a tool to control the process themselves.
The Problem with Automatic Compaction
Currently, OpenClaw automatically triggers compaction when your context window approaches capacity. The system summarizes older messages to make room for new ones. This works, but it has a costly flaw: compaction uses your session's main model.
If you're running Claude Opus or GPT-4 for quality conversations, every compaction event burns expensive tokens on what is essentially a summarization task. A cheaper model could do this job just as well, but there's no way to configure that today.
The Proposed Solution
The RFC suggests exposing compaction as a tool the agent can call directly. Instead of the system deciding when to compact, the agent would:
- Monitor its own context usage (already visible in session metadata)
- Decide when compaction makes sense based on conversation flow
- Call a
compact_contexttool with parameters like target length or which messages to preserve - Optionally specify a different model for the summarization task
This gives agents situational awareness that automatic systems lack. An agent might choose to delay compaction during a complex multi-step task where recent context is critical, then compact aggressively during a natural pause in conversation.
Community Discussion
A commenter on the issue noted that a simpler compaction.model config override (from issue #7926) could solve the cost problem without the full tool-based approach. They're right that both address the same core inefficiency: using expensive session models for summarization work.
The maintainers seem open to either approach. A config-based model override would be easier to implement and wouldn't require agents to learn new behavior. But the tool-based approach offers more flexibility for sophisticated agents that want fine-grained control.
Why This Matters
Context compaction is one of those invisible costs that adds up. If you're running long conversations with premium models, you're paying premium prices for what should be commodity summarization work. Even a simple config option to route compaction to a cheaper model could meaningfully reduce costs for heavy users.
The broader question is whether agents should have more control over their own memory management. The RFC leans toward yes, arguing that agents with tool access are already trusted to make consequential decisions. Letting them manage their context window seems like a natural extension.
You can follow the discussion and add your thoughts on GitHub issue #28845.
Comments (0)
No comments yet. Be the first to comment!