Skip to content

feat(hindsight): add on_pre_compress hook to preserve context before compression - #5794

Closed
pyrate-llama wants to merge 1 commit into
NousResearch:mainfrom
pyrate-llama:feat/hindsight-on-pre-compress
Closed

feat(hindsight): add on_pre_compress hook to preserve context before compression#5794
pyrate-llama wants to merge 1 commit into
NousResearch:mainfrom
pyrate-llama:feat/hindsight-on-pre-compress

Conversation

@pyrate-llama

Copy link
Copy Markdown

Summary

When Hermes compresses its context window to save tokens, the original messages are summarised and 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 Hindsight.

Messages are tagged [Pre-compression context] and retained with context=pre_compress. Runs in a background thread — never blocks compression.

Changes

  • on_pre_compress() method on HindsightMemoryProvider (follows MemoryProvider ABC optional hook)
  • _precompress_thread with proper join on shutdown
  • on_pre_compress registered in plugin.yaml hooks list

Test plan

  • Tested locally with Hermes v0.7.0 + Hindsight
  • Pre-compression messages appear in knowledge graph after compression
  • Background thread confirmed non-blocking

Motivation

Closes vectorize-io/hindsight#870 — standalone plugin discontinued, migration to official Hermes location.

…compression

When Hermes compresses its context window, the original messages are
summarised and discarded. This hook fires just before compression,
capturing the last 10 user/assistant messages and persisting them to
the Hindsight knowledge graph via retain().

Messages are tagged with '[Pre-compression context]' for easy
identification and are retained with context='pre_compress' so they
remain searchable via recall/reflect.

The retain call runs in a background thread so it never blocks the
compression pipeline.

Closes vectorize-io/hindsight#870 (migrated from standalone plugin).
@pyrate-llama
pyrate-llama force-pushed the feat/hindsight-on-pre-compress branch from 0d0649e to 54d099f Compare April 10, 2026 03:45
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins tool/memory Memory tool and memory providers labels Apr 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #11753 (pre-compression task state preservation hook) and closed #3741 (pre_context_compress hook). P3 per plugin-provider-demotion — Hindsight memory plugin feature.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #11753 (pre-compression task state preservation hook) and closed #3741 (pre_context_compress hook).

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the Hindsight preservation work. This is an automated hermes-sweeper review; current main already provides the requested persistence guarantee through a stronger lifecycle.

  • plugins/memory/hindsight/__init__.py:1603 retains every completed user/assistant turn by default through the serialized writer queue.
  • plugins/memory/hindsight/__init__.py:1819 flushes buffered turns during a session switch, including a compression boundary; commit 0a5ee01e487a5a4e0e3637ecce6c2a41546c9457 specifically serialized that flush behind queued retains.
  • agent/context_compressor.py:2885 summarizes the middle window while preserving the recent tail. The proposed messages[-10:] capture at PR line 897 would therefore retain messages that normally survive compaction rather than the discarded region.

Closing as implemented on main.

@teknium1 teknium1 closed this Jul 12, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have sweeper:implemented-on-main Sweeper: behavior already present on current main tool/memory Memory tool and memory providers type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants