Skip to main content

node_fn_with_state

Function node_fn_with_state 

Source
pub fn node_fn_with_state<F, Fut>(f: F) -> StateFnNode<F>
where F: Fn(String, RunState) -> Fut + WasmCompatSend + WasmCompatSync, Fut: Future<Output = Result<String, NodeError>> + WasmCompatSend + 'static,
Expand description

A node that runs f with the request-scoped state of its run: as node_fn, and f also gets the RunState the graph was started with.

use rig_multiagent::{RunState, node_fn_with_state};
struct Prefix(&'static str);
let tag = node_fn_with_state(|input: String, state: RunState| async move {
    let prefix = state.get::<Prefix>().map_or("", |prefix| prefix.0);
    Ok(format!("{prefix}{input}"))
});