MCPcopy Index your code
hub / github.com/google/adk-python / build_cluster

Function build_cluster

src/google/adk/cli/agent_graph.py:152–216  ·  view source on GitHub ↗
(child: graphviz.Digraph, agent: BaseAgent, name: str)

Source from the content-addressed store, hash-verified

150 return False
151
152 async def build_cluster(child: graphviz.Digraph, agent: BaseAgent, name: str):
153 if isinstance(agent, LoopAgent):
154 # Draw the edge from the parent agent to the first sub-agent
155 if parent_agent:
156 draw_edge(parent_agent.name, agent.sub_agents[0].name)
157 length = len(agent.sub_agents)
158 curr_length = 0
159 # Draw the edges between the sub-agents
160 for sub_agent_int_sequential in agent.sub_agents:
161 await build_graph(child, sub_agent_int_sequential, highlight_pairs)
162 # Draw the edge between the current sub-agent and the next one
163 # If it's the last sub-agent, draw an edge to the first one to indicating a loop
164 draw_edge(
165 agent.sub_agents[curr_length].name,
166 agent.sub_agents[
167 0 if curr_length == length - 1 else curr_length + 1
168 ].name,
169 )
170 curr_length += 1
171 elif isinstance(agent, SequentialAgent):
172 # Draw the edge from the parent agent to the first sub-agent
173 if parent_agent:
174 draw_edge(parent_agent.name, agent.sub_agents[0].name)
175 length = len(agent.sub_agents)
176 curr_length = 0
177
178 # Draw the edges between the sub-agents
179 for sub_agent_int_sequential in agent.sub_agents:
180 await build_graph(child, sub_agent_int_sequential, highlight_pairs)
181 # Draw the edge between the current sub-agent and the next one
182 # If it's the last sub-agent, don't draw an edge to avoid a loop
183 if curr_length != length - 1:
184 draw_edge(
185 agent.sub_agents[curr_length].name,
186 agent.sub_agents[curr_length + 1].name,
187 )
188 curr_length += 1
189
190 elif isinstance(agent, ParallelAgent):
191 # Draw the edge from the parent agent to every sub-agent
192 for sub_agent in agent.sub_agents:
193 await build_graph(child, sub_agent, highlight_pairs)
194 if parent_agent:
195 draw_edge(parent_agent.name, sub_agent.name)
196 elif isinstance(agent, Workflow) and agent._graph is not None:
197 for wf_node in agent._graph.nodes:
198 if wf_node.name == START.name:
199 continue
200 await build_graph(child, wf_node, highlight_pairs)
201 for edge in agent._graph.edges:
202 if edge.from_node.name == START.name:
203 continue
204 label = str(edge.route) if edge.route is not None else ''
205 draw_edge(edge.from_node.name, edge.to_node.name)
206 else:
207 for sub_agent in agent.sub_agents:
208 await build_graph(child, sub_agent, highlight_pairs)
209 draw_edge(agent.name, sub_agent.name)

Callers 1

draw_nodeFunction · 0.85

Calls 2

draw_edgeFunction · 0.85
build_graphFunction · 0.85

Tested by

no test coverage detected