Skip to content

feat(compression): configurable protect_first_n/protect_last_n turns (reopen #756) - #27090

Closed
Master-Rensei wants to merge 1 commit into
NousResearch:mainfrom
Master-Rensei:feat/configurable-compaction-protection
Closed

feat(compression): configurable protect_first_n/protect_last_n turns (reopen #756)#27090
Master-Rensei wants to merge 1 commit into
NousResearch:mainfrom
Master-Rensei:feat/configurable-compaction-protection

Conversation

@Master-Rensei

Copy link
Copy Markdown

Summary

Reopening closed PR #756 (not merged). Adds protect_first_n and protect_last_n to the compression config in config.yaml, allowing users to control how many initial and recent turns are preserved during context compression.

Changes

  • hermes_cli/config.py: Added protect_first_n: 3 and protect_last_n: 4 to DEFAULT_CONFIG.compression. Bumped config version to 6.
  • run_agent.py: Reads protection values from config.yaml (with 0-12 clamping). Also improved to read threshold and summary_model from config.yaml rather than only env vars.
  • tests/test_compression_config.py: 8 tests covering defaults, config version, ContextCompressor param passing, and clamping logic.

Config Example

compression:
  enabled: true
  threshold: 0.85
  protect_first_n: 3   # Initial turns to always preserve (0-12)
  protect_last_n: 4    # Recent turns to always preserve (0-12)

Inspired by openclaw's recentTurnsPreserve config (clamped 0-12, default 3) from v2026.3.7.

Related: #525, closes #756

Add protect_first_n and protect_last_n to the compression config section
in config.yaml, allowing users to control how many initial and recent
turns are preserved during context compression.

- Default values: protect_first_n=3, protect_last_n=4 (no behavior change)
- Values clamped to 0-12 range (inspired by openclaw recentTurnsPreserve)
- Config version bumped to 6 for migration
- Also improved run_agent.py to read compression config from config.yaml
  (previously only read from env vars)

Related: #525 (microcompact)
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Note: protect_first_n was already made configurable in #25447 (merged). This PR may still add protect_last_n configurability and config version bump.

@Master-Rensei Master-Rensei closed this by deleting the head repository May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants