Module workflow

Module workflow 

Source
Expand description

Workflow graph runtime — the ADK 2.0 “graph execution” pattern.

A Workflow is a directed acyclic graph (DAG) of execution nodes with dependencies. Unlike the crate::flow module (which governs conversation and tool-call ordering), workflows execute node graphs concurrently: agents, functions, and human-in-the-loop approval nodes.

§Execution Model

The runtime repeatedly collects ready nodes — those whose dependencies are all in a terminal state (finished or skipped; join_any nodes are ready as soon as one dependency finishes). Ready nodes whose when guard evaluates to false are marked skipped and do not run, and skips cascade: a node all of whose dependencies were skipped is itself skipped — an unselected branch never executes side effects. Ready nodes run concurrently via tokio::task::JoinSet, and readiness is recomputed after every node completion, so a join_any dependent starts the moment its first dependency finishes rather than waiting out the wave.

Agent and function nodes write their outputs to:

  • The WorkflowRun::outputs map (under their node ID)
  • State key workflow:<node_id> (as JSON, for downstream instruction templates)

Approval nodes suspend until an external WorkflowController approves or rejects them; decisions arriving before the node is ready are stored, never lost. Rejection fails the entire run. Workflow::run (no controller) rejects workflows containing approval nodes up front instead of hanging.

§DAG Invariants

  • Cycle detection (topological check) at build time.
  • Unknown dependencies rejected at build time.
  • Duplicate node IDs rejected at build time.
  • Deadlock guard: if unfinished nodes exist but none are ready, the run fails.

§Example

let wf = Workflow::builder()
    .function("fetch", |s| async { Ok(json!({"data": "value"})) })
    .function("process", |s| async { Ok(json!({"result": "done"})) })
    .after(&["fetch"])
    .approval("review")
    .after(&["process"])
    .build()?;

let run = wf.run_with(&state, controller).await?;
assert!(run.outputs.contains_key("review"));

Structs§

Workflow
A validated workflow graph ready for execution.
WorkflowBuilder
Builder for constructing a Workflow.
WorkflowController
Controller for HITL (human-in-the-loop) approval nodes.
WorkflowRun
The result of a completed workflow run.

Enums§

WorkflowError
Errors that can occur during workflow execution or construction.