Skip to content

feat(hooks): add pre_context_compress hook#3741

Closed
eloklam wants to merge 1 commit into
NousResearch:mainfrom
eloklam:feature/pre-context-compress
Closed

feat(hooks): add pre_context_compress hook#3741
eloklam wants to merge 1 commit into
NousResearch:mainfrom
eloklam:feature/pre-context-compress

Conversation

@eloklam

@eloklam eloklam commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds pre_context_compress hook that fires before context compression, enabling alternative context management strategies (LCM, RAG, vector DB, etc.).

Install:

No installation required — hook is available immediately for extensions to register.

Usage:

Extensions register the hook in their register() function:

def register(ctx):
    ctx.register_hook("pre_context_compress", my_context_handler)

The handler receives session_id, messages, token_budget, model, platform and can return an alternative messages array. Falls back to default compression if no extension handles it.

Files

File Description
hermes_cli/plugins.py Add pre_context_compress to VALID_HOOKS
run_agent.py Add hook invocation before _compress_context() with fallback logic

Tests

Handler loads correctly when no extensions registered, runs without error, falls back to default compression, receives correct parameters. pytest tests/test_plugins.py -v (19 tests pass, 4.06s).

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.

1 participant