Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ def __init__(
runtime: AgentRuntime | None = None,
custom_message_types: List[type[BaseAgentEvent | BaseChatMessage]] | None = None,
) -> None:
self._input_participants = participants
self._input_termination_condition = termination_condition

stop_agent = _StopAgent()
stop_agent_termination = StopMessageTermination()
termination_condition = (
Expand Down Expand Up @@ -700,8 +703,10 @@ def _factory() -> GraphFlowManager:

def _to_config(self) -> GraphFlowConfig:
"""Converts the instance into a configuration object."""
participants = [participant.dump_component() for participant in self._participants]
termination_condition = self._termination_condition.dump_component() if self._termination_condition else None
participants = [participant.dump_component() for participant in self._input_participants]
termination_condition = (
self._input_termination_condition.dump_component() if self._input_termination_condition else None
)
return GraphFlowConfig(
participants=participants,
termination_condition=termination_condition,
Expand Down
50 changes: 49 additions & 1 deletion python/packages/autogen-agentchat/tests/test_group_chat_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from autogen_agentchat.base import Response, TaskResult
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.messages import BaseChatMessage, ChatMessage, MessageFactory, TextMessage
from autogen_agentchat.messages import BaseChatMessage, ChatMessage, MessageFactory, StopMessage, TextMessage
from autogen_agentchat.messages import BaseTextChatMessage as TextChatMessage
from autogen_agentchat.teams import (
DiGraphBuilder,
Expand Down Expand Up @@ -1399,3 +1399,51 @@ async def test_graph_builder_with_filter_agent(runtime: AgentRuntime | None) ->
result = await team.run(task="Hello")
assert any(m.source == "X" and m.content == "Hello" for m in result.messages) # type: ignore[union-attr]
assert result.stop_reason is not None


@pytest.mark.asyncio
async def test_graph_flow_serialize_deserialize() -> None:
client_a = ReplayChatCompletionClient(list(map(str, range(10))))
client_b = ReplayChatCompletionClient(list(map(str, range(10))))
a = AssistantAgent("A", model_client=client_a)
b = AssistantAgent("B", model_client=client_b)

builder = DiGraphBuilder()
builder.add_node(a).add_node(b)
builder.add_edge(a, b)
builder.set_entry_point(a)

team = GraphFlow(
participants=builder.get_participants(),
graph=builder.build(),
runtime=None,
termination_condition=MaxMessageTermination(5),
)

serialized = team.dump_component()
deserialized_team = GraphFlow.load_component(serialized)
serialized_deserialized = deserialized_team.dump_component()

results = await team.run(task="Start")
de_results = await deserialized_team.run(task="Start")

assert serialized == serialized_deserialized
assert results == de_results
assert results.stop_reason is not None
assert results.stop_reason == de_results.stop_reason
assert results.messages == de_results.messages
assert isinstance(results.messages[0], TextMessage)
assert results.messages[0].source == "user"
assert results.messages[0].content == "Start"
assert isinstance(results.messages[1], TextMessage)
assert results.messages[1].source == "A"
assert results.messages[1].content == "0"
assert isinstance(results.messages[2], TextMessage)
assert results.messages[2].source == "A"
assert results.messages[2].content == "1"
assert isinstance(results.messages[3], TextMessage)
assert results.messages[3].source == "B"
assert results.messages[3].content == "0"
assert isinstance(results.messages[-1], StopMessage)
assert results.messages[-1].source == _DIGRAPH_STOP_AGENT_NAME
assert results.messages[-1].content == "Digraph execution is complete"
Loading