Skip to content

Commit 351b607

Browse files
committed
Refactor visualization functions to improve formatting and streamline edge generation
1 parent 5ad53d8 commit 351b607

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/agents/extensions/visualization.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def get_all_nodes(agent: Agent, parent: Optional[Agent] = None) -> str:
4545

4646
# Start and end the graph
4747
parts.append(
48-
f'"__start__" [label="__start__", shape=ellipse, style=filled, '
49-
f"fillcolor=lightblue, width=0.5, height=0.3];"
50-
f'"__end__" [label="__end__", shape=ellipse, style=filled, '
51-
f"fillcolor=lightblue, width=0.5, height=0.3];"
48+
'"__start__" [label="__start__", shape=ellipse, style=filled, '
49+
"fillcolor=lightblue, width=0.5, height=0.3];"
50+
'"__end__" [label="__end__", shape=ellipse, style=filled, '
51+
"fillcolor=lightblue, width=0.5, height=0.3];"
5252
)
5353
# Ensure parent agent node is colored
5454
if not parent:
@@ -95,9 +95,7 @@ def get_all_edges(agent: Agent, parent: Optional[Agent] = None) -> str:
9595
parts = []
9696

9797
if not parent:
98-
parts.append(
99-
f'"__start__" -> "{agent.name}";'
100-
)
98+
parts.append(f'"__start__" -> "{agent.name}";')
10199

102100
for tool in agent.tools:
103101
parts.append(f"""
@@ -114,9 +112,7 @@ def get_all_edges(agent: Agent, parent: Optional[Agent] = None) -> str:
114112
parts.append(get_all_edges(handoff, agent))
115113

116114
if not agent.handoffs and not isinstance(agent, Tool):
117-
parts.append(
118-
f'"{agent.name}" -> "__end__";'
119-
)
115+
parts.append(f'"{agent.name}" -> "__end__";')
120116

121117
return "".join(parts)
122118

tests/test_visualization.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def test_get_all_edges(mock_agent):
103103
assert '"Agent1" -> "Handoff1";' in result
104104

105105

106-
107106
def test_draw_graph(mock_agent):
108107
graph = draw_graph(mock_agent)
109108
assert isinstance(graph, graphviz.Source)

0 commit comments

Comments
 (0)