Skip to main content

synaptic_graph/
send.rs

1/// A Send instruction for dynamic fan-out to multiple nodes.
2///
3/// In LangGraph, `Send` allows conditional edges to dispatch work to
4/// multiple nodes in parallel, each receiving a different state payload.
5/// This is useful for map-reduce patterns where a single node's output
6/// needs to be processed by multiple downstream nodes concurrently.
7///
8/// This is currently a placeholder type for future fan-out support.
9/// The type is defined and exported so that user code can start
10/// referencing it, but the actual parallel dispatch is not yet
11/// implemented in `CompiledGraph`.
12///
13/// # Example (future API)
14///
15/// ```ignore
16/// use synaptic_graph::Send;
17///
18/// // In a conditional edge router, return multiple Send instructions
19/// // to fan out to different nodes with different state payloads:
20/// let sends = vec![
21///     Send::new("process_chunk", serde_json::json!({"chunk": "part1"})),
22///     Send::new("process_chunk", serde_json::json!({"chunk": "part2"})),
23/// ];
24/// ```
25#[derive(Debug, Clone)]
26pub struct Send {
27    /// The target node to send work to.
28    pub node: String,
29    /// The state payload to pass to the target node (serialized as JSON).
30    pub state: serde_json::Value,
31}
32
33impl Send {
34    /// Create a new `Send` instruction.
35    ///
36    /// # Arguments
37    ///
38    /// * `node` - The name of the target node to send work to.
39    /// * `state` - The state payload (as a `serde_json::Value`) to pass.
40    pub fn new(node: impl Into<String>, state: serde_json::Value) -> Self {
41        Self {
42            node: node.into(),
43            state,
44        }
45    }
46}