pub fn conditional(
predicate: impl Fn(&Value) -> bool + Send + Sync + 'static,
if_true: AgentBuilder,
if_false: AgentBuilder,
) -> ComposableExpand description
Conditional: route to one of two agents based on a state predicate.
Evaluates predicate against the current state. If it returns true,
the if_true agent runs; otherwise, the if_false agent runs.
§Arguments
predicate— Function that inspects state (asserde_json::Value) and returns a bool.if_true— Agent to run when the predicate is true.if_false— Agent to run when the predicate is false.
§Example
ⓘ
let routed = conditional(
|state| state.get("premium").and_then(|v| v.as_bool()).unwrap_or(false),
AgentBuilder::new("premium-agent").instruction("Full-featured response"),
AgentBuilder::new("basic-agent").instruction("Basic response"),
);