plans/agent-context-compaction-2025-03-24-concise.md
Add automatic context compaction to the Agent struct based on configurable triggers (token count, turn count, message count) with a specified maximum token limit.
Create a Compaction struct in crates/forge_domain/src/agent.rs with:
token_threshold: Optional maximum token count triggerturn_threshold: Optional maximum turns triggermessage_threshold: Optional maximum messages triggermax_tokens: Maximum allowed tokens after compactionshould_compact() method to determine when compaction is neededAdd an optional compact field to the Agent struct that follows existing patterns and merging strategies.
Modify the Orchestrator implementation to:
compact_context() method to handle the compaction processinit_agent_with_event() to check compaction conditions before processingSummarize mechanism for the initial implementationImplement a more accurate token counting function to support compaction decisions.
Transform::Assistant variantAdd tests to verify:
Update documentation with examples of the new configuration:
# Example in forge.yaml
agents:
myAgent:
id: myAgent
model: gpt-4-turbo
system_prompt: "You are a helpful assistant."
compact:
max_tokens: 4000
token_threshold: 6000
turn_threshold: 10
message_threshold: 30
Compaction struct with needed fields and methodsAgent struct correctly handles the new compact fieldCompaction struct to agent.rscompact field to Agent struct