-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
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
ilazarev
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status