> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# The Workflow Graph

> Explains ADK v2 workflow graphs that compose LLM agents and functions into directed node graphs for reliable, modular multi-step task execution like order tracking.

So now you have a chat agent that can call tools, look things up, and give answers. Real work rarely happens in a single step: a customer asks "Where is my order?" and the system must (1) identify the order number, (2) look up the order, and (3) draft a reply. Packing all of that into one giant instruction often fails — the agent may skip the lookup or invent a status.

![A diagram titled "One Giant Instruction" showing a customer message ("Where is my order A1234?") sent to a chat agent. The agent skips the lookup instruction and returns a response with the order status missing.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/ADKs-Workflow-Runtime/The-Workflow-Graph/one-giant-instruction-missing-order-status.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=4bcaa289393effa6df9bfef0cd6586e1)

The solution follows standard software-engineering practice: split the work into focused, composable pieces and make the control flow explicit. ADK v2 provides a runtime that executes exactly that structure: a graph of nodes connected by directed edges.

![A dark-themed slide titled "Split the Work Into a Graph" showing a "Workflow runtime" icon above a three-step flow diagram (question mark → database → chat/message icon). The KodeKloud logo appears in the bottom-left corner.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/ADKs-Workflow-Runtime/The-Workflow-Graph/split-work-graph-workflow-diagram.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=2155fc6f5e35543298948a0a0e717712)

What is an ADK v2 workflow?

* A workflow is a directed graph: nodes perform units of work; edges are one-way connections that say "after this node finishes, run that node."
* Anything that does work can be a node: an LLM-backed agent, a plain Python function, etc. The runtime treats them uniformly — it follows edges, executes the node, and passes the node's output along the edge.

Two node types cover most use cases:

| Node type | What it does | Input / Output |
| - | - | - |
| Agent node | LLM-backed agent that can declare both input and output schemas | `input_schema` and `output_schema` may be simple types (e.g., `str`) or Pydantic models. See [Pydantic](https://docs.pydantic.dev/latest/). |
| Function node | A regular Python function that accepts a single parameter (commonly `node_input`) and returns an `Event` with the result | No special base class required — the runtime treats it as a node when an edge points to it. |

![A diagram titled "Two Kinds of Node" showing an "Agent node" in the center with arrows from a left "Input schema" box (the data it expects to receive) to a right "Output schema" box (what it hands to the next node).](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/ADKs-Workflow-Runtime/The-Workflow-Graph/agent-node-input-output-schema-diagram.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=19d03ad67ed4a7a9e71baea59068da3b)

![A diagram titled "The Function Node" showing an input box labeled "node\_input" feeding into a central "Function node." The function node (captioned "A normal Python function") outputs to an "Event" box labeled "output" and "result."](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/ADKs-Workflow-Runtime/The-Workflow-Graph/function-node-python-input-output-event.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=29074ec5c7a53c105b12f0f64c86c796)

A typical order-tracking pipeline is a simple linear graph:

START → classify\_request → lookup\_order → draft\_reply

* `START` is the runtime entry point. From `START` you wire the sequence of nodes to run.
* Each node hands its result to the next node via the edge; the runtime transports values along edges.

Every run begins at `START`. Failing to include an explicit `START` edge or clear input/output schemas can produce unpredictable behavior at runtime.

Below is a concise conceptual example showing how these pieces fit together: an agent that extracts an order number, a Pydantic model for the order, a function node that looks up the order, and a final agent that drafts the reply.

```python theme={null}
# Example ADK workflow (conceptual)
from pydantic import BaseModel

# ADK runtime primitives (import names may vary by SDK)
from adk import LlmAgent, Workflow, Event, START

# A simple agent that extracts an order number as text.
classify_request = LlmAgent(
    name="classify_request",
    instruction="Return the order number found in the user's message.",
    output_schema=str,
)

# Pydantic model representing the order lookup result.
class OrderInfo(BaseModel):
    order_id: str
    status: str

# A simple in-memory orders table for the example.
ORDERS = {
    "A1234": "Out for delivery",
    "B9876": "Processing",
}

# A function node: receives the order_id string and returns an Event.
def lookup_order(node_input: str):
    # node_input is expected to be the order id (e.g., "A1234")
    info = OrderInfo(order_id=node_input, status=ORDERS.get(node_input, "Unknown"))
    return Event(output=info)
```

`classify_request` produces a string such as `"A1234"`. That string becomes the `node_input` for `lookup_order`, which returns an `OrderInfo` object with `order_id` and `status`. Because `draft_reply` declares `OrderInfo` as its input schema, its instruction can reference those fields directly when drafting the response.

```python theme={null}
# An agent that receives OrderInfo and drafts a customer-facing reply.
draft_reply = LlmAgent(
    name="draft_reply",
    input_schema=OrderInfo,
    instruction="Order {order_info.order_id} is {order_info.status}. Tell the customer.",
)

# The root agent is now a Workflow (the runtime still looks for this variable name).
root_agent = Workflow(
    name="order_status",
    edges=[(START, classify_request, lookup_order, draft_reply)],
)
```

Now watch the data move through the graph: `classify_request` → `"A1234"`, `lookup_order` → `OrderInfo(order_id="A1234", status="Out for delivery")`, and `draft_reply` → a final message like "Your order A1234 is currently Out for delivery."

![A dark-themed flowchart titled "Watch the Data Move" showing a customer message "Where is my order A1234?" flowing through steps Start → classify\_request → lookup\_order → draft\_reply. A side "OrderInfo" box shows order\_id A1234 with status "Out for delivery," and a drafted reply telling the customer the order is out for delivery.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/ADKs-Workflow-Runtime/The-Workflow-Graph/watch-data-move-order-a1234-flowchart.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=2e1cc9b1f4c6f7d97be5a61d57840149)

Useful workflow patterns

* Sequential flows: ADK provides a convenience template, `SequentialAgent`, to run sub-agents in order (A → B → C). It's equivalent to wiring `(START → A → B → C)`.
* Branching and routing: Because edges define control flow, you can branch, route, join, or loop. Nodes may decide which outgoing edge to follow at runtime, enabling dynamic flows.

Links and references

* [Pydantic documentation](https://docs.pydantic.dev/latest/)
* Python: [https://www.python.org/](https://www.python.org/)
* ADK concepts: consult your SDK's runtime docs (import names like `LlmAgent`, `Workflow`, and `Event` may vary by SDK)

Start is a special node: every run begins at `START`. Declare clear input/output schemas on agents to make data passing explicit and type-safe across nodes.

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/google-adk-2-0/module/913ea931-c1bd-4df3-8a96-c2894e9df0d2/lesson/df3d5f31-39ef-457b-9ba5-df569a6f9bc7)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.