@@ -64,11 +64,11 @@ def get_node_name(tool_or_agent: Union[BaseAgent, BaseTool]):
64
64
if isinstance (tool_or_agent , BaseAgent ):
65
65
# Added Workflow Agent checks for different agent types
66
66
if isinstance (tool_or_agent , SequentialAgent ):
67
- return tool_or_agent .name + f ' (Sequential Agent)'
67
+ return tool_or_agent .name + ' (Sequential Agent)'
68
68
elif isinstance (tool_or_agent , LoopAgent ):
69
- return tool_or_agent .name + f ' (Loop Agent)'
69
+ return tool_or_agent .name + ' (Loop Agent)'
70
70
elif isinstance (tool_or_agent , ParallelAgent ):
71
- return tool_or_agent .name + f ' (Parallel Agent)'
71
+ return tool_or_agent .name + ' (Parallel Agent)'
72
72
else :
73
73
return tool_or_agent .name
74
74
elif isinstance (tool_or_agent , BaseTool ):
@@ -144,49 +144,53 @@ def should_build_agent_cluster(tool_or_agent: Union[BaseAgent, BaseTool]):
144
144
)
145
145
return False
146
146
147
- def build_cluster (child : graphviz .Digraph , agent : BaseAgent , name : str ):
148
- if isinstance (agent , LoopAgent ) and parent_agent :
147
+ async def build_cluster (child : graphviz .Digraph , agent : BaseAgent , name : str ):
148
+ if isinstance (agent , LoopAgent ):
149
149
# Draw the edge from the parent agent to the first sub-agent
150
- draw_edge (parent_agent .name , agent .sub_agents [0 ].name )
150
+ if parent_agent :
151
+ draw_edge (parent_agent .name , agent .sub_agents [0 ].name )
151
152
length = len (agent .sub_agents )
152
- currLength = 0
153
+ curr_length = 0
153
154
# Draw the edges between the sub-agents
154
155
for sub_agent_int_sequential in agent .sub_agents :
155
- build_graph (child , sub_agent_int_sequential , highlight_pairs )
156
+ await build_graph (child , sub_agent_int_sequential , highlight_pairs )
156
157
# Draw the edge between the current sub-agent and the next one
157
158
# If it's the last sub-agent, draw an edge to the first one to indicating a loop
158
159
draw_edge (
159
- agent .sub_agents [currLength ].name ,
160
+ agent .sub_agents [curr_length ].name ,
160
161
agent .sub_agents [
161
- 0 if currLength == length - 1 else currLength + 1
162
+ 0 if curr_length == length - 1 else curr_length + 1
162
163
].name ,
163
164
)
164
- currLength += 1
165
- elif isinstance (agent , SequentialAgent ) and parent_agent :
165
+ curr_length += 1
166
+ elif isinstance (agent , SequentialAgent ):
166
167
# Draw the edge from the parent agent to the first sub-agent
167
- draw_edge (parent_agent .name , agent .sub_agents [0 ].name )
168
+ if parent_agent :
169
+ draw_edge (parent_agent .name , agent .sub_agents [0 ].name )
168
170
length = len (agent .sub_agents )
169
- currLength = 0
171
+ curr_length = 0
170
172
171
173
# Draw the edges between the sub-agents
172
174
for sub_agent_int_sequential in agent .sub_agents :
173
- build_graph (child , sub_agent_int_sequential , highlight_pairs )
175
+ await build_graph (child , sub_agent_int_sequential , highlight_pairs )
174
176
# Draw the edge between the current sub-agent and the next one
175
177
# If it's the last sub-agent, don't draw an edge to avoid a loop
176
- draw_edge (
177
- agent .sub_agents [currLength ].name ,
178
- agent .sub_agents [currLength + 1 ].name ,
179
- ) if currLength != length - 1 else None
180
- currLength += 1
178
+ if curr_length != length - 1 :
179
+ draw_edge (
180
+ agent .sub_agents [curr_length ].name ,
181
+ agent .sub_agents [curr_length + 1 ].name ,
182
+ )
183
+ curr_length += 1
181
184
182
- elif isinstance (agent , ParallelAgent ) and parent_agent :
185
+ elif isinstance (agent , ParallelAgent ):
183
186
# Draw the edge from the parent agent to every sub-agent
184
187
for sub_agent in agent .sub_agents :
185
- build_graph (child , sub_agent , highlight_pairs )
186
- draw_edge (parent_agent .name , sub_agent .name )
188
+ await build_graph (child , sub_agent , highlight_pairs )
189
+ if parent_agent :
190
+ draw_edge (parent_agent .name , sub_agent .name )
187
191
else :
188
192
for sub_agent in agent .sub_agents :
189
- build_graph (child , sub_agent , highlight_pairs )
193
+ await build_graph (child , sub_agent , highlight_pairs )
190
194
draw_edge (agent .name , sub_agent .name )
191
195
192
196
child .attr (
@@ -196,21 +200,20 @@ def build_cluster(child: graphviz.Digraph, agent: BaseAgent, name: str):
196
200
fontcolor = light_gray ,
197
201
)
198
202
199
- def draw_node (tool_or_agent : Union [BaseAgent , BaseTool ]):
203
+ async def draw_node (tool_or_agent : Union [BaseAgent , BaseTool ]):
200
204
name = get_node_name (tool_or_agent )
201
205
shape = get_node_shape (tool_or_agent )
202
206
caption = get_node_caption (tool_or_agent )
203
- asCluster = should_build_agent_cluster (tool_or_agent )
204
- child = None
207
+ as_cluster = should_build_agent_cluster (tool_or_agent )
205
208
if highlight_pairs :
206
209
for highlight_tuple in highlight_pairs :
207
210
if name in highlight_tuple :
208
211
# if in highlight, draw highlight node
209
- if asCluster :
212
+ if as_cluster :
210
213
cluster = graphviz .Digraph (
211
214
name = 'cluster_' + name
212
215
) # adding "cluster_" to the name makes the graph render as a cluster subgraph
213
- build_cluster (cluster , agent , name )
216
+ await build_cluster (cluster , agent , name )
214
217
graph .subgraph (cluster )
215
218
else :
216
219
graph .node (
@@ -224,12 +227,12 @@ def draw_node(tool_or_agent: Union[BaseAgent, BaseTool]):
224
227
)
225
228
return
226
229
# if not in highlight, draw non-highlight node
227
- if asCluster :
230
+ if as_cluster :
228
231
229
232
cluster = graphviz .Digraph (
230
233
name = 'cluster_' + name
231
234
) # adding "cluster_" to the name makes the graph render as a cluster subgraph
232
- build_cluster (cluster , agent , name )
235
+ await build_cluster (cluster , agent , name )
233
236
graph .subgraph (cluster )
234
237
235
238
else :
@@ -264,10 +267,9 @@ def draw_edge(from_name, to_name):
264
267
else :
265
268
graph .edge (from_name , to_name , arrowhead = 'none' , color = light_gray )
266
269
267
- draw_node (agent )
270
+ await draw_node (agent )
268
271
for sub_agent in agent .sub_agents :
269
-
270
- build_graph (graph , sub_agent , highlight_pairs , agent )
272
+ await build_graph (graph , sub_agent , highlight_pairs , agent )
271
273
if not should_build_agent_cluster (
272
274
sub_agent
273
275
) and not should_build_agent_cluster (
@@ -276,7 +278,7 @@ def draw_edge(from_name, to_name):
276
278
draw_edge (agent .name , sub_agent .name )
277
279
if isinstance (agent , LlmAgent ):
278
280
for tool in await agent .canonical_tools ():
279
- draw_node (tool )
281
+ await draw_node (tool )
280
282
draw_edge (agent .name , get_node_name (tool ))
281
283
282
284
0 commit comments