Skip to content

fix(agent): focus automatic compression on recent user turns#38155

Closed
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/auto-compress-focus
Closed

fix(agent): focus automatic compression on recent user turns#38155
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/auto-compress-focus

Conversation

@konsisumer

Copy link
Copy Markdown
Contributor

What does this PR do?

Automatic context compression now derives a compact focus hint from the latest real user turns when no manual focus topic is supplied. That hint is passed into the existing summary prompt so iterative compactions preserve the current task/topic more strongly and demote stale completed topics.

Related Issue

Fixes #9631

Addressing maintainer feedback

#10088 - maintainer-referenced partial mitigation/template work. The current branch already contains the described template improvements (Completed Actions, Active State, and stronger iterative-summary instructions); this PR builds on that by adding the missing automatic focus derivation path for ordinary auto-compactions.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Test update

Changes Made

  • agent/context_compressor.py: derives an automatic Recent user focus hint from the latest real user turns, skips persisted summary handoff messages, redacts sensitive text, and passes the hint into summary generation when no explicit focus topic is provided.
  • tests/agent/test_compress_focus.py: updates default-focus expectations and covers skipping stale context-summary handoff content.

How to Test

  1. pytest tests/agent/test_compress_focus.py -q - passes (5 passed).
  2. pytest tests/agent/test_context_compressor_summary_continuity.py -q - passes (3 passed).
  3. ruff check agent/context_compressor.py tests/agent/test_compress_focus.py - passes.
  4. python scripts/check-windows-footguns.py agent/context_compressor.py tests/agent/test_compress_focus.py - passes.
  5. git diff --check - passes.
  6. scripts/run_tests.sh - ran the broad suite, but exited non-zero locally with unrelated sandbox/environment failures across other modules (27375 passed, 781 failed). Representative failures include restricted socket binds, denied writes under ~/.hermes, live-system guard blocks around process-signal tests, and optional SDK import timeouts.

Checklist

  • I have read and followed the contributing guidelines
  • My code follows the existing code style
  • I have added or updated tests for my changes
  • I have run the full test suite and all tests pass (wrapper ran locally but failed for unrelated sandbox/environment reasons noted above)
  • I have considered cross-platform compatibility (scripts/check-windows-footguns.py passed for changed files)
  • My changes are focused and do not include unrelated files

Screenshots / Logs

N/A - agent compression behavior change only.

@alaamohanad169-ship-it alaamohanad169-ship-it left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice approach — auto-deriving focus from recent user turns instead of requiring explicit /compress focus is a solid DX improvement. Particularly useful for terminal-heavy workflows where most of the session is tool output but the active task is usually captured in the last 2-3 user messages.

The 260/700/3 constants seem like sensible defaults for catching the active task without pulling in stale context. If the user runs long complex sessions they can increase them.

One nit: the tail_start parameter is reserved but unused — consider removing it from the signature since compress() already has the boundary knowledge.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels Jun 3, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #44687 — your commit was cherry-picked onto current main with your authorship preserved in git log (434c684). Only change on top: dropped the reserved-but-unused tail_start parameter. Thanks!

#44687

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Iterative context compaction summary keeps completed topics alive and overrides the current active topic

4 participants