Skip to main content

langgraph_core_rs/graph/
node.rs

1use std::sync::Arc;
2use serde_json::Value as JsonValue;
3use crate::runnable::Runnable;
4use crate::types::RetryPolicy;
5
6/// Specification for a graph node.
7///
8/// Holds the node's runnable, metadata, and execution options.
9#[derive(Clone)]
10pub struct StateNodeSpec {
11    /// Name of this node.
12    pub name: String,
13    /// The executable logic for this node.
14    pub runnable: Arc<dyn Runnable>,
15    /// Optional retry policy.
16    pub retry_policy: Option<RetryPolicy>,
17    /// Optional metadata.
18    pub metadata: Option<JsonValue>,
19    /// Static destinations inferred from Command return types.
20    /// If set, the node can only route to these targets.
21    pub ends: Option<Vec<String>>,
22}
23
24impl StateNodeSpec {
25    pub fn new(name: impl Into<String>, runnable: Arc<dyn Runnable>) -> Self {
26        Self {
27            name: name.into(),
28            runnable,
29            retry_policy: None,
30            metadata: None,
31            ends: None,
32        }
33    }
34}