Skip to content

Commit 29e9983

Browse files
committed
Linting
1 parent 2993d26 commit 29e9983

File tree

2 files changed

+81
-36
lines changed

2 files changed

+81
-36
lines changed

src/agents/visualizations.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ def get_main_graph(agent: Agent) -> str:
1313
Returns:
1414
str: The DOT format string representing the graph.
1515
"""
16-
parts = ["""
16+
parts = [
17+
"""
1718
digraph G {
1819
graph [splines=true];
1920
node [fontname="Arial"];
2021
edge [penwidth=1.5];
2122
2223
"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];
2324
"__end__" [shape=ellipse, style=filled, fillcolor=lightblue];
24-
"""]
25+
"""
26+
]
2527
parts.append(get_all_nodes(agent))
2628
parts.append(get_all_edges(agent))
2729
parts.append("}")
@@ -39,23 +41,23 @@ def get_all_nodes(agent: Agent, parent: Agent = None) -> str:
3941
str: The DOT format string representing the nodes.
4042
"""
4143
parts = []
42-
44+
4345
# Ensure parent agent node is colored
4446
if not parent:
4547
parts.append(f"""
4648
"{agent.name}" [label="{agent.name}", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];""")
47-
49+
4850
# Smaller tools (ellipse, green)
4951
for tool in agent.tools:
5052
parts.append(f"""
5153
"{tool.name}" [label="{tool.name}", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];""")
52-
54+
5355
# Bigger handoffs (rounded box, yellow)
5456
for handoff in agent.handoffs:
5557
parts.append(f"""
5658
"{handoff.name}" [label="{handoff.name}", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];""")
5759
parts.append(get_all_nodes(handoff))
58-
60+
5961
return "".join(parts)
6062

6163

@@ -71,25 +73,25 @@ def get_all_edges(agent: Agent, parent: Agent = None) -> str:
7173
str: The DOT format string representing the edges.
7274
"""
7375
parts = []
74-
76+
7577
if not parent:
7678
parts.append(f"""
7779
"__start__" -> "{agent.name}";""")
78-
80+
7981
for tool in agent.tools:
8082
parts.append(f"""
8183
"{agent.name}" -> "{tool.name}" [style=dotted, penwidth=1.5];
8284
"{tool.name}" -> "{agent.name}" [style=dotted, penwidth=1.5];""")
83-
85+
8486
if not agent.handoffs:
8587
parts.append(f"""
8688
"{agent.name}" -> "__end__";""")
87-
89+
8890
for handoff in agent.handoffs:
8991
parts.append(f"""
9092
"{agent.name}" -> "{handoff.name}";""")
9193
parts.append(get_all_edges(handoff, agent))
92-
94+
9395
return "".join(parts)
9496

9597

@@ -106,8 +108,8 @@ def draw_graph(agent: Agent, filename: str = None) -> graphviz.Source:
106108
"""
107109
dot_code = get_main_graph(agent)
108110
graph = graphviz.Source(dot_code)
109-
111+
110112
if filename:
111-
graph.render(filename, format='png')
112-
113-
return graph
113+
graph.render(filename, format="png")
114+
115+
return graph

tests/test_visualizations.py

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import pytest
21
from unittest.mock import Mock
3-
from src.agents.visualizations import get_main_graph, get_all_nodes, get_all_edges, draw_graph
4-
from src.agents.agent import Agent
2+
53
import graphviz
4+
import pytest
5+
6+
from src.agents.agent import Agent
7+
from src.agents.visualizations import draw_graph, get_all_edges, get_all_nodes, get_main_graph
8+
69

710
@pytest.fixture
811
def mock_agent():
912
tool1 = Mock()
1013
tool1.name = "Tool1"
1114
tool2 = Mock()
1215
tool2.name = "Tool2"
13-
16+
1417
handoff1 = Mock()
1518
handoff1.name = "Handoff1"
1619
handoff1.tools = []
@@ -20,28 +23,55 @@ def mock_agent():
2023
agent.name = "Agent1"
2124
agent.tools = [tool1, tool2]
2225
agent.handoffs = [handoff1]
23-
26+
2427
return agent
2528

29+
2630
def test_get_main_graph(mock_agent):
2731
result = get_main_graph(mock_agent)
2832
assert "digraph G" in result
29-
assert 'graph [splines=true];' in result
33+
assert "graph [splines=true];" in result
3034
assert 'node [fontname="Arial"];' in result
31-
assert 'edge [penwidth=1.5];' in result
35+
assert "edge [penwidth=1.5];" in result
3236
assert '"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];' in result
3337
assert '"__end__" [shape=ellipse, style=filled, fillcolor=lightblue];' in result
34-
assert '"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];' in result
35-
assert '"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in result
36-
assert '"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in result
37-
assert '"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];' in result
38+
assert (
39+
'"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];'
40+
in result
41+
)
42+
assert (
43+
'"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
44+
in result
45+
)
46+
assert (
47+
'"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
48+
in result
49+
)
50+
assert (
51+
'"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];'
52+
in result
53+
)
54+
3855

3956
def test_get_all_nodes(mock_agent):
4057
result = get_all_nodes(mock_agent)
41-
assert '"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];' in result
42-
assert '"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in result
43-
assert '"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in result
44-
assert '"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];' in result
58+
assert (
59+
'"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];'
60+
in result
61+
)
62+
assert (
63+
'"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
64+
in result
65+
)
66+
assert (
67+
'"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
68+
in result
69+
)
70+
assert (
71+
'"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];'
72+
in result
73+
)
74+
4575

4676
def test_get_all_edges(mock_agent):
4777
result = get_all_edges(mock_agent)
@@ -53,16 +83,29 @@ def test_get_all_edges(mock_agent):
5383
assert '"Agent1" -> "Handoff1";' in result
5484
assert '"Handoff1" -> "__end__";' in result
5585

86+
5687
def test_draw_graph(mock_agent):
5788
graph = draw_graph(mock_agent)
5889
assert isinstance(graph, graphviz.Source)
5990
assert "digraph G" in graph.source
60-
assert 'graph [splines=true];' in graph.source
91+
assert "graph [splines=true];" in graph.source
6192
assert 'node [fontname="Arial"];' in graph.source
62-
assert 'edge [penwidth=1.5];' in graph.source
93+
assert "edge [penwidth=1.5];" in graph.source
6394
assert '"__start__" [shape=ellipse, style=filled, fillcolor=lightblue];' in graph.source
6495
assert '"__end__" [shape=ellipse, style=filled, fillcolor=lightblue];' in graph.source
65-
assert '"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];' in graph.source
66-
assert '"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in graph.source
67-
assert '"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];' in graph.source
68-
assert '"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];' in graph.source
96+
assert (
97+
'"Agent1" [label="Agent1", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];'
98+
in graph.source
99+
)
100+
assert (
101+
'"Tool1" [label="Tool1", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
102+
in graph.source
103+
)
104+
assert (
105+
'"Tool2" [label="Tool2", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];'
106+
in graph.source
107+
)
108+
assert (
109+
'"Handoff1" [label="Handoff1", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];'
110+
in graph.source
111+
)

0 commit comments

Comments
 (0)