#AG-UI bug: ToolCallStartEvent emitted multiple times

6 messages · Page 1 of 1 (latest)

compact kraken
#

AG-UI: I'm fairly certain I've found a bug in the AgentFrameworkEventBridge, but I have limited time to grok the entire setup, write a failing test, then a fix.

I'm developing an agent using CopilotKit in the frontend, and noticed that the CopilotKit consistently fails with:

Agent execution failed: Error: Cannot send 'TOOL_CALL_START' event: A tool call with ID 'call_kJ1AwU3ES6oTmODaKsreNKfM' is already in progress. Complete it with 'TOOL_CALL_END' first.

I enabled debug logging in agent_framework_ag_ui and noticed that my backend always emit a ToolCallStartEvent when it's emitting a ToolCallArgsEvent:

❯ grep 'Emitting ToolCall' debug.log
2026-01-09 14:33:14 - agent_framework_ag_ui._events - INFO - Emitting ToolCallStartEvent with name='query_space_01f0d113ac6b1e0db27651b323107a2a', id='call_kJ1AwU3ES6oTmODaKsreNKfM'
2026-01-09 14:33:14 - agent_framework_ag_ui._events - INFO - Emitting ToolCallArgsEvent with delta_length=2, id='call_kJ1AwU3ES6oTmODaKsreNKfM'
2026-01-09 14:33:14 - agent_framework_ag_ui._events - INFO - Emitting ToolCallStartEvent with name='query_space_01f0d113ac6b1e0db27651b323107a2a', id='call_kJ1AwU3ES6oTmODaKsreNKfM'
2026-01-09 14:33:14 - agent_framework_ag_ui._events - INFO - Emitting ToolCallArgsEvent with delta_length=5, id='call_kJ1AwU3ES6oTmODaKsreNKfM'
…

The protocol expects only one tool start event per call, which is why the frontend craps out.

Seems like the _handle_function_call_content doesn't correctly identify/distinguish start events vs args events. It will indeed always emit start events as long as the function call content has a name:

https://github.com/microsoft/agent-framework/blob/d28ad2d7df58481a6d1b7a24b3e4a8175c236e00/python/packages/ag-ui/agent_framework_ag_ui/_events.py#L166-L176

GitHub

A framework for building, orchestrating and deploying AI agents and multi-agent workflows with support for Python and .NET. - microsoft/agent-framework

#

For the record, I'm using the AzureOpenAIResponsesClient with gpt-5.2. The agent is configured with a single tool, MCPStreamableHTTPTool that connects to an Azure Databricks Genie space.

woeful willow
#

Hi @compact kraken

So from your details it looks like a bug could do a quick sanity check:

  1. Add a debug print of 'self.toolcallinprogress'
  2. Run a single tool call
  3. Watch it flip to True after the first delta
  4. Confirm that subsequent deltas still contain name but should not trigger a start event

This takes <5 minutes and will validate the diagnosis.

This will validate the issue:

From your initial diagnosis it looks like handlefunctioncallcontent incorrectly treats every delta with a name as a new tool call start

  • GPT‑5.2 emits repeated name fields
  • AG‑UI therefore emits multiple ToolCallStartEvents
  • CopilotKit rejects the invalid protocol sequence

A fix for could be a state‑tracking fix in AG‑UI would resolve it cleanly.

From this output you should be able to raise a issue or PR on the repo.

#

@compact kraken some more thoughts

CopilotKit’s frontend is strict about the event protocol.
AG‑UI’s backend is loose about interpreting function‑call deltas.
GPT‑5.2 emits repeated name fields.

This could be a root cause combination exposes the bug.

Potential fix

The bridge needs to track active tool calls:

if content.name and not self.toolcallinprogress:
    emit ToolCallStartEvent
    mark toolcallin_progress = True
else:
    emit ToolCallArgsEvent

And then reset the flag on ToolCallEndEvent.

This is exactly how other frameworks (LangChain, LlamaIndex, OpenAI’s JS client) handle streaming function calls.

compact kraken
#

Where do you want me to do these things? I can't find toolcallinprogress anywhere in the codebase, nor any relevant in_progress

compact kraken
#

I believe this PR fixed the problem: https://github.com/microsoft/agent-framework/pull/3148 (haven't verified yet, because now I get ERROR: ASGI callable returned without completing response in uvicorn for some reason, without any traceback logged/exception raised, only change I've done is upgrade the library from 1.0.0b260107 to 1.0.0b260114)

GitHub

Motivation and Context
The Responses API expects tool calls to start with fc_*. AG-UI is passing tool call IDs that need this prefix. We also need to make sure we&#39;re only emitting ToolCallS...