Skip to content
Blog

Sub-Workflows: Nesting Workflows Inside Parent Workflow Graphs

Compose a Workflow as a node inside a parent graph, define the data contract across the boundary, and decide when to nest, flatten, or hand off to a dynamic or collaborative orchestrator.

Published on • December 2, 2026

AI Assistant

A document-processing pipeline has grown to twenty-three nodes: ingest, three classification branches, four enrichment steps, a merge, two export formats. Every node sits in one flat edges list, and the file is now harder to navigate than the process it describes. Worse, the “enrichment” steps are needed — unchanged — by a second pipeline, and copying them means copying bugs.

The escape hatch is already in the docs: a Workflow is itself a node. You can place one inside another workflow’s edges, use it as a branch target, and let it present a single face to the parent while keeping its own internal topology. This post covers how nesting works, what crosses the boundary, and when not to nest.

Prerequisites

  • ADK 2.0 graph workflows: Workflow, edges, routers with Event(route=...), and JoinNode. See the graph workflows intro and our conditional edge routing post for the basics.
  • Familiarity with fan-out/fan-in graphs (multiple START rows feeding a JoinNode).

1. A workflow is a node

The composition rule is one sentence from the docs: a Workflow is itself a node, so you can use one inside another workflow’s edges to encapsulate a reusable sub-process. In practice this appears in two positions.

As a sequential step:

from google.adk import Workflow

root_agent = Workflow(
    name="parent_workflow",
    edges=[
        ("START", task_A1, workflow_B, final_node),
    ],
)

As a branch target:

root_agent = Workflow(
    name="parent_workflow",
    edges=[
        ("START", task_A1, router),
        (router, {
            "RUN_WORKFLOW_B": workflow_B,
            "RUN_WORKFLOW_C": workflow_C,
        }),
    ],
)

Each child is an ordinary workflow with its own edges:

workflow_B = Workflow(
    name="workflow_B",
    edges=[("START", b_title_case, b_frame)],
)
workflow_C = Workflow(
    name="workflow_C",
    edges=[("START", c_lower_case, c_frame)],
)

From the parent’s perspective, workflow_B is one box. Internally it has its own START, its own routes, its own terminal node — and none of that leaks into the parent’s edges list.

2. What crosses the boundary

The parent/child contract is deliberately thin.

Output: one value. When the nested workflow completes, the output of its terminal node becomes the output of the nested-workflow node on the parent’s edge. The parent never sees the child’s intermediate values — it receives exactly what the child’s last node produced, exactly like any other node’s output.

Events: full visibility. While the inner workflow runs, each of its node events bubbles up to the parent for traceability. In the ADK Web UI’s event history you can watch a child’s internal steps as part of the parent’s run — encapsulation for the graph, transparency for observability.

Input: whatever you route to it. The value arriving on the parent edge becomes the child’s input, so a child used in two parents must tolerate both parents’ payload shapes — or you normalize at the boundary.

Retries: whole-subprocess granularity. In Python you can attach a retry policy to a nested workflow, and then a failure of any node inside it retries the nested workflow. That is occasionally what you want (an idempotent, cheap sub-process) and usually not: prefer setting the retry policy on the individual node that calls the unreliable service, which retries less work and gives you more control.

3. The two hard rules

Nesting surfaces two validation constraints that are easy to hit once graphs get big:

  1. A workflow must have at most one terminal node that produces output. If two parallel branches both end in an output, the workflow fails with a ValueError at build time. Merge them with a JoinNode before the graph ends. This rule applies to every workflow — but it is nested children where it surprises people, because the child’s internal fan-out was written by a different person (or a different past you) than the parent.
  2. Nodes that feed a JoinNode must produce output. The join releases only after all predecessors finish, and it passes its successor a record keyed by predecessor node name. A predecessor that finishes without an output leaves that branch of the record empty, and the failure surfaces downstream, far from the node that caused it. Attach a retry configuration to any node that can fail this way.

4. Data contracts across the boundary

Because a child collapses to a single output, the child’s terminal node is its public API. Treat it that way:

class EnrichmentResult(BaseModel):
    doc_id: str
    entities: list[str]
    sentiment: str


@node(output_schema=EnrichmentResult)   # explicit contract on the child's last node
def finalize_enrichment(node_input: dict):
    ...

Practical contract discipline:

  • Declare input_schema / output_schema on the boundary nodes — the child’s first node and its terminal node — so mismatches fail loudly instead of as a downstream KeyError.
  • Version the payload, not the graph. If parents must send different shapes, add an adapter node at the parent’s side of the boundary rather than overloading the child.
  • Make the terminal node stable. Renaming or reordering the child’s last node changes what the parent receives; treat that change like an API change.
  • Keep the child’s output serializable. It travels as an event field; large or non-serializable objects belong in session state or artifacts, referenced by ID.

