-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Labels
Description
Description
Hi! I think there is an incompatibility between WorkflowAgent (returned by Workflow.as_agent()) and the add_agent_framework_fastapi_endpoint function from agent_framework_ag_ui.
When trying to expose a workflow through the AG-UI endpoint, the application crashes at runtime with a TypeError because the AG-UI code attempts to await an async generator, which is not a valid operation.
This prevents users from exposing multi-agent workflows (created for example with GroupChatBuilder) through FastAPI endpoints using the standard AG-UI integration.
Code Sample
from agent_framework_ag_ui import add_agent_framework_fastapi_endpoint
from agent_framework_orchestrations import GroupChatBuilder
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
from fastapi import FastAPI
# Create agents
def create_openai_client() -> OpenAIChatClient:
return OpenAIChatClient(
base_url="https://example.openai.azure.com/openai/v1/",
api_key="your-api-key",
model_id="gpt-4",
)
triage_agent = Agent(
client=create_openai_client(),
instructions="You are a triage agent",
name="triage_agent",
description="Routes requests",
tools=[],
)
specialist_agent = Agent(
client=create_openai_client(),
instructions="You are a specialist",
name="specialist_agent",
description="Handles specialized requests",
tools=[],
)
# Create workflow
workflow = GroupChatBuilder(
participants=[specialist_agent],
orchestrator_agent=triage_agent
).build()
# Try to expose workflow through AG-UI endpoint
app = FastAPI()
workflow_agent = workflow.as_agent()
add_agent_framework_fastapi_endpoint(app=app, agent=workflow_agent, path="/chat")
# This will crash at runtime when a request is made to the endpointError Messages / Stack Traces
TypeError: object async_generator can't be used in 'await' expression
Traceback (most recent call last):
File "venv\Lib\site-packages\agent_framework_ag_ui\_agent.py", line 116, in run_agent
async for event in run_agent_stream(input_data, self.agent, self.config):
yield event
File "venv\Lib\site-packages\agent_framework_ag_ui\_run.py", line 877, in run_agent_stream
stream = await cast(Awaitable[ResponseStream[Any, Any]], response_stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object async_generator can't be used in 'await' expressionPackage Versions
python-1.0.0b260210
Python Version
Python 3.13.3
Additional Context
Root cause location - Analyze by AI (agent_framework_ag_ui/_run.py:873-877):
response_stream = agent.run(messages, stream=True, **run_kwargs)
if isinstance(response_stream, ResponseStream):
stream = response_stream
else:
stream = await cast(Awaitable[ResponseStream[Any, Any]], response_stream)
# ^ This fails because WorkflowAgent.run(stream=True) returns AsyncIterable, not Awaitable[ResponseStream]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done