Repository navigation
Labels
bugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)Usage: [Issues], Target: all issues (Legacy, prefer issue type: bug)pythonUsage: [Issues, PRs], Target: PythonUsage: [Issues, PRs], Target: Python
Description
Description
When using Agent Framework AG-UI with a Handoff workflow, the server crashes with a JSON serialization error the first time a handoff agent requests user input. This happens because AG-UI’s event bridge attempts to json.dumps a HandoffAgentUserRequest dataclass emitted by HandoffAgentExecutor.
Expected:
- AG-UI should serialize the request_info arguments and emit ToolCallArgsEvent without throwing.
Actual:
- Exception: TypeError: Object of type HandoffAgentUserRequest is not JSON serializable
- The AG-UI stream ends with an unhandled exception.
Steps to reproduce:
- Install Agent Framework Python packages (versions below).
- Create a Handoff workflow with two agents using HandoffBuilder and expose it through AG-UI FastAPI endpoint.
- Trigger a conversation where a specialist agent replies without calling a handoff tool (so it requests user input).
- Observe server crash on ToolCallArgsEvent emission.
Code Sample
import asyncio
from fastapi import FastAPI
from agent_framework import HandoffBuilder
from agent_framework.azure import AzureOpenAIChatClient
from agent_framework.ag_ui import add_agent_framework_fastapi_endpoint
from azure.identity import AzureCliCredential
app = FastAPI()
async def build_agent():
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
triage = chat_client.create_agent(
name="triage",
instructions="You are a triage agent. Handoff to specialist when needed."
)
specialist = chat_client.create_agent(
name="specialist",
instructions=(
"You are a specialist. Respond normally and ask the user for more details."
)
)
workflow = (
HandoffBuilder(
name="handoff_demo",
participants=[triage, specialist],
)
.with_start_agent(triage)
.add_handoff(triage, [specialist])
.build()
)
return workflow.as_agent()
@app.on_event("startup")
async def startup():
agent = await build_agent()
add_agent_framework_fastapi_endpoint(
app=app,
agent=agent,
path="/chat",
dependencies=[],
)
# Run with: uvicorn main:app --reload
# Client request:
curl -N -s \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{"messages":[{"role":"user","content":"Help me with my issue"}],"state":{}}' \
http://localhost:8000/chatError Messages / Stack Traces
TypeError: Object of type HandoffAgentUserRequest is not JSON serializable
File ".../agent_framework_ag_ui/_events.py", line 181, in _handle_function_call_content
delta_str = content.arguments if isinstance(content.arguments, str) else json.dumps(content.arguments)
File ".../json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)Package Versions
agent-framework: 1.0.0b260114, agent-framework-core: 1.0.0b260114, agent-framework-ag-ui: 1.0.0b260114
Python Version
Python 3.12
Additional Context
AG-UI uses raw json.dumps in _handle_function_call_content
- Handoff emits HandoffAgentUserRequest dataclass for RequestInfoEvent data
- There is already a make_json_safe helper that supports dataclasses in agent_framework_ag_ui/_utils.py
Suggested fix:
- Replace json.dumps(content.arguments) with json.dumps(make_json_safe(content.arguments))
or serialize via prepare_function_call_results with default=str
Relevant files:
- https://github.com/microsoft/agent-framework/blob/main/python/packages/ag-ui/agent_framework_ag_ui/_events.py
- https://github.com/microsoft/agent-framework/blob/main/python/packages/ag-ui/agent_framework_ag_ui/_utils.py
- https://github.com/microsoft/agent-framework/blob/main/python/packages/core/agent_framework/_workflows/_handoff.py
Reacted by Ivan Lazarev (Audi)
Metadata
Metadata
Assignees
Labels
bugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)Usage: [Issues], Target: all issues (Legacy, prefer issue type: bug)pythonUsage: [Issues, PRs], Target: PythonUsage: [Issues, PRs], Target: Python
Type
Projects
- StatusShow more project fieldsDone
Activity
ilazarev commentedon Jan 22, 2026
Hi Evan Mattson (@moonbox3) ,
if i run code sample provided by petetakacs
i still get serialization errors.
moonbox3 commentedon Jan 22, 2026
Ivan Lazarev (Audi) (@ilazarev) are you running from our main branch or a package? We haven't released a package yet that contains this bug fix.
moonbox3 commentedon Jan 23, 2026
With that said, the JSON serialize/deserialize issue are fixed in main; however, AG‑UI in MAF does not currently treat
request_info(from a workflow) as a first‑class UI event. In handoff‑as‑agent flows, the framework emits request_info as tool call events (plus confirm_changes approval), so the stream can be “tool‑only” and render nothing in the default AG‑UI client. You can still render these yourself by handling the tool call events and displaying the payloads.ilazarev commentedon Jan 23, 2026
thank you for the hints, Evan Mattson (@moonbox3). I still have to fill out some white spots on MAF & AG-UI...
i ran it from main, it was my intent to try the fresh fix :)
i was wondering if i can get some out-of-the-box frontend to work with handoff workflow ;) (devui is not working either with handoff)