5. Naming and scoping pitfalls

  • Node names are the join key. A JoinNode’s output is a record keyed by predecessor node name, and your diagram exporter (see our visualization post) labels nodes by .name. Two internal nodes with the same name — easy when two children both contain a finalize node — make join records and diagrams ambiguous. Prefix child-internal names when children are likely to be inspected together.
  • chat-mode agents are only allowed directly after START. An agent used as a graph node defaults to single_turn; a chat agent consumes conversational history rather than a node’s input. Inside a child, “directly after START” means the child’s START — but if the child is a branch target mid-parent-graph, you almost certainly want single_turn handlers anyway.
  • Branch routes are scoped to their source node. Two routers in different children can both define a "RETRY" route without colliding — but if you copy-paste a child and change only one route, you will debug the wrong router for an hour. Make route names specific to the child.
  • The child’s START row is not the parent’s. Wiring mistakes happen when someone adds a node to the parent’s edge list expecting it to run “inside” the child. Edges are per-workflow; there is no implicit inheritance.

6. Nesting vs flat graphs vs other orchestrators

Nesting is one of four composition tools in ADK 2.0. The workflows overview sorts them; here is the decision in practice:

ApproachReach for it when…Watch out for…
Flat graphThe process is a handful of nodes; every branch matters to the reader of one file.The edges list becomes the thing you scroll past; duplicate sub-processes get copy-pasted.
Nested sub-workflowsA multi-step sub-process is reused, is independently meaningful, or has its own validation/fan-in.Boundary contracts drift; the single-terminal-output rule; whole-subprocess retry granularity.
Dynamic workflow (ctx.run_node)Control flow is iterative or recursive — loops with data-dependent bounds, unbounded fan-out, “run until the model is happy.”You trade the at-a-glance topology for code; checkpointing rules (rerun_on_resume=True) now govern every orchestrator body.
Collaborative team (coordinator + sub-agents)The work is genuinely delegated and self-managing — a coordinator hands substantial tasks to specialists that return results.mode applies to sub-agents only (not root agents); task mode agents must be leaf agents; task mode is currently disabled inside graph-based workflows in ADK Python v2.0.0.

A useful heuristic: if the sub-process has a name you’d use in conversation (“the enrichment step”), it is probably a sub-workflow; if its loop bound is data, it is probably dynamic; if it needs to decide what to delegate, it is probably a coordinator.

Collaborative nesting deserves one extra note: task and single-turn agents can be placed as workflow graph nodes, and they behave differently by invocation context. As a workflow node, the agent runs and control automatically advances to the next node. As a transferee from an LlmAgent via its delegation tool, it runs until it calls finish_task and returns control to the originating agent. The same agent works in both — the runtime picks the control flow.

Also relevant to boundary hygiene: task and single-turn agents each operate in their own isolated session branch, so parallel peers cannot see each other’s events; the parent receives the collected results once all branches complete. That isolation is a feature for parallel children — and a trap if you expected two children to share state implicitly. Pass data across child boundaries explicitly.

7. A worked shape

from google.adk import Workflow

# --- child: self-contained, single terminal output ---
enrichment = Workflow(
    name="enrichment_pipeline",
    edges=[
        ("START", extract_entities, score_sentiment, summarize),
    ],
)

# --- parent: the child is one node, one branch target, one output ---
root_agent = Workflow(
    name="processing_workflow",
    edges=[
        ("START", classify_document),
        (classify_document, {
            "NEEDS_ENRICHMENT": enrichment,   # sub-workflow as branch target
            "SIMPLE": pass_through,           # plain function node
        }),
        (enrichment, render_output),
        (pass_through, render_output),
        (render_output, finalize),
    ],
)

The parent file stays readable: classify, enrich-or-pass, render, finalize. The enrichment topology — and any future fix to it — lives in one place, shared by any other workflow that imports enrichment_pipeline.

Checklist

  • Each child has exactly one terminal node producing output (merge parallel ends with a JoinNode).
  • Every node feeding a JoinNode produces output, and can-fail ones carry a retry_config.
  • Boundary nodes declare input_schema / output_schema.
  • Node names are unique across parent and children (join keys, diagrams, traces).
  • Retry policies sit on the flaky node, not on the whole child, unless whole-subprocess retry is intended.
  • Child outputs are small, serializable, and versioned at the parent’s adapter.
  • Shared sub-processes are imported as Workflow objects, not copy-pasted.
  • Cross-child data flows explicitly — no reliance on implicit shared state between isolated branches.

Nesting does not make a workflow more powerful — every nested graph could be flattened into the parent. It makes the workflow more legible and reusable: the parent states the process, the child owns the mechanics, and the boundary states the contract. That is the same bargain components have always made, applied to agent graphs.

References