Skip to content

feat: Add SemanticCompressorMemory for dynamic context compression - #1067

Merged
AmitoVrito merged 2 commits into
SynapseKit:mainfrom
ramashishmaurya:feature/semantic-compressor
Oct 13, 2026
Merged

AmitoVrito merged 2 commits into
SynapseKit:mainfrom
ramashishmaurya:feature/semantic-compressor

Conversation

@ramashishmaurya

Copy link
Copy Markdown
Contributor

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 SemanticCompressorMemory solves 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

  • Dynamic Compression: Tracks token limits natively and intelligently grabs the oldest half of the active context to compress into a dense block when a configurable threshold is breached.
  • Cost Saving: Prevents expensive LLMs from constantly reading identical, verbose older histories.
  • Extensible: Simply pass any BaseLLM to the llm argument of the compressor.

Changes

  • Built src/synapsekit/memory/semantic_compressor.py.
  • Exported in src/synapsekit/memory/__init__.py.
  • Wrote full unit test coverage using a mocked compressor VLM in tests/memory/test_semantic_compressor.py.

ramashishmaurya and others added 2 commits October 1, 2026 09:00
…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 AmitoVrito left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AmitoVrito
AmitoVrito merged commit 2ffdc44 into SynapseKit:main Oct 13, 2026
19 checks passed
AmitoVrito added a commit that referenced this pull request Oct 13, 2026
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.

2 participants