You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: AG-UI TOOL_CALL_RESULT reuses replyId as messageId, causing duplicate tool-message IDs when multiple tools are called in one reply #2907
When an agent issues multiple tool calls within a single assistant reply, the
AG-UI adapter emits one TOOL_CALL_RESULT event per tool result, but all of
them share the same messageId (the reply's replyId).
The frontend (@ag-ui/client) creates one role:"tool" message per TOOL_CALL_RESULT keyed by messageId, so multiple tool results end up with
the same message id. CopilotKit's CopilotChatMessageView deduplicates by message.id before rendering and keeps only the last one — so any earlier tool
result that has a frontend renderer is silently dropped.
Environment
agentscope-java: 2.0.3-SNAPSHOT (also present in 2.0.2)
frontend: CopilotKit React v2 / @ag-ui/client
Observed event stream
For a single assistant reply that called two tools (memory_save + show_note_panel), the SSE stream contains two TOOL_CALL_RESULT events with
the same messageId but different toolCallId:
toolCallId is unique per tool call, but replyId is shared across all tool
calls in a single reply. With one tool call per reply this is harmless; with
2+ tool calls in the same reply the ids collide.
Reproduce
Run an agent that calls two tools within one reply.
Inspect the SSE stream: two TOOL_CALL_RESULT events with the same messageId but different toolCallId.
CopilotKit dev console logs: CopilotChatMessageView: Merged 1 message(s) with duplicate IDs.
Expected behavior
Each TOOL_CALL_RESULT should carry a unique messageId so every tool result
renders independently.
I confirmed on current main that AguiStreamContext.endToolResult() uses the shared replyId as ToolCallResult.messageId, while the existing parallel-tool coverage does not assert result message IDs.
I plan to keep the PR focused on the v2 AguiStreamContext path: emit a deterministic per-tool result message ID and add regression coverage proving that two tool results from the same reply have distinct message IDs. I will leave the legacy adapter path unchanged unless maintainers prefer parity in this PR.
This PR can solve the messageId duplication issue mentioned above, but I think we should fix the replyId at its source instead. Since AGUI is only at the application layer, if the core remains unchanged, other protocols might have problems.
Thanks, that's a fair concern. I checked the core flow before choosing the adapter-level fix.
replyId is generated once per acting batch and is intentionally shared by all tool-result events in that batch; the code also describes it as an event-correlation identifier. Each AgentEvent already has its own unique id, while toolCallId identifies the individual tool call.
AG-UI materializes every tool result as a separate ToolMessage, whose message id is distinct from its toolCallId. The collision happens when the adapter uses the batch-level replyId directly as that message ID. This PR derives the ID from both values, so it preserves reply correlation while remaining unique per tool result.
I also checked the current non-AG-UI consumers I could find. They correlate tool results using toolCallId and/or the event ID or sequence, so I haven't found evidence of the same collision outside AG-UI.
For that reason, I'd prefer to keep this PR scoped to the adapter. A canonical core-level message ID or helper could still be a useful follow-up, but changing replyId to be unique per tool would change its current semantics.
Were you suggesting adding a separate message identifier in core, rather than changing the meaning of replyId itself?
Activity
steven-ji commentedon Aug 30, 2026
Hi, I'd like to work on this.
I confirmed on current
mainthatAguiStreamContext.endToolResult()uses the sharedreplyIdasToolCallResult.messageId, while the existing parallel-tool coverage does not assert result message IDs.I plan to keep the PR focused on the v2
AguiStreamContextpath: emit a deterministic per-tool result message ID and add regression coverage proving that two tool results from the same reply have distinct message IDs. I will leave the legacy adapter path unchanged unless maintainers prefer parity in this PR.dragondyt commentedon Aug 30, 2026
This PR can solve the messageId duplication issue mentioned above, but I think we should fix the replyId at its source instead. Since AGUI is only at the application layer, if the core remains unchanged, other protocols might have problems.
steven-ji commentedon Aug 30, 2026
Thanks, that's a fair concern. I checked the core flow before choosing the adapter-level fix.
replyIdis generated once per acting batch and is intentionally shared by all tool-result events in that batch; the code also describes it as an event-correlation identifier. EachAgentEventalready has its own uniqueid, whiletoolCallIdidentifies the individual tool call.AG-UI materializes every tool result as a separate
ToolMessage, whose messageidis distinct from itstoolCallId. The collision happens when the adapter uses the batch-levelreplyIddirectly as that message ID. This PR derives the ID from both values, so it preserves reply correlation while remaining unique per tool result.I also checked the current non-AG-UI consumers I could find. They correlate tool results using
toolCallIdand/or the event ID or sequence, so I haven't found evidence of the same collision outside AG-UI.For that reason, I'd prefer to keep this PR scoped to the adapter. A canonical core-level message ID or helper could still be a useful follow-up, but changing
replyIdto be unique per tool would change its current semantics.Were you suggesting adding a separate message identifier in core, rather than changing the meaning of
replyIditself?fix(agui): assign per-tool result message ids (#2908)