Skip to main content

Module tool

Module tool 

Source
Available on crate feature graph only.
Expand description

Exposing a node or a whole graph as a tool an LLM can call.

A graph is often the deterministic part of a system: fixed steps, checked state, a durable checkpoint. An LlmAgent is the part that decides. Handing the graph to the model as a tool lets the model choose when the deterministic part runs without deciding how it runs.

adk-python exposes this as NodeTool; adk-go routes agent-as-tool through its dynamic sub-scheduler.

§Schemas

Node declares no input schema, so a tool over one node accepts any object unless a schema is supplied with with_parameters_schema. A tool over a whole graph derives its parameters from the graph’s declared state channels, which are known.

§Example

use adk_graph::edge::{END, START};
use adk_graph::graph::StateGraph;
use adk_graph::node::NodeOutput;
use adk_graph::tool::NodeTool;
use serde_json::json;
use std::sync::Arc;

let graph = Arc::new(
    StateGraph::with_channels(&["city", "forecast"])
        .add_node_fn("lookup", |ctx| async move {
            let city = ctx.get("city").and_then(|v| v.as_str()).unwrap_or("");
            Ok(NodeOutput::new().with_update("forecast", json!(format!("sunny in {city}"))))
        })
        .add_edge(START, "lookup")
        .add_edge("lookup", END)
        .compile()?,
);

let tool = NodeTool::for_graph(graph).with_description("Looks up a forecast.");
// builder.tool(Arc::new(tool))

Structs§

NodeTool
A Tool that runs a graph node, or a whole graph.