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 max_concurrency(self, limit: usize) -> GraphAgentBuilder
pub fn max_concurrency(self, limit: usize) -> GraphAgentBuilder
Set recursion limit Cap how many nodes execute concurrently within one super-step.
pub fn recursion_limit(self, limit: usize) -> GraphAgentBuilder
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 mark_deferred(
self,
name: &str,
config: DeferredNodeConfig,
) -> GraphAgentBuilder
pub fn mark_deferred( self, name: &str, config: DeferredNodeConfig, ) -> GraphAgentBuilder
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()?;Configure fan-in for a node already added with node.
deferred_node both adds and configures a node, so
a custom Node added through node had no way to set a merge strategy or
a fan-in timeout.
A node reached by more than one unconditional edge is deferred automatically; this overrides that default.
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,
Sourcepub fn node_cache(
self,
name: &str,
policy: NodeCachePolicy,
) -> GraphAgentBuilder
Available on crate feature node-cache only.
pub fn node_cache( self, name: &str, policy: NodeCachePolicy, ) -> GraphAgentBuilder
node-cache only.Set a cache policy for a specific node.
When a node has a cache policy, its execution results are cached keyed by a blake3 hash of the node name and input state. Subsequent executions with identical inputs return the cached result without re-executing the node.
§Arguments
name— the name of the node to cachepolicy— the cache policy specifying backend and TTL
§Example
use std::time::Duration;
use adk_graph::cache::{CacheBackend, NodeCachePolicy};
let agent = GraphAgent::builder("cached_graph")
.node_cache("expensive_node", NodeCachePolicy {
backend: CacheBackend::InMemory { max_entries: 128 },
ttl: Some(Duration::from_secs(300)),
})
.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
Auto Trait Implementations§
impl !RefUnwindSafe for GraphAgentBuilder
impl !UnwindSafe for GraphAgentBuilder
impl Freeze for GraphAgentBuilder
impl Send for GraphAgentBuilder
impl Sync for GraphAgentBuilder
impl Unpin for GraphAgentBuilder
impl UnsafeUnpin for GraphAgentBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.