fix(agent): forward reasoning middleware events#2179
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes a genuine event-forwarding bug in ReActAgent's reactive stream pipeline. InboxMiddleware (and any other onReasoning middleware) injects HintBlockEvent values at the outer reasoning middleware boundary, but the original code only called publishEvent at the inner model-call boundary (reasoningStream). Events injected by onReasoning middlewares were thus silently consumed by .then(...) and never reached HarnessAgent.streamEvents().
The fix is minimal and surgically precise: move .doOnNext(this::publishEvent) from the inner reasoningStream() to the outer reasoning() method. The accompanying test directly reproduces the bug scenario and asserts no double-publishing. This correctly resolves issue #2160.
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes a genuine event-forwarding bug in ReActAgent's reactive stream pipeline. InboxMiddleware (and any other onReasoning middleware) injects HintBlockEvent values at the outer reasoning middleware boundary, but the original code only called publishEvent at the inner model-call boundary (reasoningStream). Events injected by onReasoning middlewares were thus silently consumed by .then(...) and never reached HarnessAgent.streamEvents().
The fix is minimal and surgically precise: move .doOnNext(this::publishEvent) from the inner reasoningStream() to the outer reasoning() method. The accompanying test directly reproduces the bug scenario and asserts no double-publishing. This correctly resolves issue #2160.
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Fixes reasoning middleware events not being forwarded to the event stream. The issue was that publishEvent was called inside the middleware chain, but events added by onReasoning middlewares were not published.
Findings
- [Info]
ReActAgent.java:1981-1985— MovedpublishEventto the outer reasoning boundary. Now events fromonReasoningmiddlewares are forwarded. - [Info]
ReActAgent.java:2123— Removed duplicatepublishEventfrommodelCallStreamto avoid double-publishing. - [Info] Test
reasoningMiddlewareEventsAreForwardedExactlyOnce()verifies HintBlockEvent is forwarded and core events are not duplicated.
Verdict
Correct fix with good test coverage. LGTM.
Automated review by github-manager
AgentScope-Java Version
2.0.1-SNAPSHOT
Description
Fixes #2160.
InboxMiddlewareemitsHintBlockEventvalues from itsonReasoning(...)middleware hook, but these events were not observable through
HarnessAgent.streamEvents().The reasoning middleware stream was exhausted with
.then(...), while eventpublication happened inside the nested model-call stream. As a result, events
added directly by
onReasoningmiddleware were discarded from the public eventstream.
This change moves event publication to the outer reasoning middleware boundary
and removes the nested publication point. This ensures that:
HintBlockEventemitted byInboxMiddlewareis forwarded throughstreamEvents().Testing
reasoningMiddlewareEventsAreForwardedExactlyOnce.HintBlockEventfields are preserved.ModelCallStartEventis not duplicated.agentscope-core: 2210 tests passed, 9 skipped, 0 failures.InboxMiddlewareTest: 6 tests passed.agentscope-coreSpotless check passed.Checklist