Skip to main content

ri_agent_graph/
stream.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::collections::HashMap;
4
5/// Events emitted during graph execution.
6#[non_exhaustive]
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub enum StreamEvent {
9    /// Graph execution started
10    GraphStart { graph_name: Option<String> },
11    /// Graph execution ended
12    GraphEnd { graph_name: Option<String> },
13    /// Node execution started
14    NodeStart { node: String },
15    /// Node execution ended
16    NodeEnd { node: String },
17    /// State was updated by a node
18    StateUpdate {
19        node: String,
20        updates: HashMap<String, Value>,
21    },
22    /// A parallel superstep started
23    SuperstepStart { step: usize, nodes: Vec<String> },
24    /// A parallel superstep ended
25    SuperstepEnd { step: usize },
26    /// Execution was interrupted
27    Interrupt { node: String, value: Option<Value> },
28    /// Custom event emitted by a node
29    Custom(Value),
30}
31
32/// Stream mode controls what events are emitted.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
34pub enum StreamMode {
35    /// Emit full state after each node execution
36    Values,
37    /// Emit only changed state keys after each node execution
38    Updates,
39    /// Emit all events
40    #[default]
41    Events,
42}