Repository navigation
feat(auto-contextMemory): implement AutoContextMemory with multi-strategy intelligent context compression and offloading - #1523
Conversation
…text compression and offloading
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR makes AutoContext context compression fully reactive (non-blocking), adds per-strategy enable/disable switches, and improves SYSTEM message handling so multiple SYSTEM prompts are preserved while appending the offload instruction only to the first.
Changes:
- Refactor compression pipeline to
compressIfNeededAsync()using Reactor (Mono/Flux) and deprecate the blockingcompressIfNeeded(). - Add configuration flags to enable/disable compression strategies 1–6.
- Preserve multiple SYSTEM messages in
AutoContextHookand add a unit test covering this behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| agentscope-extensions/agentscope-extensions-autocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java | Converts compression strategies to a reactive pipeline; adds concurrency for some summarization paths; keeps a deprecated blocking wrapper. |
| agentscope-extensions/agentscope-extensions-autocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextHook.java | Switches PreReasoning handling to the async compressor and preserves multiple SYSTEM messages. |
| agentscope-extensions/agentscope-extensions-autocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextConfig.java | Adds per-strategy enable/disable switches and exposes them via getters + builder. |
| agentscope-extensions/agentscope-extensions-autocontext-memory/src/test/java/io/agentscope/core/memory/autocontext/AutoContextHookTest.java | Adds test to ensure multiple SYSTEM messages are preserved and instruction is appended only to the first. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR makes three valuable changes: per-strategy enable/disable flags, multi-SYSTEM message preservation in the hook, and conversion of the compression pipeline from blocking .block() calls to a Reactor chain. The refactor is comprehensive and well-documented, with new tests covering the SYSTEM-preservation and disabled-strategy cases. However, the new concurrent execution in Strategy 4 and Strategy 5 introduces a real thread-safety regression: offloadContext is a plain HashMap and is now mutated from multiple boundedElastic worker threads simultaneously. There are also a few smaller issues (loss of subscribeOn(boundedElastic) in the hook, hard-coded block(60s) in the deprecated wrapper, raw Object[] tuple in Strategy 4, misleading "exhausted" log when all strategies are disabled). Recommend changes before merge.
|
@LearningGp Could you please review the PR? |
|
@shiyiyue1102 PTAL |
|
@shiyiyue1102 could you please review it? |
AgentScope-Java Version
1.0.13-SNAPSHOT
Description
This PR solves issue #1350 by addressing structural and behavioral limitations within
AutoContextMemoryandAutoContextHook.Background & Purpose:
While extending
AutoContextMemory, several limitations restricted flexibility and latency:.block()calls, breaking the reactive chain and degrading performance under heavy compression scenarios.AutoContextHookonly preserved the firstSYSTEMmessage, accidentally wiping out any subsequent system instructions (e.g., roleplay directives alongside system prompts).Changes Made:
AutoContextConfig: Introducedstrategy1Enabledthroughstrategy6Enabled(defaulting to true) to allow fine-grained control over which compression rules execute.AutoContextMemory: Refactored the core implementation to be completely asynchronous using Spring Reactor types (MonoandFlux). All synchronous.block()wrappers were eliminated internally, and the primary entry point is nowcompressIfNeededAsync(). (The synchronouscompressIfNeeded()is kept as a@Deprecatedwrapper for backwards compatibility).AutoContextHook: ModifiedhandlePreReasoningto collect and preserve allSYSTEMmessages. The memory-offloading instruction is now correctly appended to only the firstSYSTEMmessage without discarding the others.AutoContextHookTest,AutoContextMemoryTest, andAutoContextConfigTestto verify that concurrent evaluation logic resolves correctly and that multiple system prompts remain intact.How to test this PR:
mvn clean test -pl agentscope-extensions/agentscope-extensions-autocontext-memory -am.mvn spotless:check.Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)