Skip to content

Python: [AG-UI] Error occurs when using with_plan_review in Magentic workflow #3331

@TsukasaIshimura

Description

@TsukasaIshimura

I am building a web app using Microsoft Agent Framework AG-UI and CopilotKit.
I want to run the Magentic workflow with AG-UI. When I specify with_plan_review, an error occurs the first time the user enters input. When I do not specify with_plan_review, no error occurs.

Could you please look into this? Thank you.

Source code

python_agent = ChatAgent(
    name="PythonAgent",
    chat_client=chat_client,
    description="Specialist in Python programming.",
    instructions="Your role is to code in Python.",
)

javascript_agent = ChatAgent(
    name="JavascriptAgent",
    chat_client=chat_client,
    description="Specialist in Javascript programming.",
    instructions="Your role is to code in Javascript.",
)

manager_agent = ChatAgent(
    name="MagenticManager",
    instructions="You coordinate a team to complete complex tasks efficiently.",
    chat_client=chat_client,
)

workflow = (
    MagenticBuilder()
    .participants([python_agent, javascript_agent])
    .with_standard_manager(
        agent=manager_agent,
        max_round_count=3,
        max_stall_count=3,
        max_reset_count=2,
    )
    .with_plan_review() # Using this causes an error.
    .build()
)


add_agent_framework_fastapi_endpoint(
    app=app,
    agent=AgentFrameworkAgent(
        agent=workflow.as_agent(),
        name="MyAgent",
        description="Helpful AI Agent",
    ),
    path="/api/v1/agents/my-agent",
)

Error log

