Skip to content

fix: improve context compression quality — higher limits, tool tracking, degradation warning#4156

Closed
SHL0MS wants to merge 1 commit into
NousResearch:mainfrom
SHL0MS:fix/compression-quality-v2
Closed

fix: improve context compression quality — higher limits, tool tracking, degradation warning#4156
SHL0MS wants to merge 1 commit into
NousResearch:mainfrom
SHL0MS:fix/compression-quality-v2

Conversation

@SHL0MS

@SHL0MS SHL0MS commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

Three targeted improvements to the compression system that address the most impactful remaining quality issues documented in #499.

1. Increase serializer truncation limits

Content type Before After
Tool results 3,000 chars (2000+800) 6,000 chars (4000+1500)
Assistant content 3,000 chars 6,000 chars
Tool call arguments 500 chars 1,500 chars
User messages 3,000 chars 6,000 chars

The summarizer LLM was working from heavily truncated data. The budget is the summary model's context window, not the main model's.

2. Add "Tools & Patterns" section to compression prompts

Both templates now include:

## Tools & Patterns
[Which tools were used, how they were used effectively, and any
tool-specific discoveries]

Preserves HOW tools were used effectively across compaction boundaries.

3. Degradation warning on repeated compressions

After 2nd compression:

⚠️  Session compressed 3 times — accuracy may degrade. Consider /new to start fresh.

compression_count was tracked but never surfaced.

Changes

24 insertions, 9 deletions across agent/context_compressor.py and run_agent.py. Clean diff on latest main.

Ref #499 (supersedes #4153 which had merge conflicts)

@SHL0MS SHL0MS force-pushed the fix/compression-quality-v2 branch from 353dd6e to 6f08887 Compare March 31, 2026 03:33
…king, degradation warning

Three targeted improvements to the compression system:

1. Replace hardcoded truncation limits with named class constants
   (_CONTENT_MAX=6000, _CONTENT_HEAD=4000, _CONTENT_TAIL=1500,
   _TOOL_ARGS_MAX=1500, _TOOL_ARGS_HEAD=1200). Previous limits
   (3000/500) heavily truncated the summarizer's input — a 200-line
   edit got cut to 3000 chars before the summarizer ever saw it.

2. Add '## Tools & Patterns' section to both compression prompt
   templates (first-pass and iterative). Preserves working tool
   invocations, preferred flags, and tool-specific discoveries
   across compaction boundaries.

3. Warn users on 2nd+ compression: 'Session compressed N times —
   accuracy may degrade. Consider /new to start fresh.'

Ref NousResearch#499
@teknium1

teknium1 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #6395 — your commit was cherry-picked onto current main with authorship preserved. One small test fix added on top (MagicMock needed compression_count set as int). Thanks for the quality improvements, @SHL0MS!

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

Labels

type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants