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
importasyncioimportjsonfromautogen_agentchat.agentsimportAssistantAgentfromautogen_agentchat.teamsimportRoundRobinGroupChatfromautogen_agentchat.conditionsimportTextMentionTerminationfromautogen_agentchat.uiimportConsolefromautogen_ext.models.openaiimportOpenAIChatCompletionClientdefcreate_team() ->RoundRobinGroupChat:
model_client=OpenAIChatCompletionClient(model="gpt-4o", seed=42, temperature=0)
writer=AssistantAgent(
name="writer",
description="A writer.",
system_message="You are a writer.",
model_client=model_client,
)
critic=AssistantAgent(
name="critic",
description="A critic.",
system_message="You are a critic, provide feedback on the writing. Reply only 'APPROVE' if the task is done.",
model_client=model_client,
)
# The termination condition is a text termination, which will cause the chat to terminate when the text "APPROVE" is received.termination=TextMentionTermination("APPROVE")
# The group chat will alternate between the writer and the critic.group_chat=RoundRobinGroupChat([writer, critic], termination_condition=termination)
returngroup_chatasyncdefmain() ->None:
# Create team.group_chat=create_team()
# `run_stream` returns an async generator to stream the intermediate messages.stream=group_chat.run_stream(task="Write a short story about a robot that discovers it has feelings.")
# `Console` is a simple UI to display the stream.awaitConsole(stream)
# Save the state of the group chat and all participants.state=awaitgroup_chat.save_state()
withopen("group_chat_state.json", "w") asf:
json.dump(state, f)
# Create a new team with the same participants configuration.group_chat=create_team()
# Load the state of the group chat and all participants.withopen("group_chat_state.json", "r") asf:
state=json.load(f)
awaitgroup_chat.load_state(state)
# Resume the chat.stream=group_chat.run_stream(task="Translate the story into Chinese.")
awaitConsole(stream)
asyncio.run(main())
Get warning when saving state.
/Users/ekzhu/autogen/python/.venv/lib/python3.11/site-packages/pydantic/main.py:390: UserWarning: Pydantic serializer warnings:
PydanticSerializationUnexpectedValue: Expected `ToolCallRequestEvent` but got `TextMessage` with value `TextMessage(source='user'...s.', type='TextMessage')` - serialized value may not be as expected
PydanticSerializationUnexpectedValue: Expected `ToolCallExecutionEvent` but got `TextMessage` with value `TextMessage(source='user'...s.', type='TextMessage')` - serialized value may not be as expected
PydanticSerializationUnexpectedValue: Expected `ToolCallRequestEvent` but got `TextMessage` with value `TextMessage(source='write...d.', type='TextMessage')` - serialized value may not be as expected
PydanticSerializationUnexpectedValue: Expected `ToolCallExecutionEvent` but got `TextMessage` with value `TextMessage(source='write...d.', type='TextMessage')` - serialized value may not be as expected
PydanticSerializationUnexpectedValue: Expected `ToolCallRequestEvent` but got `TextMessage` with value `TextMessage(source='criti...VE', type='TextMessage')` - serialized value may not be as expected
PydanticSerializationUnexpectedValue: Expected `ToolCallExecutionEvent` but got `TextMessage` with value `TextMessage(source='criti...VE', type='TextMessage')` - serialized value may not be as expected
return self.__pydantic_serializer__.to_python(
Cause: union type AgentEvent | ChatMessage in the group chat's message thread causes Pydantic to raise warning.
Suggest fix: create an_AgentMessage = Annotated[AgentEvent | ChatMessage, Field(discriminator="type")] private type in _states.py, use where the union is needed.
The text was updated successfully, but these errors were encountered:
Run this:
Get warning when saving state.
Cause: union type
AgentEvent | ChatMessage
in the group chat's message thread causes Pydantic to raise warning.Suggest fix: create an
_AgentMessage = Annotated[AgentEvent | ChatMessage, Field(discriminator="type")]
private type in_states.py
, use where the union is needed.The text was updated successfully, but these errors were encountered: