Skip to content

feat: context pressure warnings and compaction improvements#2116

Closed
ticketclosed-wontfix wants to merge 1 commit into
NousResearch:mainfrom
ticketclosed-wontfix:feat/context-pressure-compaction
Closed

feat: context pressure warnings and compaction improvements#2116
ticketclosed-wontfix wants to merge 1 commit into
NousResearch:mainfrom
ticketclosed-wontfix:feat/context-pressure-compaction

Conversation

@ticketclosed-wontfix

Copy link
Copy Markdown
Contributor

Summary

Adds context pressure warnings and improves the compaction experience.

Changes

  • Context pressure warnings: The agent now receives internal warnings at 50% and 70% context usage, giving it time to save important state (memory, skills, notes) before compaction triggers at 80%.
  • Compaction summary notification: After compaction, a summary of what was preserved is injected so the model can inform the user about what happened and what context was retained.
  • Threshold bump: Default compression threshold raised from 50% → 80%. The previous 50% was too aggressive — compaction was triggering while conversations still had plenty of headroom, causing unnecessary context loss.
  • last_summary tracking: Exposed on the ContextCompressor so post-compaction notifications can reference the summary text.

Files Changed

  • agent/context_compressor.py — Track last_summary from compaction
  • hermes_cli/config.py — Bump default threshold 50% → 80%
  • run_agent.py — Context pressure warnings at 50%/70%, post-compaction summary injection, threshold default update

Testing

Tested in production across multi-hour Discord sessions. Context warnings give the model time to proactively persist important information before compaction wipes conversation history.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the PR! The core idea here — giving advance notice before compaction fires — is good, but the implementation approach doesn't fit how we handle the message stream.

Hermes enforces strict message role alternation, and we're very careful about not injecting synthetic user messages into the conversation mid-loop. The budget pressure system you referenced as a model actually avoids this — it only ever piggybacks on existing tool results and silently drops the warning if there's no tool result to attach to. The fallback to messages.append({"role": "user", ...}) in this PR would break that invariant, and the post-compaction summary injection that instructs the model to "share this with the user" would derail it from whatever task it was working on.

We also don't want to change the model's behavior around compaction — telling it to proactively save state or inform the user about compaction details adds noise to the conversation and can cause the model to prioritize compaction housekeeping over the user's actual task.

What we do want is to warn the user (not the model) that compaction is approaching — a simple notification in the CLI output or gateway chat, similar to how budget pressure already prints a console line. We'll implement that ourselves since it touches display/gateway plumbing rather than the message stream.

Appreciate the contribution!

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