pub struct GraphAgentBuilder { /* private fields */ }Expand description
Builder for GraphAgent
Implementations§
Source§impl GraphAgentBuilder
impl GraphAgentBuilder
Sourcepub fn description(self, desc: &str) -> Self
pub fn description(self, desc: &str) -> Self
Set description
Sourcepub fn state_schema(self, schema: StateSchema) -> Self
pub fn state_schema(self, schema: StateSchema) -> Self
Set state schema
Sourcepub fn node_fn<F, Fut>(self, name: &str, func: F) -> Selfwhere
F: Fn(NodeContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<NodeOutput>> + Send + 'static,
pub fn node_fn<F, Fut>(self, name: &str, func: F) -> Selfwhere
F: Fn(NodeContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<NodeOutput>> + Send + 'static,
Add a function as a node
Sourcepub fn conditional_edge<F, I>(self, source: &str, router: F, targets: I) -> Self
pub fn conditional_edge<F, I>(self, source: &str, router: F, targets: I) -> Self
Add a conditional edge
Sourcepub fn checkpointer<C: Checkpointer + 'static>(self, checkpointer: C) -> Self
pub fn checkpointer<C: Checkpointer + 'static>(self, checkpointer: C) -> Self
Set checkpointer
Sourcepub fn checkpointer_arc(self, checkpointer: Arc<dyn Checkpointer>) -> Self
pub fn checkpointer_arc(self, checkpointer: Arc<dyn Checkpointer>) -> Self
Set checkpointer with Arc
Sourcepub fn interrupt_before(self, nodes: &[&str]) -> Self
pub fn interrupt_before(self, nodes: &[&str]) -> Self
Set nodes to interrupt before
Sourcepub fn interrupt_after(self, nodes: &[&str]) -> Self
pub fn interrupt_after(self, nodes: &[&str]) -> Self
Set nodes to interrupt after
Sourcepub fn recursion_limit(self, limit: usize) -> Self
pub fn recursion_limit(self, limit: usize) -> Self
Set recursion limit
Sourcepub fn node_timeout(self, node_name: &str, policy: TimeoutPolicy) -> Self
pub fn node_timeout(self, node_name: &str, policy: TimeoutPolicy) -> Self
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) -> Self
pub fn default_timeout(self, policy: TimeoutPolicy) -> Self
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,
) -> Selfwhere
F: Fn(NodeContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<NodeOutput>> + Send + 'static,
pub fn deferred_node<F, Fut>(
self,
name: &str,
func: F,
config: DeferredNodeConfig,
) -> Selfwhere
F: Fn(NodeContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<NodeOutput>> + 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) -> Self
pub fn input_mapper<F>(self, mapper: F) -> Self
Set custom input mapper
Sourcepub fn output_mapper<F>(self, mapper: F) -> Self
pub fn output_mapper<F>(self, mapper: F) -> Self
Set custom output mapper
Sourcepub fn before_agent_callback<F, Fut>(self, callback: F) -> Self
pub fn before_agent_callback<F, Fut>(self, callback: F) -> Self
Set before agent callback
Sourcepub fn after_agent_callback<F, Fut>(self, callback: F) -> Self
pub fn after_agent_callback<F, Fut>(self, callback: F) -> Self
Set after agent callback
Note: The callback receives a cloned Event to avoid lifetime issues.
Sourcepub fn build(self) -> Result<GraphAgent>
pub fn build(self) -> Result<GraphAgent>
Build the GraphAgent