Skip to main content

langgraph_core_rs/runnable/
base.rs

1use async_trait::async_trait;
2use serde_json::Value as JsonValue;
3use langgraph_checkpoint::config::RunnableConfig;
4use crate::types::GraphInterrupt;
5
6/// Core Runnable trait — the universal execution abstraction.
7///
8/// All input/output is type-erased to `serde_json::Value` to match
9/// the channel layer's type erasure strategy.
10#[async_trait]
11pub trait Runnable: Send + Sync {
12    /// Execute synchronously.
13    fn invoke(&self, input: &JsonValue, config: &RunnableConfig) -> Result<JsonValue, RunnableError>;
14
15    /// Execute asynchronously.
16    async fn ainvoke(&self, input: &JsonValue, config: &RunnableConfig) -> Result<JsonValue, RunnableError>;
17
18    /// Human-readable name for tracing/debugging.
19    fn name(&self) -> &str {
20        std::any::type_name::<Self>()
21    }
22}
23
24/// Errors from Runnable execution.
25#[derive(Debug, thiserror::Error)]
26pub enum RunnableError {
27    #[error("node error: {0}")]
28    Node(String),
29
30    #[error("config error: {0}")]
31    Config(String),
32
33    #[error("channel error: {0}")]
34    Channel(#[from] langgraph_checkpoint::error::ChannelError),
35
36    #[error(transparent)]
37    Other(#[from] Box<dyn std::error::Error + Send + Sync>),
38
39    #[error("runner error: {0}")]
40    Runner(String),
41
42    #[error("graph interrupt")]
43    Interrupt(GraphInterrupt),
44}