mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-16 04:02:55 -06:00
chore: Fix formatting
PiperOrigin-RevId: 766407362
This commit is contained in:
parent
174afb3975
commit
eb2b9ef88f
@ -19,7 +19,10 @@ from typing import Union
|
|||||||
|
|
||||||
import graphviz
|
import graphviz
|
||||||
|
|
||||||
from ..agents import BaseAgent, SequentialAgent, LoopAgent, ParallelAgent
|
from ..agents import BaseAgent
|
||||||
|
from ..agents import LoopAgent
|
||||||
|
from ..agents import ParallelAgent
|
||||||
|
from ..agents import SequentialAgent
|
||||||
from ..agents.llm_agent import LlmAgent
|
from ..agents.llm_agent import LlmAgent
|
||||||
from ..tools.agent_tool import AgentTool
|
from ..tools.agent_tool import AgentTool
|
||||||
from ..tools.base_tool import BaseTool
|
from ..tools.base_tool import BaseTool
|
||||||
@ -35,7 +38,12 @@ else:
|
|||||||
retrieval_tool_module_loaded = True
|
retrieval_tool_module_loaded = True
|
||||||
|
|
||||||
|
|
||||||
async def build_graph(graph: graphviz.Digraph, agent: BaseAgent, highlight_pairs, parent_agent=None):
|
async def build_graph(
|
||||||
|
graph: graphviz.Digraph,
|
||||||
|
agent: BaseAgent,
|
||||||
|
highlight_pairs,
|
||||||
|
parent_agent=None,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Build a graph of the agent and its sub-agents.
|
Build a graph of the agent and its sub-agents.
|
||||||
Args:
|
Args:
|
||||||
@ -56,11 +64,11 @@ async def build_graph(graph: graphviz.Digraph, agent: BaseAgent, highlight_pairs
|
|||||||
if isinstance(tool_or_agent, BaseAgent):
|
if isinstance(tool_or_agent, BaseAgent):
|
||||||
# Added Workflow Agent checks for different agent types
|
# Added Workflow Agent checks for different agent types
|
||||||
if isinstance(tool_or_agent, SequentialAgent):
|
if isinstance(tool_or_agent, SequentialAgent):
|
||||||
return tool_or_agent.name + f" (Sequential Agent)"
|
return tool_or_agent.name + f' (Sequential Agent)'
|
||||||
elif isinstance(tool_or_agent, LoopAgent):
|
elif isinstance(tool_or_agent, LoopAgent):
|
||||||
return tool_or_agent.name + f" (Loop Agent)"
|
return tool_or_agent.name + f' (Loop Agent)'
|
||||||
elif isinstance(tool_or_agent, ParallelAgent):
|
elif isinstance(tool_or_agent, ParallelAgent):
|
||||||
return tool_or_agent.name + f" (Parallel Agent)"
|
return tool_or_agent.name + f' (Parallel Agent)'
|
||||||
else:
|
else:
|
||||||
return tool_or_agent.name
|
return tool_or_agent.name
|
||||||
elif isinstance(tool_or_agent, BaseTool):
|
elif isinstance(tool_or_agent, BaseTool):
|
||||||
@ -147,7 +155,12 @@ async def build_graph(graph: graphviz.Digraph, agent: BaseAgent, highlight_pairs
|
|||||||
build_graph(child, sub_agent_int_sequential, highlight_pairs)
|
build_graph(child, sub_agent_int_sequential, highlight_pairs)
|
||||||
# Draw the edge between the current sub-agent and the next one
|
# Draw the edge between the current sub-agent and the next one
|
||||||
# If it's the last sub-agent, draw an edge to the first one to indicating a loop
|
# If it's the last sub-agent, draw an edge to the first one to indicating a loop
|
||||||
draw_edge(agent.sub_agents[currLength].name, agent.sub_agents[0 if currLength == length - 1 else currLength+1 ].name)
|
draw_edge(
|
||||||
|
agent.sub_agents[currLength].name,
|
||||||
|
agent.sub_agents[
|
||||||
|
0 if currLength == length - 1 else currLength + 1
|
||||||
|
].name,
|
||||||
|
)
|
||||||
currLength += 1
|
currLength += 1
|
||||||
elif isinstance(agent, SequentialAgent):
|
elif isinstance(agent, SequentialAgent):
|
||||||
# Draw the edge from the parent agent to the first sub-agent
|
# Draw the edge from the parent agent to the first sub-agent
|
||||||
@ -160,7 +173,10 @@ async def build_graph(graph: graphviz.Digraph, agent: BaseAgent, highlight_pairs
|
|||||||
build_graph(child, sub_agent_int_sequential, highlight_pairs)
|
build_graph(child, sub_agent_int_sequential, highlight_pairs)
|
||||||
# Draw the edge between the current sub-agent and the next one
|
# Draw the edge between the current sub-agent and the next one
|
||||||
# If it's the last sub-agent, don't draw an edge to avoid a loop
|
# If it's the last sub-agent, don't draw an edge to avoid a loop
|
||||||
draw_edge(agent.sub_agents[currLength].name, agent.sub_agents[currLength+1].name) if currLength != length - 1 else None
|
draw_edge(
|
||||||
|
agent.sub_agents[currLength].name,
|
||||||
|
agent.sub_agents[currLength + 1].name,
|
||||||
|
) if currLength != length - 1 else None
|
||||||
currLength += 1
|
currLength += 1
|
||||||
|
|
||||||
elif isinstance(agent, ParallelAgent):
|
elif isinstance(agent, ParallelAgent):
|
||||||
@ -191,7 +207,9 @@ async def build_graph(graph: graphviz.Digraph, agent: BaseAgent, highlight_pairs
|
|||||||
if name in highlight_tuple:
|
if name in highlight_tuple:
|
||||||
# if in highlight, draw highlight node
|
# if in highlight, draw highlight node
|
||||||
if asCluster:
|
if asCluster:
|
||||||
cluster = graphviz.Digraph(name='cluster_' + name) # adding "cluster_" to the name makes the graph render as a cluster subgraph
|
cluster = graphviz.Digraph(
|
||||||
|
name='cluster_' + name
|
||||||
|
) # adding "cluster_" to the name makes the graph render as a cluster subgraph
|
||||||
build_cluster(cluster, agent, name)
|
build_cluster(cluster, agent, name)
|
||||||
graph.subgraph(cluster)
|
graph.subgraph(cluster)
|
||||||
else:
|
else:
|
||||||
@ -208,7 +226,9 @@ async def build_graph(graph: graphviz.Digraph, agent: BaseAgent, highlight_pairs
|
|||||||
# if not in highlight, draw non-highlight node
|
# if not in highlight, draw non-highlight node
|
||||||
if asCluster:
|
if asCluster:
|
||||||
|
|
||||||
cluster = graphviz.Digraph(name='cluster_' + name) # adding "cluster_" to the name makes the graph render as a cluster subgraph
|
cluster = graphviz.Digraph(
|
||||||
|
name='cluster_' + name
|
||||||
|
) # adding "cluster_" to the name makes the graph render as a cluster subgraph
|
||||||
build_cluster(cluster, agent, name)
|
build_cluster(cluster, agent, name)
|
||||||
graph.subgraph(cluster)
|
graph.subgraph(cluster)
|
||||||
|
|
||||||
@ -234,9 +254,13 @@ async def build_graph(graph: graphviz.Digraph, agent: BaseAgent, highlight_pairs
|
|||||||
graph.edge(from_name, to_name, color=light_green, dir='back')
|
graph.edge(from_name, to_name, color=light_green, dir='back')
|
||||||
return
|
return
|
||||||
# if no need to highlight, color gray
|
# if no need to highlight, color gray
|
||||||
if (should_build_agent_cluster(agent)):
|
if should_build_agent_cluster(agent):
|
||||||
|
|
||||||
graph.edge(from_name, to_name, color=light_gray, )
|
graph.edge(
|
||||||
|
from_name,
|
||||||
|
to_name,
|
||||||
|
color=light_gray,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
graph.edge(from_name, to_name, arrowhead='none', color=light_gray)
|
graph.edge(from_name, to_name, arrowhead='none', color=light_gray)
|
||||||
|
|
||||||
@ -244,7 +268,11 @@ async def build_graph(graph: graphviz.Digraph, agent: BaseAgent, highlight_pairs
|
|||||||
for sub_agent in agent.sub_agents:
|
for sub_agent in agent.sub_agents:
|
||||||
|
|
||||||
build_graph(graph, sub_agent, highlight_pairs, agent)
|
build_graph(graph, sub_agent, highlight_pairs, agent)
|
||||||
if (not should_build_agent_cluster(sub_agent) and not should_build_agent_cluster(agent)): # This is to avoid making a node for a Workflow Agent
|
if not should_build_agent_cluster(
|
||||||
|
sub_agent
|
||||||
|
) and not should_build_agent_cluster(
|
||||||
|
agent
|
||||||
|
): # This is to avoid making a node for a Workflow Agent
|
||||||
draw_edge(agent.name, sub_agent.name)
|
draw_edge(agent.name, sub_agent.name)
|
||||||
if isinstance(agent, LlmAgent):
|
if isinstance(agent, LlmAgent):
|
||||||
for tool in await agent.canonical_tools():
|
for tool in await agent.canonical_tools():
|
||||||
|
Loading…
Reference in New Issue
Block a user