pub struct GraphAgentBuilder { /* private fields */ }graph only.Expand description
Builder for GraphAgent
Implementations§
Source§impl GraphAgentBuilder
impl GraphAgentBuilder
Sourcepub fn new(name: &str) -> GraphAgentBuilder
pub fn new(name: &str) -> GraphAgentBuilder
Create a new builder
Sourcepub fn description(self, desc: &str) -> GraphAgentBuilder
pub fn description(self, desc: &str) -> GraphAgentBuilder
Set description
Sourcepub fn state_schema(self, schema: StateSchema) -> GraphAgentBuilder
pub fn state_schema(self, schema: StateSchema) -> GraphAgentBuilder
Set state schema
Sourcepub fn channels(self, channels: &[&str]) -> GraphAgentBuilder
pub fn channels(self, channels: &[&str]) -> GraphAgentBuilder
Add channels to state schema
Sourcepub fn node<N>(self, node: N) -> GraphAgentBuilderwhere
N: Node + 'static,
pub fn node<N>(self, node: N) -> GraphAgentBuilderwhere
N: Node + 'static,
Add a node
Sourcepub fn node_fn<F, Fut>(self, name: &str, func: F) -> GraphAgentBuilderwhere
F: Fn(NodeContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<NodeOutput, GraphError>> + Send + 'static,
pub fn node_fn<F, Fut>(self, name: &str, func: F) -> GraphAgentBuilderwhere
F: Fn(NodeContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<NodeOutput, GraphError>> + Send + 'static,
Add a function as a node
Sourcepub fn edge(self, source: &str, target: &str) -> GraphAgentBuilder
pub fn edge(self, source: &str, target: &str) -> GraphAgentBuilder
Add a direct edge
Sourcepub fn conditional_edge<F, I>(
self,
source: &str,
router: F,
targets: I,
) -> GraphAgentBuilder
pub fn conditional_edge<F, I>( self, source: &str, router: F, targets: I, ) -> GraphAgentBuilder
Add a conditional edge
Sourcepub fn checkpointer<C>(self, checkpointer: C) -> GraphAgentBuilderwhere
C: Checkpointer + 'static,
pub fn checkpointer<C>(self, checkpointer: C) -> GraphAgentBuilderwhere
C: Checkpointer + 'static,
Set checkpointer
Sourcepub fn checkpointer_arc(
self,
checkpointer: Arc<dyn Checkpointer>,
) -> GraphAgentBuilder
pub fn checkpointer_arc( self, checkpointer: Arc<dyn Checkpointer>, ) -> GraphAgentBuilder
Set checkpointer with Arc
Sourcepub fn interrupt_before(self, nodes: &[&str]) -> GraphAgentBuilder
pub fn interrupt_before(self, nodes: &[&str]) -> GraphAgentBuilder
Set nodes to interrupt before
Sourcepub fn interrupt_after(self, nodes: &[&str]) -> GraphAgentBuilder
pub fn interrupt_after(self, nodes: &[&str]) -> GraphAgentBuilder
Set nodes to interrupt after
Sourcepub fn recursion_limit(self, limit: usize) -> GraphAgentBuilder
pub fn recursion_limit(self, limit: usize) -> GraphAgentBuilder
Set recursion limit
Sourcepub fn node_timeout(
self,
node_name: &str,
policy: TimeoutPolicy,
) -> GraphAgentBuilder
pub fn node_timeout( self, node_name: &str, policy: TimeoutPolicy, ) -> GraphAgentBuilder
Set a timeout policy for a specific node.
The policy is applied when the named node executes, enforcing wall-clock and/or idle timeouts with the configured recovery action.
§Example
use std::time::Duration;
use adk_graph::timeout::{TimeoutPolicy, OnTimeout};
let agent = GraphAgent::builder("my_graph")
.node_timeout("slow_node", TimeoutPolicy {
run_timeout: Some(Duration::from_secs(10)),
idle_timeout: None,
on_timeout: OnTimeout::Fail,
})
.build()?;Sourcepub fn default_timeout(self, policy: TimeoutPolicy) -> GraphAgentBuilder
pub fn default_timeout(self, policy: TimeoutPolicy) -> GraphAgentBuilder
Set a default timeout policy applied to all nodes without an explicit override.
Nodes that have a per-node policy set via node_timeout
will use their specific policy instead of this default.
§Example
use std::time::Duration;
use adk_graph::timeout::{TimeoutPolicy, OnTimeout};
let agent = GraphAgent::builder("my_graph")
.default_timeout(TimeoutPolicy {
run_timeout: Some(Duration::from_secs(30)),
idle_timeout: Some(Duration::from_secs(5)),
on_timeout: OnTimeout::Skip,
})
.build()?;Sourcepub fn deferred_node<F, Fut>(
self,
name: &str,
func: F,
config: DeferredNodeConfig,
) -> GraphAgentBuilderwhere
F: Fn(NodeContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<NodeOutput, GraphError>> + Send + 'static,
pub fn deferred_node<F, Fut>(
self,
name: &str,
func: F,
config: DeferredNodeConfig,
) -> GraphAgentBuilderwhere
F: Fn(NodeContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<NodeOutput, GraphError>> + Send + 'static,
Add a deferred (fan-in barrier) node to the graph.
A deferred node waits for all upstream parallel paths to complete before
executing. The provided function is wrapped as a FunctionNode and the
DeferredNodeConfig controls how upstream outputs are merged and how
long the node waits for all paths.
§Arguments
name- The name of the deferred node.func- The async function to execute once all upstream paths complete.config- Configuration controlling merge strategy and fan-in timeout.
§Example
use std::time::Duration;
use adk_graph::deferred::{DeferredNodeConfig, MergeStrategy};
use adk_graph::node::NodeOutput;
let agent = GraphAgent::builder("scatter_gather")
.deferred_node("aggregator", |_ctx| async {
Ok(NodeOutput::new().with_update("status", serde_json::json!("merged")))
}, DeferredNodeConfig {
merge_strategy: MergeStrategy::Collect,
fan_in_timeout: Some(Duration::from_secs(30)),
})
.build()?;Sourcepub fn input_mapper<F>(self, mapper: F) -> GraphAgentBuilder
pub fn input_mapper<F>(self, mapper: F) -> GraphAgentBuilder
Set custom input mapper
Sourcepub fn output_mapper<F>(self, mapper: F) -> GraphAgentBuilder
pub fn output_mapper<F>(self, mapper: F) -> GraphAgentBuilder
Set custom output mapper
Sourcepub fn before_agent_callback<F, Fut>(self, callback: F) -> GraphAgentBuilder
pub fn before_agent_callback<F, Fut>(self, callback: F) -> GraphAgentBuilder
Set before agent callback
Sourcepub fn after_agent_callback<F, Fut>(self, callback: F) -> GraphAgentBuilder
pub fn after_agent_callback<F, Fut>(self, callback: F) -> GraphAgentBuilder
Set after agent callback
Note: The callback receives a cloned Event to avoid lifetime issues.
Sourcepub fn build(self) -> Result<GraphAgent, GraphError>
pub fn build(self) -> Result<GraphAgent, GraphError>
Build the GraphAgent