Crate adk_graph

Crate adk_graph 

Source
Expand description

§adk-graph

Graph-based workflow orchestration for ADK-Rust agents, inspired by LangGraph.

§Overview

adk-graph provides a powerful way to build complex, stateful agent workflows using a graph-based approach. It brings LangGraph-style capabilities to the Rust ADK ecosystem while maintaining full compatibility with ADK’s agent system, callbacks, and streaming infrastructure.

§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
  • State Management: Typed state with reducers (overwrite, append, sum, custom)
  • Checkpointing: Persistent state after each step
  • Human-in-the-Loop: Interrupt before/after nodes, dynamic interrupts
  • Streaming: Multiple stream modes (values, updates, messages, debug)
  • ADK Integration: Full callback support, works with existing runners

§Quick Start

use adk_graph::prelude::*;

let agent = GraphAgent::builder("processor")
    .description("Process data through multiple steps")
    .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.state.get("data").unwrap();
        Ok(NodeOutput::new().with_update("result", data.clone()))
    })
    .edge(START, "fetch")
    .edge("fetch", "transform")
    .edge("transform", END)
    .build()?;

// Execute
let result = agent.invoke(State::new(), ExecutionConfig::new("thread_1")).await?;

§ReAct Pattern

use adk_graph::prelude::*;

let react_agent = GraphAgent::builder("react")
    .node(llm_agent_node)
    .node_fn("tools", execute_tools)
    .edge(START, "llm")
    .conditional_edge(
        "llm",
        |state| {
            if has_tool_calls(state) { "tools" } else { END }
        },
        [("tools", "tools"), (END, END)],
    )
    .edge("tools", "llm")  // Cycle back
    .recursion_limit(25)
    .build()?;

Re-exports§

pub use agent::GraphAgent;
pub use agent::GraphAgentBuilder;
pub use checkpoint::Checkpointer;
pub use checkpoint::MemoryCheckpointer;
pub use edge::Edge;
pub use edge::EdgeTarget;
pub use edge::Router;
pub use edge::END;
pub use edge::START;
pub use error::GraphError;
pub use error::InterruptedExecution;
pub use error::Result;
pub use executor::PregelExecutor;
pub use graph::CompiledGraph;
pub use graph::StateGraph;
pub use interrupt::interrupt;
pub use interrupt::interrupt_with_data;
pub use interrupt::Interrupt;
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 state::Channel;
pub use state::Checkpoint;
pub use state::Reducer;
pub use state::State;
pub use state::StateSchema;
pub use state::StateSchemaBuilder;
pub use stream::StreamEvent;
pub use stream::StreamMode;

Modules§

agent
GraphAgent - ADK Agent integration for graph workflows
checkpoint
Checkpointing for persistent graph state
edge
Edge types for graph control flow
error
Error types for adk-graph
executor
Pregel-based execution engine for graphs
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
state
State management for graph execution
stream
Streaming types for graph execution