Repository navigation
feat: Add SemanticCompressorMemory for dynamic context compression - #1067
Merged
AmitoVrito merged 2 commits intoOct 13, 2026
Merged
Conversation
…mport order Replaced the unittest.mock.AsyncMock-based test fixture with a hand-written FakeCompressorLLM per house testing standards (MagicMock silently accepts anything, which previously masked a real async bug elsewhere in the codebase). Tightened SemanticCompressorMemory.llm from Any to BaseLLM for consistency with the rest of the memory package, and fixed the un-sorted import in memory/__init__.py. Co-authored-by: Ashish Maurya <[email protected]>
AmitoVrito
approved these changes
Oct 13, 2026
AmitoVrito
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed and hardened before merge: replaced the unittest.mock.AsyncMock test fixture with a hand-written FakeCompressorLLM per house testing standards, tightened the llm param from Any to BaseLLM, and fixed an import-sort lint error.
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.
Overview
This PR introduces the
SemanticCompressorMemory, an advanced memory backend that automatically summarizes older parts of a conversation into dense, structured blocks when the context window reaches a predefined token threshold.Why?
Long-running agents (like coding assistants or roleplay bots) eventually fill up the context window.
Traditionally, memory managers either use a naive sliding window (which deletes the oldest messages causing "amnesia") or simply crash.
The
SemanticCompressorMemorysolves this by using a fast, cheap LLM (like Llama 3 8B or GPT-4o-mini) to dynamically merge the existing summary with new exchanges, preserving core instructions, critical entities, and ongoing state indefinitely—while staying perfectly within token bounds and saving massive API costs on larger models.Features
BaseLLMto thellmargument of the compressor.Changes
src/synapsekit/memory/semantic_compressor.py.src/synapsekit/memory/__init__.py.tests/memory/test_semantic_compressor.py.