Skip to content

[Bug]: AguiMessageConverter duplicates ToolResultBlock when CopilotKit sends tool message + resume #2954

Closed

Description

@resomi

Description

When using CopilotKit v2 useInterrupt.resolve() with AgentScope schema-only HITL tools (e.g. toolkit.registerSchema(...) / TOOL_SUSPENDED → AG-UI interrupt with reason: "tool_call"), the resumed RunAgentInput commonly contains both:

  1. a role: "tool" message with the user payload (toolCallId = call_xxx)
  2. a resume[] entry for the same interrupt / tool call

AguiMessageConverter.toMsgList currently converts both into ToolResultBlock with the same id. ReActAgent then throws:

Duplicate tool result ID: call_xxx

Why this is not fixed on the CopilotKit side alone

CopilotKit #6201 / #6470 only stops synthesizing client tool results for non-tool_call interrupts. AgentScope schema-only / permission-bound interrupts intentionally use reason: "tool_call", so CopilotKit still dual-sends tool message + resume[] by design (keeps chat history well-formed).

The official agentscope-copilotkit example primarily demos permission ASK / frontend useHumanInTheLoop, which do not hit this path. Schema-only requestHumanApproval on the default agent does.

Repro (against agentscope-copilotkit, agent=default)

  1. Run until requestHumanApproval emits RUN_FINISHED with interrupt (reason=tool_call).
  2. Resume with CopilotKit-shaped payload: same toolCallId in messages and resume[].
  3. Observe RUN_ERROR / Duplicate tool result ID.

We reproduced this against local 2.0.3-SNAPSHOT.

Expected

Converter should be idempotent for ordinary tool resumes: if a ToolResultBlock for that id already exists from messages, skip generating another from resume.

Permission-confirm resumes must still produce USER ConfirmResult (they are not ToolResultBlock duplicates).

Proposed fix

In AguiMessageConverter.toMsgList(RunAgentInput, Map):

  • collect existing ToolResultBlock ids from converted messages
  • for non-permission-confirm resumes, skip when id already present
  • prefer the message-history result (CopilotKit already wrote the payload there)

Activity

  1. oss-maintainer commented on Sep 3, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed

    Verified against current main (8a78d6c).

    Root Cause: In AguiMessageConverter.toMsgList(RunAgentInput, Map<String, Interrupt>) (~lines 192–211), both input paths are converted and concatenated without deduplication:

    1. role:"tool" messages produce a ToolResultBlock built from aguiMessage.getToolCallId() (addTextBlock, ~lines 261–278);
    2. each resume[] entry produces a second ToolResultBlock with the same id via toToolResultMsg(resume, toolCallId) (~line 379).

    ReActAgent.validateAndAddToolResults() (~lines 2207–2212) then rejects the duplicated id with IllegalStateException("Duplicate tool result ID: ...").

    Impact: CopilotKit v2 resume flows with schema-only / permission-bound HITL interrupts (reason:"tool_call") fail with RUN_ERROR whenever the payload carries both the tool message and the resume entry — which CopilotKit does by design for this interrupt type.
    Severity: high

    Suggested fix direction: deduplicate in toMsgList — when a resume[] entry covers a toolCallId, skip (or merge) the corresponding role:"tool" message before building the Msg list.

    An automated fix proposal will be generated. Reply /approve to proceed with PR generation.


    Automated evaluation by github-manager-bot

  2. added
    bug
    on Sep 3, 2026
  3. ZYZ666-RGB commented on Sep 3, 2026

    @ZYZ666-RGB
    Contributor

    Hi, I'd like to work on this issue if it is still available.

    I reviewed the confirmed conversion path in AguiMessageConverter.toMsgList(...): input messages are converted first, and each ordinary resume entry is then appended as another ToolResultBlock without checking whether the same tool-call ID already exists in the converted message history.

    I plan to:

    1. Collect existing ToolResultBlock IDs from the converted input messages.
    2. Skip only non-permission-confirm resume entries whose tool-call ID is already present, preserving the message-history result.
    3. Keep permission-confirm resumes on the existing USER ConfirmResult path unchanged.
    4. Add focused regression tests covering the duplicate CopilotKit payload, resume-only input, different tool-call IDs, and permission-confirm resumes.
    5. Run the AG-UI extension test suite and Spotless checks.

    Could you please assign this issue to me before I begin implementation? Thank you!

  4. added a commit that references this issue on Sep 5, 2026
    9073c43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions