pub fn conditional(
predicate: impl Fn(&Value) -> bool + Send + Sync + 'static,
if_true: impl Into<Composable>,
if_false: impl Into<Composable>,
) -> ComposableExpand description
Conditional: run one of two workflows, chosen by a state predicate.
predicate sees the state (as a JSON object) when the compiled agent
runs. If it returns true, if_true runs; otherwise if_false runs.
Exactly one branch runs, and each branch keeps its full configuration.
§Arguments
predicate— Function that inspects state (asserde_json::Value) and returns a bool.if_true— Agent or workflow to run when the predicate is true.if_false— Agent or workflow 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"),
);
assert!(matches!(routed, Composable::Branch(_)));