hermes - ✅(Solved) Fix [Feature]: expose protect_first_n in config [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#13751Fetched 2026-04-22 08:04:21
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×3cross-referenced ×1

Fix Action

Fixed

PR fix notes

PR #13754: feat(compression): make protect_first_n configurable

Description (problem / solution / changelog)

What does this PR do?

The number of head messages preserved verbatim across context compactions was previously hardcoded to 3 in AIAgent.init. Expose it as compression.protect_first_n in config, matching the existing protect_last_n pattern.

Motivation: users who rely on rolling compaction for long-running sessions had the opening user/assistant exchange pinned as head forever, which doesn't always match how they want the session framed after many compactions. Lowering to 1 preserves only the system prompt and lets the first exchange age out naturally through the summary.

Related Issue

Fixes #13751

Type of Change

<!-- Check the one that applies. -->
  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

<!-- List the specific changes. Include file paths for code changes. -->
  • hermes_cli/config.py: add default (3) + show_config() line
  • run_agent.py: read from config with max(1, ...) floor so the system prompt always survives head-protection
  • cli-config.yaml.example: document with rationale

How to Test

<!-- Steps to verify this change works. For bugs: reproduction steps + proof that the fix works. -->
  1. Modify the protect_first_n config variable
  2. Run a compress
  3. Inspect head length to ensure it respects variable setting.

Checklist

<!-- Complete these before requesting review. -->

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Ubuntu 24.04

Documentation & Housekeeping

<!-- Check all that apply. It's OK to check "N/A" if a category doesn't apply to your change. -->
  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Changed files

  • cli-config.yaml.example (modified, +10/-0)
  • hermes_cli/config.py (modified, +6/-0)
  • run_agent.py (modified, +7/-1)
  • scripts/release.py (modified, +1/-0)
  • tests/agent/test_context_compressor.py (modified, +43/-0)
RAW_BUFFERClick to expand / collapse

Problem or Use Case

Compression preserves a head that's currently set to protect_first_n=3, hard-coded. I would like to not have compression preserve the first turn.

Proposed Solution

A protect_last_n already is exposed to config, so I figured the easiest path forward would be to expose a parallel config variable.

Alternatives Considered

Could just hard-code it in my fork, but might as well upstream the change.

Feature Type

Configuration option

Scope

Small (single file, < 50 lines)

Contribution

  • I'd like to implement this myself and submit a PR

Debug Report (optional)

extent analysis

TL;DR

Exposing a new configuration variable to control the preservation of the first turn during compression is the most likely fix.

Guidance

  • Introduce a new configuration option, e.g., protect_first_n, to allow users to control whether the first turn is preserved during compression.
  • Update the compression logic to respect the new configuration option, defaulting to the current hard-coded behavior if the option is not set.
  • Consider adding validation for the new configuration option to ensure it is a non-negative integer.
  • Document the new configuration option in the relevant documentation to inform users of its purpose and usage.

Example

# Example of how the new configuration option could be implemented
config = {
    # ...
    'protect_first_n': 0,  # default to not preserving the first turn
    # ...
}

# Update compression logic to respect the new configuration option
if config['protect_first_n'] > 0:
    # preserve the first turn
else:
    # do not preserve the first turn

Notes

The introduction of a new configuration option may require updates to existing tests and documentation to ensure compatibility and inform users of the change.

Recommendation

Apply workaround by introducing the new configuration option, as it provides a flexible solution that allows users to control the behavior of the compression algorithm.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix [Feature]: expose protect_first_n in config [1 pull requests, 1 participants]