1
+ from typing import Optional
2
+
1
3
import graphviz
2
4
3
5
from agents import Agent
@@ -20,8 +22,6 @@ def get_main_graph(agent: Agent) -> str:
20
22
graph [splines=true];
21
23
node [fontname="Arial"];
22
24
edge [penwidth=1.5];
23
- "__start__" [shape=ellipse, style=filled, fillcolor=lightblue];
24
- "__end__" [shape=ellipse, style=filled, fillcolor=lightblue];
25
25
"""
26
26
]
27
27
parts .append (get_all_nodes (agent ))
@@ -30,8 +30,6 @@ def get_main_graph(agent: Agent) -> str:
30
30
return "" .join (parts )
31
31
32
32
33
- from typing import Optional
34
-
35
33
def get_all_nodes (agent : Agent , parent : Optional [Agent ] = None ) -> str :
36
34
"""
37
35
Recursively generates the nodes for the given agent and its handoffs in DOT format.
@@ -59,12 +57,14 @@ def get_all_nodes(agent: Agent, parent: Optional[Agent] = None) -> str:
59
57
for handoff in agent .handoffs :
60
58
if isinstance (handoff , Handoff ):
61
59
parts .append (
62
- f'"{ handoff .agent_name } " [label="{ handoff .agent_name } ", shape=box, style=filled, style=rounded, '
60
+ f'"{ handoff .agent_name } " [label="{ handoff .agent_name } ", shape=box, '
61
+ f"shape=box, style=filled, style=rounded, "
63
62
f"fillcolor=lightyellow, width=1.5, height=0.8];"
64
63
)
65
64
if isinstance (handoff , Agent ):
66
65
parts .append (
67
- f'"{ handoff .name } " [label="{ handoff .name } ", shape=box, style=filled, style=rounded, '
66
+ f'"{ handoff .name } " [label="{ handoff .name } ", '
67
+ f"shape=box, style=filled, style=rounded, "
68
68
f"fillcolor=lightyellow, width=1.5, height=0.8];"
69
69
)
70
70
parts .append (get_all_nodes (handoff ))
@@ -85,19 +85,11 @@ def get_all_edges(agent: Agent, parent: Optional[Agent] = None) -> str:
85
85
"""
86
86
parts = []
87
87
88
- if not parent :
89
- parts .append (f"""
90
- "__start__" -> "{ agent .name } ";""" )
91
-
92
88
for tool in agent .tools :
93
89
parts .append (f"""
94
90
"{ agent .name } " -> "{ tool .name } " [style=dotted, penwidth=1.5];
95
91
"{ tool .name } " -> "{ agent .name } " [style=dotted, penwidth=1.5];""" )
96
92
97
- if not agent .handoffs :
98
- parts .append (f"""
99
- "{ agent .name } " -> "__end__";""" )
100
-
101
93
for handoff in agent .handoffs :
102
94
if isinstance (handoff , Handoff ):
103
95
parts .append (f"""
@@ -110,8 +102,6 @@ def get_all_edges(agent: Agent, parent: Optional[Agent] = None) -> str:
110
102
return "" .join (parts )
111
103
112
104
113
- from typing import Optional
114
-
115
105
def draw_graph (agent : Agent , filename : Optional [str ] = None ) -> graphviz .Source :
116
106
"""
117
107
Draws the graph for the given agent and optionally saves it as a PNG file.
0 commit comments