@export_module("autogen.agentchat")
def run_group_chat(
pattern: "Pattern",
messages: Union[list[dict[str, Any]], str],
max_rounds: int = 20,
) -> RunResponseProtocol:
iostream = ThreadIOStream()
response = RunResponse(iostream)
def _initiate_group_chat(
pattern: "Pattern" = pattern,
messages: Union[list[dict[str, Any]], str] = messages,
max_rounds: int = max_rounds,
iostream: ThreadIOStream = iostream,
response: RunResponse = response,
) -> None:
with IOStream.set_default(iostream):
try:
chat_result, context_vars, agent = 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]
threading.Thread(
target=_initiate_group_chat,
).start()
return response