Skip to content

Python: [Bug]: agent-framework-ag-ui crashes when Handoff user-input requests emit non‑JSON‑serializable arguments #3239

Closed

Description

@petetakacs

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:

  1. Install Agent Framework Python packages (versions below).
  2. Create a Handoff workflow with two agents using HandoffBuilder and expose it through AG-UI FastAPI endpoint.
  3. Trigger a conversation where a specialist agent replies without calling a handoff tool (so it requests user input).
  4. 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/chat

Error 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:

Activity

  1. added theissue type on Jan 15, 2026
  2. added
    bugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)
    on Jan 15, 2026
  3. added and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Jan 16, 2026
  4. ilazarev commented on Jan 22, 2026

    @ilazarev

    Hi Evan Mattson (@moonbox3) ,
    if i run code sample provided by petetakacs
    i still get serialization errors.

    agent-framework/python/packages/ag-ui/agent_framework_ag_ui/_endpoint.py", line 92, in event_generator
        |     encoded = encoder.encode(event)
    ....
    |     return self.__pydantic_serializer__.to_json(
        |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        |         self,
        |         ^^^^^
        |     ...<13 lines>...
        |         serialize_as_any=serialize_as_any,
        |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |     ).decode()
        |     ^
        | pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'agent_framework._types.AgentResponse'>
    
  5. moonbox3 commented on Jan 22, 2026

    @moonbox3
    Contributor

    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.

  6. moonbox3 commented on Jan 23, 2026

    @moonbox3
    Contributor

    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.

  7. ilazarev commented on Jan 23, 2026

    @ilazarev

    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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)pythonUsage: [Issues, PRs], Target: Python

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions