Expand description
§adk-graph
Graph-based workflow orchestration for ADK-Rust agents, inspired by LangGraph.
§Overview
adk-graph builds stateful agent workflows as graphs of nodes and edges. A
GraphAgent implements the ADK Agent trait, so a graph runs under a Runner
and streams through it like any other agent.
§Features
- Graph-Based Workflows: Define agent workflows as directed graphs
- Cyclic Support: Native support for loops and iterative reasoning
- Conditional Routing: Dynamic edge routing based on state, or a goto from inside a node
- Fan-out / fan-in: Parallel branches in one super-step; a node with several incoming edges waits for the predecessors that can still reach it
- State Management: Typed state with reducers (overwrite, append, sum, custom)
- Checkpointing: Persistent, versioned state after each step, with memory, SQLite, PostgreSQL, Redis, MongoDB, Neo4j, and Firestore backends
- Human-in-the-Loop: Interrupt before/after nodes, dynamic interrupts, and
NodeContext::resume_valuefor the answer to a pause - Streaming: Multiple stream modes (values, updates, messages, custom, debug)
- ADK Integration:
AgentNoderuns any ADK agent as a node, and an agent’s failure isGraphError::AgentFailedwith the agent’s ownAdkError - YAML and JSON workflows (
yamlfeature): thedefinitionmodule reads a workflow file, validates it with each issue’s line and column, and builds it into a graph - Functional API (
functionalfeature): Write workflows as async functions with#[entrypoint]/#[task]macros, automatic checkpointing, typed state reducers (ReducedValue, UntrackedValue, MessagesValue), state schema validation, interrupt/resume, and loop iteration checkpoint keying
§Feature flags
No feature is on by default; the in-memory checkpointer needs none.
| Feature | Enables |
|---|---|
sqlite | The SQLite checkpointer |
postgres, redis, mongodb, neo4j, firestore | Checkpointers for shared databases |
conformance | CheckpointerHarness and checkpointer_conformance_tests! for testing a backend |
functional | The functional API: TaskContext, typed reducers, schema validation, cancellation |
node-cache | Per-node result caching; redis-cache adds a Redis store |
delta-checkpoint | The difference between super-steps stored instead of the full state |
time-travel | Step, fork and state history |
action | ActionNodeExecutor for adk-action node configurations |
action-http, action-rss, action-trigger | HTTP and notification nodes, RSS feeds, the cron and webhook trigger runtime |
action-db, action-email | Placeholders: database and email nodes are rejected when the graph compiles |
action-full | action, action-trigger, action-http, action-db, action-email and action-rss |
yaml | The definition module: workflows from YAML or JSON files, their validation and JSON Schema; implies action |
full | sqlite, action-full and yaml |
§Quick Start
use adk_graph::prelude::*;
let agent = GraphAgent::builder("processor")
.description("Process data through multiple steps")
.channels(&["data", "result"])
.node_fn("fetch", |_ctx| async move {
Ok(NodeOutput::new().with_update("data", json!({"items": [1, 2, 3]})))
})
.node_fn("transform", |ctx| async move {
let data = ctx.get("data").cloned().unwrap_or_default();
Ok(NodeOutput::new().with_update("result", data))
})
.edge(START, "fetch")
.edge("fetch", "transform")
.edge("transform", END)
.build()?;
// Execute
let result = agent.invoke(State::new(), ExecutionConfig::new("thread_1")).await?;
assert_eq!(result["result"], json!({"items": [1, 2, 3]}));§Loops and Conditional Edges
use adk_graph::prelude::*;
let agent = GraphAgent::builder("counter")
.channels(&["count"])
.node_fn("step", |ctx| async move {
let count = ctx.get("count").and_then(Value::as_i64).unwrap_or(0);
Ok(NodeOutput::new().with_update("count", json!(count + 1)))
})
.edge(START, "step")
.conditional_edge(
"step",
|state: &State| {
let count = state.get("count").and_then(Value::as_i64).unwrap_or(0);
if count < 3 { "step".to_string() } else { END.to_string() }
},
[("step", "step"), (END, END)], // Cycle back until the count reaches 3
)
.build()?;
let result = agent.invoke(State::new(), ExecutionConfig::new("thread_2")).await?;
assert_eq!(result["count"], json!(3));Re-exports§
pub use functional::schema::ExpectedType;pub use functional::schema::StateSchemaValidator;pub use functional::AppendReducer;pub use functional::ExecutionLog;pub use functional::FunctionalError;pub use functional::MergeReducer;pub use functional::MessagesValue;pub use functional::ReducedValue;pub use functional::ReplaceReducer;pub use functional::TaskContext;pub use functional::TypedReducer;pub use functional::UntrackedValue;pub use agent::GraphAgent;pub use agent::GraphAgentBuilder;pub use checkpoint::Checkpointer;pub use checkpoint::Durability;pub use checkpoint::MemoryCheckpointer;pub use checkpoint::RetentionPolicy;pub use decision::DecisionNode;pub use deferred::DeferredNodeConfig;pub use deferred::FanInTracker;pub use deferred::MergeStrategy;pub use edge::END;pub use edge::Edge;pub use edge::EdgeTarget;pub use edge::Router;pub use edge::START;pub use error::GraphError;pub use error::InterruptedExecution;pub use error::Result;pub use executor::PregelExecutor;pub use governed::EffectRecord;pub use governed::GovernedError;pub use governed::GovernedNode;pub use graph::CompiledGraph;pub use graph::StateGraph;pub use interrupt::GraphToolConfirmationPause;pub use interrupt::Interrupt;pub use interrupt::interrupt;pub use interrupt::interrupt_with_data;pub use node::AgentNode;pub use node::ExecutionConfig;pub use node::FunctionNode;pub use node::Node;pub use node::NodeContext;pub use node::NodeOutput;pub use record::Lineage;pub use record::NodeRecord;pub use record::NodeStatus;pub use record::RunRecord;pub use record::StepKind;pub use record::StepRecord;pub use shape::EdgeShape;pub use shape::GovernedShape;pub use shape::GraphShape;pub use shape::NodeKind;pub use shape::NodeShape;pub use state::Channel;pub use state::Checkpoint;pub use state::PendingWrite;pub use state::Reducer;pub use state::State;pub use state::StateSchema;pub use state::StateSchemaBuilder;pub use stream::StreamEvent;pub use stream::StreamMode;pub use timeout::OnTimeout;pub use timeout::ProgressHandle;pub use timeout::TimeoutPolicy;pub use timeout::execute_with_timeout;pub use checkpoint::SqliteCheckpointer;pub use checkpointers::firestore::FirestoreCheckpointer;pub use checkpointers::mongodb::MongoCheckpointer;pub use checkpointers::neo4j::Neo4jCheckpointer;pub use checkpointers::postgres::PostgresCheckpointer;pub use checkpointers::redis::RedisCheckpointer;pub use cache::CacheBackend;pub use cache::NodeCache;pub use cache::NodeCachePolicy;pub use cache::compute_cache_key;pub use delta::CheckpointType;pub use delta::DeltaCheckpointer;pub use delta::DeltaConfig;pub use delta::Diff;pub use delta::MapDelta;pub use delta::StringDelta;pub use delta::StringOp;pub use delta::VecDelta;pub use time_travel::ForkError;pub use time_travel::ForkSpec;pub use time_travel::StepInfo;pub use time_travel::TimeTravelHandle;pub use time_travel::fork_thread;
Modules§
- action
- Action node executor for adk-graph.
- agent
- GraphAgent - ADK Agent integration for graph workflows
- cache
- Node-level caching for graph execution.
- checkpoint
- Checkpointing for persistent graph state.
- checkpointers
- Checkpointers for shared databases.
- child
- Invoking a node from inside another node’s body.
- conformance
- Conformance suite for
Checkpointerbackends. - decision
DecisionNode: a graph router node whose route a model decides, with structured output.- deferred
- Deferred node (fan-in barrier) support for graph workflows.
- definition
- Graph workflows defined in YAML or JSON.
- delta
- Delta checkpoint compression for graph state.
- edge
- Edge types for graph control flow
- error
- Error types for adk-graph
- executor
- Pregel-based execution engine for graphs
- functional
- Functional API for Graph Workflows
- governed
- Governed graph nodes: a node whose call goes through the governed path, at most once per lineage (spec 3.3 §12 developer track, §7.1–§7.4, §11 S-I1, S-I2).
- graph
- StateGraph builder for constructing graphs
- interrupt
- Human-in-the-loop interrupt types
- node
- Node types for graph execution
- prelude
- Prelude module for convenient imports
- record
- Run, step and lineage records carried in checkpoint metadata (spec 3.3 §12, developer track).
- retry
- Per-node retry with exponential backoff.
- shape
- The static shape of a compiled graph, for workflow observers (spec 3.3 §12, developer track).
- state
- State management for graph execution
- stream
- Streaming types for graph execution
- subgraph
- Running one graph as a node of another.
- time_
travel - Time-travel debugging for graph execution history.
- timeout
- Timeout enforcement for graph node execution.
- tool
- Exposing a node or a whole graph as a tool an LLM can call.
- workflow
- Workflow schema types and loader for action node graph workflows.
Macros§
- checkpointer_
conformance_ tests - Generates one test per
conformancecase for aCheckpointerHarness.