@export_module("autogen.agentchat")
async def a_run_group_chat(
pattern: "Pattern",
messages: Union[list[dict[str, Any]], str],
max_rounds: int = 20,
) -> AsyncRunResponseProtocol:
iostream = AsyncThreadIOStream()
response = AsyncRunResponse(iostream)
async def _initiate_group_chat(
pattern: "Pattern" = pattern,
messages: Union[list[dict[str, Any]], str] = messages,
max_rounds: int = max_rounds,
iostream: AsyncThreadIOStream = iostream,
response: AsyncRunResponse = response,
) -> None:
with IOStream.set_default(iostream):
try:
chat_result, context_vars, agent = await a_initiate_group_chat(
pattern=pattern,
messages=messages,
max_rounds=max_rounds,
)
IOStream.get_default().send(
RunCompletionEvent( # type: ignore[call-arg]
history=chat_result.chat_history,
summary=chat_result.summary,
cost=chat_result.cost,
last_speaker=agent.name,
context_variables=context_vars,
)
)
except Exception as e:
response.iostream.send(ErrorEvent(error=e)) # type: ignore[call-arg]
asyncio.create_task(_initiate_group_chat())
return response