Skip to main content

langgraph_core_rs/
runtime.rs

1use std::sync::Arc;
2use serde_json::Value as JsonValue;
3use tokio::sync::mpsc;
4use langgraph_checkpoint::store::base::BaseStore;
5
6/// StreamWriter sends custom stream chunks to the output stream.
7/// Nodes can use this to emit arbitrary data when `stream_mode` includes "custom".
8pub type StreamWriter = mpsc::Sender<JsonValue>;
9
10/// Runtime context for graph execution
11#[derive(Clone)]
12pub struct Runtime<Ctx: Clone = ()> {
13    /// Run-scoped immutable context (user_id, db_conn, etc.)
14    pub context: Ctx,
15    /// Persistence/memory store
16    pub store: Option<Arc<dyn BaseStore>>,
17    /// Channel sender for custom streaming
18    pub stream_writer: Option<StreamWriter>,
19    /// Previous return value (functional API)
20    pub previous: Option<JsonValue>,
21    /// Execution metadata
22    pub execution_info: Option<ExecutionInfo>,
23    /// Server metadata
24    pub server_info: Option<ServerInfo>,
25}
26
27/// Execution info for the current task
28#[derive(Debug, Clone)]
29pub struct ExecutionInfo {
30    pub checkpoint_id: String,
31    pub checkpoint_ns: String,
32    pub task_id: String,
33    pub thread_id: Option<String>,
34    pub run_id: Option<String>,
35}
36
37/// Server info from LangGraph Server
38#[derive(Debug, Clone)]
39pub struct ServerInfo {
40    pub server_url: Option<String>,
41}