fix(core): fix ReActAgent stream event block end ordering#1829
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes ReActAgent streaming event lifecycle ordering so block end events (thinking/text/tool-call) are emitted at the correct transition points instead of being deferred until MODEL_CALL_END, addressing #1634.
Changes:
- Introduced a per-model-call lifecycle helper to coordinate start/end flushing for text, thinking, and tool-call blocks during
streamEvents. - Adjusted end-event emission so thinking ends before text begins, and active blocks are flushed before tool-call/model-call boundaries.
- Extended end-to-end tests to assert correct ordering across thinking→text, text/thinking→tool-call, multiple tool calls, and summary model-call flows.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java | Adds a model-call-scoped block lifecycle tracker and updates streaming emission to flush block end events at transition points. |
| agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentNewLoopReplyTest.java | Adds ordering-focused tests to validate corrected stream event sequencing and prevent regressions. |
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
PR #1829 fixes issue #1634: ReActAgent streamEvents streaming event ordering was incorrect. The original implementation deferred THINKING_BLOCK_END, TEXT_BLOCK_END, and TOOL_CALL_END events until MODEL_CALL_END, causing frontend consumers to be unable to correctly distinguish block boundaries. The fix introduces a ModelCallBlockLifecycle inner class that flushes previous block END events at block transition points (thinking→text, any→tool-call, any→model-call-end), ensuring strictly ordered event streams. The change involves +94/-59 lines in ReActAgent.java and a new ReActAgentNewLoopReplyTest.java with comprehensive test coverage. The concurrency strategy (AtomicBoolean + ConcurrentHashMap) remains sound. The code is well-structured and the tests are thorough. No blocking issues found.
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
PR #1829 fixes issue #1634: ReActAgent streamEvents streaming event ordering was incorrect. The original implementation deferred THINKING_BLOCK_END, TEXT_BLOCK_END, and TOOL_CALL_END events until MODEL_CALL_END, causing frontend consumers to be unable to correctly distinguish block boundaries. The fix introduces a ModelCallBlockLifecycle inner class that flushes previous block END events at block transition points (thinking→text, any→tool-call, any→model-call-end), ensuring strictly ordered event streams. The change involves +94/-59 lines in ReActAgent.java and a new ReActAgentNewLoopReplyTest.java with comprehensive test coverage. The concurrency strategy (AtomicBoolean + ConcurrentHashMap) remains sound. The code is well-structured and the tests are thorough. No blocking issues found.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Description:
Close #1634
Fixes ReActAgent
streamEventsblock lifecycle ordering so text, thinking, and tool-call end events are emitted at the correct transition points instead of being deferred untilMODEL_CALL_END.Code Changes & Architecture
Fixed model-call block lifecycle ordering:
ModelCallBlockLifecycleto manage active text, thinking, and tool-call blocks within a single model-call stream.THINKING_BLOCK_ENDbeforeTEXT_BLOCK_START.TEXT_BLOCK_END,THINKING_BLOCK_END, and priorTOOL_CALL_ENDevents before a newTOOL_CALL_START.MODEL_CALL_END.Preserved concurrency-safe state tracking:
AtomicBooleanfor text/thinking lifecycle state.ConcurrentHashMapfor active tool-call tracking.Extended stream event ordering tests:
Event output log before and after repair
使用如下输入用例测试(Text+Thinking+mult Tool Call):“请先讲一个简单的冷笑话,再并行查北京、杭州天气。”
然后这里对输出做了简化,所有 delta 只保留第一个,其它原样输出。
修复前
修复后
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)