You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to figure out how to interact with a multi-agent workflow that is served with AG-UI. My server code is shown below which is based on the example in the Agent Framework docs.
# server.pyfromtextwrapimportdedentimportuvicornfromagent_frameworkimportAgent, Message, Workflowfromagent_framework_ag_uiimportadd_agent_framework_fastapi_endpointfromagent_framework_ag_uiimportAgentFrameworkWorkflowfromagent_framework.openaiimportOpenAIChatClientfromagent_framework.orchestrationsimportHandoffBuilderfromdotenvimportload_dotenvfromfastapiimportFastAPIdefcreate_agents() ->tuple:
"""Create agents for the workflow."""chat_client=OpenAIChatClient(model="gpt-5.5")
triage_agent=Agent(
client=chat_client,
name="triage_agent",
instructions=dedent("""\ You are the triage agent. Decide whether the user needs one of these specialist agents: - math_agent: arithmetic, calculations, equations, or math explanations. - writing_agent: rewrite, summarize, edit, or improve text. - code_agent: Python, programming, debugging, or software development questions. Hand off to the best agent. Do not answer the task yourself. """),
require_per_service_call_history_persistence=True,
)
math_agent=Agent(
client=chat_client,
name="math_agent",
instructions=(
"You solve math and calculation problems. Return the answer clearly. ""Do not hand off unless the user asks for a different kind of help."
),
require_per_service_call_history_persistence=True,
)
writing_agent=Agent(
client=chat_client,
name="writing_agent",
instructions=(
"You rewrite, summarize, edit, and improve text. Return the improved text clearly. ""Do not hand off unless the user asks for a different kind of help."
),
require_per_service_call_history_persistence=True,
)
code_agent=Agent(
client=chat_client,
name="code_agent",
instructions=(
"You answer Python, programming, debugging, and software development questions. ""Do not hand off unless the user asks for a different kind of help."
),
require_per_service_call_history_persistence=True,
)
returntriage_agent, math_agent, writing_agent, code_agentdeftermination_condition(conversation: list[Message]) ->bool:
formsginreversed(conversation):
ifmsg.role=="assistant"and (msg.textor"").strip().lower().endswith(
"case complete."
):
returnTruereturnFalsedefcreate_workflow() ->Workflow:
"""Create a handoff workflow."""triage_agent, math_agent, writing_agent, code_agent=create_agents()
builder=HandoffBuilder(
name="handoff",
participants=[triage_agent, math_agent, writing_agent, code_agent],
termination_condition=termination_condition,
)
builder.add_handoff(triage_agent, [math_agent, writing_agent, code_agent])
builder.with_start_agent(triage_agent)
returnbuilder.build()
defmain():
"""Run the server."""load_dotenv()
workflow=AgentFrameworkWorkflow(
workflow_factory=lambda_thread_id: create_workflow(),
name="workflow",
description="Example of a handoff workflow.",
)
app=FastAPI(title="AG-UI Workflow Server")
add_agent_framework_fastapi_endpoint(app, workflow)
uvicorn.run(app)
if__name__=="__main__":
main()
My client code is shown next. It connects to the AG-UI server which I'm running locally on port 8000. This client code works fine when I serve a single agent and I can send several user messages in the same session without problems. But I'm having issues when the server is for a workflow.
# client.pyimportasynciofromagent_frameworkimportAgentfromagent_framework_ag_uiimportAGUIChatClientasyncdefmain():
"""Run the client."""server_url="http://127.0.0.1:8000/"chat_client=AGUIChatClient(endpoint=server_url)
agent=Agent(
name="Client Agent",
client=chat_client,
instructions="you are a helpful assistant",
)
thread=agent.create_session()
try:
whileTrue:
# Get user inputmessage=input("\nUser (:q or quit to exit): ")
ifnotmessage.strip():
print("Request cannot be empty.")
continueifmessage.lower() in (":q", "quit"):
break# Stream the agent responseprint("\nAssistant: ", end="", flush=True)
asyncforupdateinagent.run(message, session=thread, stream=True):
# Print text content as it streamsifupdate.text:
print(f"\033[96m{update.text}\033[0m", end="", flush=True)
print("\n")
exceptKeyboardInterrupt:
print("\n\nExiting...")
exceptExceptionase:
print(f"\n\033[91mAn error occurred: {e}\033[0m")
if__name__=="__main__":
asyncio.run(main())
This works for the initial user message (prompt) but subsequent messages fail on the server. The error given below is from the server after the second message is sent.
agent_framework.exceptions.ChatClientException:
("<class 'agent_framework_openai._chat_client.OpenAIChatClient'> service failed to complete the prompt:
Error code: 400 - {'error': {'message': 'No tool output found for function call 0c9a1ef3-ba95-4ae6-9d11-7fbab624bdd9.',
'type': 'invalid_request_error', 'param': 'input', 'code': None}}",
BadRequestError("Error code: 400 - {'error': {'message': 'No tool output found for function call 0c9a1ef3-ba95-4ae6-9d11-7fbab624bdd9.', 'type': 'invalid_request_error', 'param': 'input', 'code': None}}"))
I can't find much information in the Agent Framework docs regarding the client side code for multi-agent workflows. How am I supposed to interact with an AG-UI workflow server? Does the client code need to use an ID or something else to connect with the workflow? This was fairly straightforward with a single agent but seems to be more involved with workflows.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to figure out how to interact with a multi-agent workflow that is served with AG-UI. My server code is shown below which is based on the example in the Agent Framework docs.
My client code is shown next. It connects to the AG-UI server which I'm running locally on port 8000. This client code works fine when I serve a single agent and I can send several user messages in the same session without problems. But I'm having issues when the server is for a workflow.
This works for the initial user message (prompt) but subsequent messages fail on the server. The error given below is from the server after the second message is sent.
I can't find much information in the Agent Framework docs regarding the client side code for multi-agent workflows. How am I supposed to interact with an AG-UI workflow server? Does the client code need to use an ID or something else to connect with the workflow? This was fairly straightforward with a single agent but seems to be more involved with workflows.
All reactions