Skip to content

fix(agent): capture on_pre_compress return value and pass to compressor#7195

Open
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/on-pre-compress-return-discarded
Open

fix(agent): capture on_pre_compress return value and pass to compressor#7195
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/on-pre-compress-return-discarded

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Captures the return value of MemoryProvider.on_pre_compress() and passes it through to the context compressor's summarization prompt. Previously, the return value was silently discarded — every memory plugin returning compression context was broken without any error.

The fix threads memory_context through three layers:

  1. run_agent.py — captures the return value
  2. compress() — accepts and forwards the new parameter
  3. _generate_summary() — injects a "MEMORY PROVIDER INSIGHTS" section into the summarization template when non-empty

Related Issue

Fixes #7192

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • run_agent.py line ~6078: Capture on_pre_compress() return value into pre_compress_context; pass to compress() as memory_context=
  • agent/context_compressor.py compress(): Add memory_context: str = "" parameter; forward to _generate_summary()
  • agent/context_compressor.py _generate_summary(): Add memory_context: str = "" parameter; conditionally inject "MEMORY PROVIDER INSIGHTS" section into both the iterative-update and first-compaction prompts

How to Test

  1. Enable a memory provider that returns text from on_pre_compress() (e.g., Honcho, or a test stub)
  2. Have a conversation long enough to trigger compression (or use /compress)
  3. Verify (via DEBUG logs) that the provider's returned text appears in the summarization prompt
  4. Verify the compression summary references provider insights when relevant

For code review only (no runtime test harness):

  1. Read run_agent.py line ~6078 — confirm return value is now captured
  2. Read compress() signature — confirm memory_context parameter exists
  3. Read _generate_summary() — confirm the "MEMORY PROVIDER INSIGHTS" section is injected conditionally

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15 (Darwin 24.6.0)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

N/A — see commit description and PR diff.

The MemoryProvider.on_pre_compress() hook returns text that providers
want preserved in the compression summary, but run_agent.py discarded
the return value. Additionally, compress() and _generate_summary() had
no mechanism to accept this context.

- Capture on_pre_compress() return value in run_agent.py
- Add memory_context parameter to compress() and _generate_summary()
- Inject memory provider insights into summarization prompts

Fixes all MemoryProvider plugins that return context from
on_pre_compress() (currently silently broken for every plugin).
@Tranquil-Flow Tranquil-Flow force-pushed the fix/on-pre-compress-return-discarded branch from 6b9ce96 to 9d2a83c Compare May 25, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MemoryProvider.on_pre_compress() return value silently discarded — provider insights never reach the compressor

2 participants