Skip to content

Commit 0079bca

Browse files
committed
style: improve code formatting and readability in visualization functions
1 parent 39ff00d commit 0079bca

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

src/agents/extensions/visualization.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def get_main_graph(agent: Agent) -> str:
1919
graph [splines=true];
2020
node [fontname="Arial"];
2121
edge [penwidth=1.5];
22-
2322
"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];
2423
"__end__" [shape=ellipse, style=filled, fillcolor=lightblue];
2524
"""
@@ -41,21 +40,23 @@ def get_all_nodes(agent: Agent, parent: Agent = None) -> str:
4140
str: The DOT format string representing the nodes.
4241
"""
4342
parts = []
44-
4543
# Ensure parent agent node is colored
4644
if not parent:
4745
parts.append(f"""
48-
"{agent.name}" [label="{agent.name}", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];""")
46+
"{agent.name}" [label="{agent.name}", shape=box, style=filled,
47+
fillcolor=lightyellow, width=1.5, height=0.8];""")
4948

5049
# Smaller tools (ellipse, green)
5150
for tool in agent.tools:
5251
parts.append(f"""
53-
"{tool.name}" [label="{tool.name}", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];""")
52+
"{tool.name}" [label="{tool.name}", shape=ellipse, style=filled,
53+
fillcolor=lightgreen, width=0.5, height=0.3];""")
5454

5555
# Bigger handoffs (rounded box, yellow)
5656
for handoff in agent.handoffs:
5757
parts.append(f"""
58-
"{handoff.name}" [label="{handoff.name}", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];""")
58+
"{handoff.name}" [label="{handoff.name}", shape=box, style=filled,
59+
style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];""")
5960
parts.append(get_all_nodes(handoff))
6061

6162
return "".join(parts)

tests/test_visualization.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import pytest
55

66
from agents import Agent
7-
from agents.extensions.visualization import draw_graph, get_all_edges, get_all_nodes, get_main_graph
7+
from agents.extensions.visualization import (
8+
draw_graph,
9+
get_all_edges,
10+
get_all_nodes,
11+
get_main_graph,
12+
)
813

914

1015
@pytest.fixture
@@ -36,40 +41,40 @@ def test_get_main_graph(mock_agent):
3641
assert '"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];' in result
3742
assert '"__end__" [shape=ellipse, style=filled, fillcolor=lightblue];' in result
3843
assert (
39-
'"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];'
40-
in result
44+
'"Agent1" [label="Agent1", shape=box, style=filled, '
45+
"fillcolor=lightyellow, width=1.5, height=0.8];" in result
4146
)
4247
assert (
43-
'"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
44-
in result
48+
'"Tool1" [label="Tool1", shape=ellipse, style=filled, '
49+
"fillcolor=lightgreen, width=0.5, height=0.3];" in result
4550
)
4651
assert (
47-
'"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
48-
in result
52+
'"Tool2" [label="Tool2", shape=ellipse, style=filled, '
53+
"fillcolor=lightgreen, width=0.5, height=0.3];" in result
4954
)
5055
assert (
51-
'"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];'
52-
in result
56+
'"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, '
57+
"fillcolor=lightyellow, width=1.5, height=0.8];" in result
5358
)
5459

5560

5661
def test_get_all_nodes(mock_agent):
5762
result = get_all_nodes(mock_agent)
5863
assert (
59-
'"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];'
60-
in result
64+
'"Agent1" [label="Agent1", shape=box, style=filled, '
65+
"fillcolor=lightyellow, width=1.5, height=0.8];" in result
6166
)
6267
assert (
63-
'"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
64-
in result
68+
'"Tool1" [label="Tool1", shape=ellipse, style=filled, '
69+
"fillcolor=lightgreen, width=0.5, height=0.3];" in result
6570
)
6671
assert (
67-
'"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
68-
in result
72+
'"Tool2" [label="Tool2", shape=ellipse, style=filled, '
73+
"fillcolor=lightgreen, width=0.5, height=0.3];" in result
6974
)
7075
assert (
71-
'"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];'
72-
in result
76+
'"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, '
77+
"fillcolor=lightyellow, width=1.5, height=0.8];" in result
7378
)
7479

7580

@@ -94,18 +99,18 @@ def test_draw_graph(mock_agent):
9499
assert '"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];' in graph.source
95100
assert '"__end__" [shape=ellipse, style=filled, fillcolor=lightblue];' in graph.source
96101
assert (
97-
'"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];'
98-
in graph.source
102+
'"Agent1" [label="Agent1", shape=box, style=filled, '
103+
"fillcolor=lightyellow, width=1.5, height=0.8];" in graph.source
99104
)
100105
assert (
101-
'"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
102-
in graph.source
106+
'"Tool1" [label="Tool1", shape=ellipse, style=filled, '
107+
"fillcolor=lightgreen, width=0.5, height=0.3];" in graph.source
103108
)
104109
assert (
105-
'"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
106-
in graph.source
110+
'"Tool2" [label="Tool2", shape=ellipse, style=filled, '
111+
"fillcolor=lightgreen, width=0.5, height=0.3];" in graph.source
107112
)
108113
assert (
109-
'"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];'
110-
in graph.source
114+
'"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, '
115+
"fillcolor=lightyellow, width=1.5, height=0.8];" in graph.source
111116
)

0 commit comments

Comments
 (0)