INFO:agent_framework_ag_ui._events:Processing AgentRunUpdate with 2 content items
INFO:agent_framework_ag_ui._events:  Content 0: type=FunctionCallContent
DEBUG:agent_framework_ag_ui._events:Tool call: request_info (call_id: 2bc658c2-f66f-405f-9122-8f474b6ba895)
INFO:agent_framework_ag_ui._events:Emitting ToolCallStartEvent with name='request_info', id='2bc658c2-f66f-405f-9122-8f474b6ba895'
ERROR:    Exception in ASGI application
  + Exception Group Traceback (most recent call last):
  |   File "/usr/local/lib/python3.13/site-packages/starlette/_utils.py", line 79, in collapse_excgroups
  |     yield
  |   File "/usr/local/lib/python3.13/site-packages/starlette/responses.py", line 270, in __call__
  |     async with anyio.create_task_group() as task_group:
  |                ~~~~~~~~~~~~~~~~~~~~~~~^^
  |   File "/usr/local/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 783, in __aexit__
  |     raise BaseExceptionGroup(
  |         "unhandled errors in a TaskGroup", self._exceptions
  |     ) from None
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/usr/local/lib/python3.13/site-packages/uvicorn/protocols/http/h11_impl.py", line 410, in run_asgi
    |     result = await app(  # type: ignore[func-returns-value]
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |         self.scope, self.receive, self.send
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |     )
    |     ^
    |   File "/usr/local/lib/python3.13/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    |     return await self.app(scope, receive, send)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/usr/local/lib/python3.13/site-packages/fastapi/applications.py", line 1135, in __call__
    |     await super().__call__(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/applications.py", line 107, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/middleware/errors.py", line 186, in __call__
    |     raise exc
    |   File "/usr/local/lib/python3.13/site-packages/starlette/middleware/errors.py", line 164, in __call__
    |     await self.app(scope, receive, _send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/middleware/cors.py", line 85, in __call__
    |     await self.app(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/middleware/exceptions.py", line 63, in __call__
    |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    |     raise exc
    |   File "/usr/local/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "/usr/local/lib/python3.13/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    |     await self.app(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/routing.py", line 716, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/routing.py", line 736, in app
    |     await route.handle(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/routing.py", line 290, in handle
    |     await self.app(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/fastapi/routing.py", line 115, in app
    |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    |     raise exc
    |   File "/usr/local/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "/usr/local/lib/python3.13/site-packages/fastapi/routing.py", line 102, in app
    |     await response(scope, receive, send)
    |   File "/usr/local/lib/python3.13/site-packages/starlette/responses.py", line 269, in __call__
    |     with collapse_excgroups():
    |          ~~~~~~~~~~~~~~~~~~^^
    |   File "/usr/local/lib/python3.13/contextlib.py", line 162, in __exit__
    |     self.gen.throw(value)
    |     ~~~~~~~~~~~~~~^^^^^^^
    |   File "/usr/local/lib/python3.13/site-packages/starlette/_utils.py", line 85, in collapse_excgroups
    |     raise exc
    |   File "/usr/local/lib/python3.13/site-packages/starlette/responses.py", line 273, in wrap
    |     await func()
    |   File "/usr/local/lib/python3.13/site-packages/starlette/responses.py", line 253, in stream_response
    |     async for chunk in self.body_iterator:
    |     ...<2 lines>...
    |         await send({"type": "http.response.body", "body": chunk, "more_body": True})
    |   File "/usr/local/lib/python3.13/site-packages/agent_framework_ag_ui/_endpoint.py", line 83, in event_generator
    |     async for event in wrapped_agent.run_agent(input_data):
    |     ...<14 lines>...
    |         yield encoded
    |   File "/usr/local/lib/python3.13/site-packages/agent_framework_ag_ui/_agent.py", line 182, in run_agent
    |     async for event in orchestrator.run(context):
    |         yield event
    |   File "/usr/local/lib/python3.13/site-packages/agent_framework_ag_ui/_orchestrators.py", line 676, in run
    |     events = await event_bridge.from_agent_run_update(update)
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/usr/local/lib/python3.13/site-packages/agent_framework_ag_ui/_events.py", line 102, in from_agent_run_update
    |     events.extend(self._handle_function_call_content(content))
    |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
    |   File "/usr/local/lib/python3.13/site-packages/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 "/usr/local/lib/python3.13/json/__init__.py", line 235, in dumps
    |     return _default_encoder.encode(obj)
    |            ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
    |   File "/usr/local/lib/python3.13/json/encoder.py", line 202, in encode
    |     chunks = self.iterencode(o, _one_shot=True)
    |   File "/usr/local/lib/python3.13/json/encoder.py", line 263, in iterencode
    |     return _iterencode(o, 0)
    |   File "/usr/local/lib/python3.13/json/encoder.py", line 182, in default
    |     raise TypeError(f'Object of type {o.__class__.__name__} '
    |                     f'is not JSON serializable')
    | TypeError: Object of type MagenticPlanReviewRequest is not JSON serializable
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/uvicorn/protocols/http/h11_impl.py", line 410, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self.scope, self.receive, self.send
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/fastapi/applications.py", line 1135, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/starlette/applications.py", line 107, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/usr/local/lib/python3.13/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.13/site-packages/starlette/middleware/cors.py", line 85, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/starlette/middleware/exceptions.py", line 63, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.13/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/starlette/routing.py", line 716, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/starlette/routing.py", line 736, in app
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/starlette/routing.py", line 290, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/fastapi/routing.py", line 115, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.13/site-packages/fastapi/routing.py", line 102, in app
    await response(scope, receive, send)
  File "/usr/local/lib/python3.13/site-packages/starlette/responses.py", line 269, in __call__
    with collapse_excgroups():
         ~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/contextlib.py", line 162, in __exit__
    self.gen.throw(value)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/starlette/_utils.py", line 85, in collapse_excgroups
    raise exc
  File "/usr/local/lib/python3.13/site-packages/starlette/responses.py", line 273, in wrap
    await func()
  File "/usr/local/lib/python3.13/site-packages/starlette/responses.py", line 253, in stream_response
    async for chunk in self.body_iterator:
    ...<2 lines>...
        await send({"type": "http.response.body", "body": chunk, "more_body": True})
  File "/usr/local/lib/python3.13/site-packages/agent_framework_ag_ui/_endpoint.py", line 83, in event_generator
    async for event in wrapped_agent.run_agent(input_data):
    ...<14 lines>...
        yield encoded
  File "/usr/local/lib/python3.13/site-packages/agent_framework_ag_ui/_agent.py", line 182, in run_agent
    async for event in orchestrator.run(context):
        yield event
  File "/usr/local/lib/python3.13/site-packages/agent_framework_ag_ui/_orchestrators.py", line 676, in run
    events = await event_bridge.from_agent_run_update(update)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/agent_framework_ag_ui/_events.py", line 102, in from_agent_run_update
    events.extend(self._handle_function_call_content(content))
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/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 "/usr/local/lib/python3.13/json/__init__.py", line 235, in dumps
    return _default_encoder.encode(obj)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/usr/local/lib/python3.13/json/encoder.py", line 202, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python3.13/json/encoder.py", line 263, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/lib/python3.13/json/encoder.py", line 182, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
                    f'is not JSON serializable')
TypeError: Object of type MagenticPlanReviewRequest is not JSON serializable

Version information
Python 3.13.10
agent-framework-ag-ui==1.0.0b260116
agent-framework-core==1.0.0b260116

Thank you in advance.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions