fix(core): propagate acting middleware result rewrites - #2676
Open
dangzitou wants to merge 2 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes ReActAgent acting-phase middleware rewrites so that transformed tool-result events are what downstream consumers observe and what the next model iteration receives, addressing issue #2672.
Changes:
- Publish acting-phase tool-result events after the
onActingmiddleware chain, not before it. - Detect when middleware replaces/filters tool-result delta/end events and rebuild only the affected
ToolResultBlockvalues (preserving original instances when unchanged). - Add an end-to-end regression test ensuring a middleware rewrite is reflected both in the public event stream and the subsequent model request.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java | Moves event publication post-middleware and reconstructs tool results from the transformed event stream when needed. |
| agentscope-core/src/main/java/io/agentscope/core/middleware/MiddlewareBase.java | Documents that tool-result delta-event transformations affect the next-iteration result message. |
| agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentNewLoopE2ETest.java | Adds an E2E regression test covering acting middleware rewriting tool results for events and next model call. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+2693
to
+2694
| List<AgentEvent> coreToolResultEvents = new ArrayList<>(); | ||
| List<AgentEvent> transformedToolResultEvents = new ArrayList<>(); |
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.
AgentScope-Java Version
2.0.3-SNAPSHOT
Description
Fixes #2672.
ReActAgent.actingStreampublished raw tool-result events before theonActingmiddleware chain. The acting phase then discarded the post-middleware events and continued with the rawresultHolder, so a middleware rewrite was visible neither to event consumers nor to the next model call.This change:
ToolResultBlockvalues from the transformed stream;The new end-to-end regression test rewrites
search:alphatorewritten. On current main it failed because the public stream returnedsearch:alpha; with this change both the public stream and the second model request contain onlyrewritten.Tests
mvn -pl agentscope-core -Dtest=ReActAgentNewLoopE2ETest#actingMiddlewareCanRewriteToolResultForEventsAndNextModelCall test— 1 passedmvn -pl agentscope-core -Dtest=ReActAgentNewLoopE2ETest,ReActAgentMiddlewareIntegrationTest test— 12 passedmvn -pl agentscope-core test— 2275 passed, 9 skippedCompatibility and risk
No public API signatures change. Existing tool results retain their original
ToolResultBlockinstance unless middleware actually changes the tool-result event sequence. Text and data deltas, metadata, and end state are retained when rebuilding a transformed result.Checklist
mvn spotless:apply