Skip to content

feat(compression): optimize context compressor via autoresearch - #2866

Closed
SSGREAPER wants to merge 14 commits into
NousResearch:mainfrom
SSGREAPER:autoresearch/compressor-optimization
Closed

feat(compression): optimize context compressor via autoresearch#2866
SSGREAPER wants to merge 14 commits into
NousResearch:mainfrom
SSGREAPER:autoresearch/compressor-optimization

Conversation

@SSGREAPER

Copy link
Copy Markdown
Contributor

Summary

Applied Karpathy's autoresearch pattern to autonomously optimize the context compressor. An agent loop ran 50 experiments, evaluating each change against a composite metric (info retention, compression ratio, structural integrity, test regression). 8 improvements were kept.

Changes discovered by the autoresearch loop:

  • Summary budget: _SUMMARY_RATIO 0.20 → 0.30 (50% more budget for summaries)
  • Min summary tokens: 2000 → 500 (prevents summary inflation on short conversations)
  • Max summary tokens: 8000 → 4000 (tighter cap prevents bloated summaries)
  • Tail token budget: 20,000 → 8,000 (more aggressive compression)
  • Truncation limits: 3000 → 4500 chars per message (retains more tool output)
  • File path pre-extraction: New regex-based pass that detects all file paths and appends them with "MUST appear in summary" — forces the summarizer to preserve them
  • Template restructure: Moved "Relevant Files" and "Critical Context" above "Progress" sections; merged "Key Decisions" + "Constraints & Preferences"
  • Mandatory preservation rules: Explicit instructions in both prompts that file paths, error messages, commands, and specific values must be preserved verbatim

Issues addressed

Metrics (composite score 0–1, higher is better)

Metric Before After Change
Composite 0.6346 0.6572 +3.6%
Info retention 0.828 0.867 +4.7%
Compression ratio 0.011 0.035 3x
Structural integrity 1.0 1.0
Tests pass pass

Test plan

  • All existing compression tests pass (test_compression_boundary.py, test_context_compressor.py)
  • Structural integrity validated (tool pairs, role alternation)
  • 50 automated experiments with keep/revert evaluation
  • Manual testing on long gateway sessions (Discord/Telegram)

🤖 Generated with Claude Code + autoresearch

DeadMan and others added 14 commits March 18, 2026 01:50
…le; gitignore local plans and ported skills
Applied Karpathy's autoresearch pattern to autonomously optimize the
context compressor. 50 experiments run, 8 improvements kept.

- _SUMMARY_RATIO 0.20 → 0.30 (more budget for summaries)
- _MIN_SUMMARY_TOKENS 2000 → 500 (no inflation on short conversations)
- _MAX_SUMMARY_TOKENS 8000 → 4000 (tighter cap)
- _DEFAULT_TAIL_TOKEN_BUDGET 20000 → 8000 (more aggressive compression)
- Truncation 3000 → 4500 chars (retains more tool output)
- Regex file path pre-extraction with "MUST appear in summary"
- Template restructured: Relevant Files + Critical Context moved up
- MANDATORY PRESERVATION RULES added to both prompts

Addresses #705, #1273, and context drift from lossy summarization.
Score improved 3.6% (0.6346 → 0.6572).
@teknium1

Copy link
Copy Markdown
Contributor

Closing this PR:

1. PR is unmergeable. 1,733 files changed, 280K+ additions — the branch includes 13 unrelated commits (MCP errors, Cerebras/Groq providers, gateway fixes, lock files) on top of the compressor change. GitHub can't even render the diff. The actual compressor change is 1 commit in 1 file, buried under everything else.

2. Compression tuning changes are risky without real-world validation. The autoresearch loop optimized against its own synthetic evaluation metric — that's circular. A 3.6% composite score improvement on a synthetic benchmark doesn't justify changing defaults that affect every user's compression behavior. Specifically:

  • Halving _MAX_SUMMARY_TOKENS (8000 → 4000) conflicts with our Gemini auxiliary model's 12K summary cap
  • Halving _DEFAULT_TAIL_TOKEN_BUDGET (20000 → 8000) means substantially more information loss on long sessions
  • These parameters were tuned through real-world usage over months

3. Some ideas have merit. The file path pre-extraction regex and mandatory preservation rules for error messages/commands are worth exploring — but as a separate, clean PR with real-world testing on long gateway sessions, not as autoresearch-tuned constants.

If you want to resubmit the compressor changes, please open a PR with only the context_compressor.py changes on a fresh branch from current main.

@teknium1 teknium1 closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants