-
Notifications
You must be signed in to change notification settings - Fork 283
fix(agui): Fix duplicate TextMessageEnd emission (#562) #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AlbumenJ
merged 4 commits into
agentscope-ai:main
from
fishl3j:fix-agui-duplicate-text-message-end
Jan 22, 2026
Merged
fix(agui): Fix duplicate TextMessageEnd emission (#562) #586
AlbumenJ
merged 4 commits into
agentscope-ai:main
from
fishl3j:fix-agui-duplicate-text-message-end
Jan 22, 2026
Conversation
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
9beab1b to
0ec149a
Compare
…n in AguiAgentAdapterTest
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This test covers the new code path at lines 153-158 in AguiAgentAdapter that checks if a message has already been ended before emitting TextMessageEnd event. This fixes the patch coverage issue for commit 9beab1b.
AlbumenJ
approved these changes
Jan 21, 2026
AlbumenJ
requested changes
Jan 21, 2026
Collaborator
AlbumenJ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…text-message-end # Conflicts: # agentscope-extensions/agentscope-extensions-agui/src/test/java/io/agentscope/core/agui/adapter/AguiAgentAdapterTest.java
AlbumenJ
approved these changes
Jan 22, 2026
Alexxigang
pushed a commit
to Alexxigang/agentscope-java
that referenced
this pull request
Jan 25, 2026
…gentscope-ai#586) # Background: Fix Duplicate AguiEvent.TextMessageEnd Issue ## Problem Description When using AGUI protocol to request a ReActAgent with SKILL and TOOL capabilities, the `AguiAgentAdapter` was emitting duplicate `AguiEvent.TextMessageEnd` events, causing incorrect event closure in the AGUI event stream. ## Root Cause The issue occurs in the `convertEvent` method of `AguiAgentAdapter` when processing `REASONING` events that contain both `TextBlock` and `ToolUseBlock` content blocks: 1. **First emission path**: When processing a `ToolUseBlock` ,checks if there's an active text message and attempts to end it before starting the tool call (lines 162-169). 2. **Second emission path**: When processing a `TextBlock` in the last event (`event.isLast() == true`), the code emits `TextMessageEnd` to close the text message (lines 152-158). 3. **The bug**: If a message contains both text content and tool usage, and the text block is processed as the last event, the `TextMessageEnd` is emitted. However, when the subsequent `ToolUseBlock` is processed, the code doesn't check if the message has already been ended, leading to a duplicate `TextMessageEnd` event. ## Impact - **Issue**: [agentscope-ai#562](agentscope-ai#562) - AGUI方式下请求使用Skill的ReActAgent,返回的AguiEvent存在闭合错误 - **Version affected**: 1.0.8-SNAPSHOT - **Symptoms**: - Duplicate `TextMessageEnd` events in the AGUI event stream - Incorrect event closure state - Potential issues with AGUI clients expecting proper event sequencing ## Solution Added a guard check using `state.hasEndedMessage(messageId)` before emitting `TextMessageEnd` events. This ensures that: 1. The message end event is only emitted once per message 2. The state tracking correctly reflects whether a message has been closed 3. The event stream maintains proper sequencing and closure semantics ## Code Changes The fix adds a conditional check before emitting `TextMessageEnd`: ```java if (!state.hasEndedMessage(messageId)) { events.add( new AguiEvent.TextMessageEnd( state.threadId, state.runId, messageId)); state.endMessage(messageId); } ``` This prevents duplicate emissions while maintaining the existing logic for properly closing messages when tool calls are encountered.
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.

Background: Fix Duplicate AguiEvent.TextMessageEnd Issue
Problem Description
When using AGUI protocol to request a ReActAgent with SKILL and TOOL capabilities, the
AguiAgentAdapterwas emitting duplicateAguiEvent.TextMessageEndevents, causing incorrect event closure in the AGUI event stream.Root Cause
The issue occurs in the
convertEventmethod ofAguiAgentAdapterwhen processingREASONINGevents that contain bothTextBlockandToolUseBlockcontent blocks:First emission path: When processing a
ToolUseBlock,checks if there's an active text message and attempts to end it before starting the tool call (lines 162-169).Second emission path: When processing a
TextBlockin the last event (event.isLast() == true), the code emitsTextMessageEndto close the text message (lines 152-158).The bug: If a message contains both text content and tool usage, and the text block is processed as the last event, the
TextMessageEndis emitted. However, when the subsequentToolUseBlockis processed, the code doesn't check if the message has already been ended, leading to a duplicateTextMessageEndevent.Impact
TextMessageEndevents in the AGUI event streamSolution
Added a guard check using
state.hasEndedMessage(messageId)before emittingTextMessageEndevents. This ensures that:Code Changes
The fix adds a conditional check before emitting
TextMessageEnd:This prevents duplicate emissions while maintaining the existing logic for properly closing messages when tool calls are encountered.