Repository navigation
Replies: 1 comment
|
For example, this controller function forwards events to your UI callback and returns the agent to resume: from autogen_agentchat.base import TaskResult
from autogen_agentchat.messages import HandoffMessage
async def run_ui_turn(team, task, emit_event):
result = None
async for event in team.run_stream(task=task):
if isinstance(event, TaskResult):
result = event
else:
await emit_event(event)
if result is None:
raise RuntimeError("The stream ended without a TaskResult")
last = result.messages[-1] if result.messages else None
if isinstance(last, HandoffMessage) and last.target == "user":
return last.source
return NoneHere On the first UI submission, pass the task string. When the function returns a pending agent name, store it in that conversation's server-side session. On the next user submission, resume with: reply = HandoffMessage(
source="user",
target=pending_agent_name,
content=user_text,
)
# Within your async UI handler:
next_pending_agent = await run_ui_turn(team, reply, emit_event)Keep a separate team/state per conversation, and serialize calls to the same team. Do not recreate/reset the team between these two submissions. If your web framework recreates it on reruns, save its state after the completed turn and load it into an equivalently configured team before resuming. Close the model client when disposing the session, rather than after every message. You do not need a blocking References: stream contract and terminal |
Uh oh!
There was an error while loading. Please reload this page.
Does anyone know how to utilize swarm in autogen0.4 to facilitate a multi-round conversation? The official demonstration on the website only employs Console for implementation. How can I accomplish a multi-round setup using gradio or streamlit as the user interface without relying on Console, especially under the condition of need user input messages?
async def run_team_stream() -> None:
task_result = await Console(team.run_stream(task=task))
last_message = task_result.messages[-1]
asyncio.run(run_team_stream())
All reactions