ri_agent_graph/
outcome.rs1use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6#[derive(Debug, Clone)]
8pub enum NodeOutcome {
9 Continue { output: Value },
11 Interrupt { interrupt: Interrupt },
13 Fail { error: String },
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct Interrupt {
23 pub kind: InterruptKind,
25 pub payload: Value,
27 pub correlation_id: String,
29}
30
31impl Interrupt {
32 pub fn await_input(payload: Value) -> Self {
34 Self {
35 kind: InterruptKind::AwaitInput,
36 payload,
37 correlation_id: uuid::Uuid::new_v4().to_string(),
38 }
39 }
40
41 pub fn await_approval(payload: Value) -> Self {
43 Self {
44 kind: InterruptKind::AwaitApproval,
45 payload,
46 correlation_id: uuid::Uuid::new_v4().to_string(),
47 }
48 }
49
50 pub fn custom(kind: impl Into<String>, payload: Value) -> Self {
52 Self {
53 kind: InterruptKind::Custom(kind.into()),
54 payload,
55 correlation_id: uuid::Uuid::new_v4().to_string(),
56 }
57 }
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
62pub enum InterruptKind {
63 AwaitInput,
65 AwaitApproval,
67 Custom(String),
69}
70
71impl std::fmt::Display for InterruptKind {
72 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73 match self {
74 InterruptKind::AwaitInput => write!(f, "await_input"),
75 InterruptKind::AwaitApproval => write!(f, "await_approval"),
76 InterruptKind::Custom(s) => write!(f, "custom:{}", s),
77 }
78 }
79}