Skip to content

feat: add structured context compression (6-phase algorithm)#2333

Open
diegofornalha wants to merge 1 commit intosipeed:mainfrom
diegofornalha:feat/context-compression
Open

feat: add structured context compression (6-phase algorithm)#2333
diegofornalha wants to merge 1 commit intosipeed:mainfrom
diegofornalha:feat/context-compression

Conversation

@diegofornalha
Copy link
Copy Markdown

Summary

  • Iterative summaries (updates previous, doesn't recreate)
  • Structured template: Goal/Progress/Decisions/Files/Next Steps
  • Token-budget tail protection (not fixed message count)
  • Tool pair integrity (adds stubs for orphan calls, removes orphan results)
  • LLM-agnostic (returns prompt for external summarization)

Test plan

  • Run go test ./pkg/agent/... — 12 tests passing
  • Verify compression preserves tool call/result pairs
  • Test with varying token budgets

🤖 Generated with Claude Code

@sipeed-bot sipeed-bot bot added type: enhancement New feature or request domain: agent labels Apr 4, 2026
Implement 6-phase context compression as a pluggable ContextManager:
- Phase 1: Prune old tool results with placeholders
- Phase 2-3: Protect head (system prompt) and tail (token budget)
- Phase 4: Generate structured summary prompt (LLM-agnostic)
- Phase 5: Assemble head + summary + tail
- Phase 6: Sanitize orphaned tool call/result pairs

Registered as "structured" via RegisterContextManager factory.
Activate with: agents.defaults.context_manager = "structured"
Zero breaking change — defaults to "legacy" if unconfigured.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@diegofornalha diegofornalha force-pushed the feat/context-compression branch from 5ff216f to 6968cf3 Compare April 5, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant