ri_agent_graph/
interrupt.rs1use crate::state::AgentState;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5#[derive(Debug, Clone, Default)]
7pub struct InterruptConfig {
8 pub interrupt_before: Vec<String>,
10 pub interrupt_after: Vec<String>,
12}
13
14impl InterruptConfig {
15 pub fn new() -> Self {
16 Self::default()
17 }
18
19 pub fn before(mut self, node: impl Into<String>) -> Self {
20 self.interrupt_before.push(node.into());
21 self
22 }
23
24 pub fn after(mut self, node: impl Into<String>) -> Self {
25 self.interrupt_after.push(node.into());
26 self
27 }
28
29 pub fn should_interrupt_before(&self, node: &str) -> bool {
30 self.interrupt_before.iter().any(|n| n == node)
31 }
32
33 pub fn should_interrupt_after(&self, node: &str) -> bool {
34 self.interrupt_after.iter().any(|n| n == node)
35 }
36
37 pub fn is_empty(&self) -> bool {
38 self.interrupt_before.is_empty() && self.interrupt_after.is_empty()
39 }
40}
41
42#[derive(Debug)]
44pub enum ExecutionResult {
45 Complete(AgentState),
47 Interrupted {
49 state: AgentState,
51 node: String,
53 interrupt_value: Option<Value>,
55 checkpoint_data: Option<InterruptCheckpoint>,
57 },
58 Failed {
64 error: crate::error::AgentGraphError,
66 state: AgentState,
68 },
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct InterruptCheckpoint {
74 pub resume_node: String,
76 pub resume_before: bool,
78 pub iteration: usize,
80 pub active_nodes: Vec<String>,
82 #[serde(default)]
85 pub graph_hash: Option<String>,
86}