Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/google/adk/cli/agent_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ async def build_cluster(
await build_graph(child, sub_agent, highlight_pairs)
if parent_agent:
draw_edge(parent_agent.name, sub_agent.name)
elif isinstance(agent, Workflow) and agent._graph is not None:
for wf_node in agent._graph.nodes:
elif isinstance(agent, Workflow) and agent.graph is not None:
for wf_node in agent.graph.nodes:
if wf_node.name == START.name:
continue
await build_graph(child, wf_node, highlight_pairs)
for edge in agent._graph.edges:
for edge in agent.graph.edges:
if edge.from_node.name == START.name:
continue
label = str(edge.route) if edge.route is not None else ''
Expand Down
33 changes: 33 additions & 0 deletions tests/unittests/cli/test_agent_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
from google.adk.agents.parallel_agent import ParallelAgent
from google.adk.agents.sequential_agent import SequentialAgent
from google.adk.cli.agent_graph import get_agent_graph
from google.adk.events.event import Event
from google.adk.tools.agent_tool import AgentTool
from google.adk.workflow import DEFAULT_ROUTE
from google.adk.workflow import Workflow
import pytest

_DARK_GREEN = '#0F5223'
Expand Down Expand Up @@ -190,6 +193,36 @@ async def test_build_graph_parallel_agent_fans_out_from_the_parent():
assert 'subgraph "cluster_fanout (Parallel Agent)"' in graph.source


@pytest.mark.asyncio
async def test_build_graph_workflow_draws_nodes_and_edges_from_its_graph():
def check(node_input: str):
return Event(route='retry')

def done(node_input: str):
return node_input

writer = LlmAgent(name='writer', model='gemini-2.0-flash')
workflow = Workflow(
name='flow',
edges=[
('START', writer, check),
(check, {'retry': writer, DEFAULT_ROUTE: done}),
],
)

graph = await get_agent_graph(workflow, [])

nodes, edges = _parse(graph.source)
# START is never drawn, and back-edges (the retry loop) are kept.
assert set(nodes) == {'writer', 'check', 'done'}
assert set(edges) == {
('writer', 'check'),
('check', 'writer'),
('check', 'done'),
}
assert 'subgraph cluster_flow' in graph.source


@pytest.mark.asyncio
async def test_build_graph_highlight_pair_fills_both_nodes_and_colors_edge():
graph = await get_agent_graph(
Expand Down
Loading