feat(hermes): add on_pre_compress hook to preserve context before compression#870
Open
pyrate-llama wants to merge 1 commit intovectorize-io:mainfrom
Open
feat(hermes): add on_pre_compress hook to preserve context before compression#870pyrate-llama wants to merge 1 commit intovectorize-io:mainfrom
pyrate-llama wants to merge 1 commit intovectorize-io:mainfrom
Conversation
…pression When Hermes compresses its context window to save tokens, the original messages are summarized and the full text is discarded. This adds an on_pre_compress lifecycle hook that fires just before compression, capturing the last 10 user/assistant messages and persisting them to the Hindsight knowledge graph via retain(). The retain call runs in a background thread so it never blocks the compression pipeline. Messages are truncated to 500 chars each and tagged with [Pre-compression context] for easy identification. Requires hermes-agent >= 0.7.0 which supports the on_pre_compress hook. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
on_pre_compresslifecycle hook to the Hermes integration that fires before context window compressionretain()Motivation
When Hermes compresses its context window to save tokens, the original messages are summarized and the full text is discarded. This means potentially valuable context is lost forever. By hooking into the compression lifecycle, we can preserve those messages in Hindsight's knowledge graph where they remain searchable via
recall()andreflect().This was inspired by ByteRover's
on_pre_compressimplementation, adapted to use Hindsight's syncretain()API.Details
[Pre-compression context]prefix for easy identificationon_pre_compresshookTest plan