{{ message }}
feat(compaction): add Headroom context compaction middleware#3568
Open
Srinath279 wants to merge 1 commit into
Open
feat(compaction): add Headroom context compaction middleware#3568Srinath279 wants to merge 1 commit into
Srinath279 wants to merge 1 commit into
Conversation
Compress the message history sent to the LLM — primarily large tool outputs, logs, and search results — at the model-call boundary using the optional `headroom-ai` package. Design: - Non-destructive: runs in `wrap_model_call` and only rewrites the request copy of the messages via `request.override(...)`. Persisted ThreadState keeps full originals, so it is reversible. Complementary to (not a replacement for) SummarizationMiddleware. - Structure-preserving: only string content is mapped back onto the original LangChain messages, so message IDs and tool_calls are intact. Any message-count change or error falls back to the originals (fail_open). - Optional dependency: transparent no-op when `headroom-ai` is absent; middleware is only added to the chain when `compaction.enabled`. - Event-loop safe: async hook offloads compression via asyncio.to_thread. Wiring: lead agent (after summarization) + subagent runtime. Config: new `compaction` section in AppConfig / config.example.yaml (config_version 12 -> 13). New `[compaction]` extra (headroom-ai). Docs: backend/docs/compaction.md + CLAUDE.md. Tests: test_compaction_config.py, test_compaction_middleware.py (use a compress_fn injection seam; never import the heavy ML stack). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
|
@Srinath279, thanks for your contribution. To address the CLA complaint, please make sure your git commit author email is set in your GitHub profile's email settings. |
Collaborator
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.

Compress the message history sent to the LLM — primarily large tool outputs, logs, and search results — at the model-call boundary using the optional
headroom-aipackage.Design:
wrap_model_calland only rewrites the request copy of the messages viarequest.override(...). Persisted ThreadState keeps full originals, so it is reversible. Complementary to (not a replacement for) SummarizationMiddleware.headroom-aiis absent; middleware is only added to the chain whencompaction.enabled.Wiring: lead agent (after summarization) + subagent runtime. Config: new
compactionsection in AppConfig / config.example.yaml (config_version 12 -> 13). New[compaction]extra (headroom-ai). Docs: backend/docs/compaction.md + CLAUDE.md.Tests: test_compaction_config.py, test_compaction_middleware.py (use a compress_fn injection seam; never import the heavy ML stack).
Fixes #
Why
What changed
Surface area
frontend/backend/applanggraph.json, or prompt changedocker/or sandboxed executionskills/backend/pyproject.tomlorfrontend/package.json(say what it buys us)Screenshots / Recording
Bug fix verification
Validation
AI assistance
Tool(s) used:
How you used it: