Skip to main content

wesichain_core/
agent_event.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
4#[serde(tag = "type", content = "data")]
5pub enum AgentEvent {
6    Status {
7        stage: String,
8        message: String,
9        step: usize,
10        thread_id: String,
11    },
12    Thought {
13        content: String,
14        step: usize,
15        metadata: Option<serde_json::Value>,
16    },
17    ToolCall {
18        id: String,
19        tool_name: String,
20        input: serde_json::Value,
21        step: usize,
22    },
23    Observation {
24        id: String,
25        tool_name: String,
26        output: serde_json::Value,
27        step: usize,
28    },
29    Final {
30        content: String,
31        step: usize,
32    },
33    Error {
34        message: String,
35        step: usize,
36        recoverable: bool,
37        source: Option<String>,
38    },
39    Metadata {
40        key: String,
41        value: serde_json::Value,
42    },
43}
44
45impl AgentEvent {
46    pub fn step(&self) -> Option<usize> {
47        match self {
48            Self::Status { step, .. }
49            | Self::Thought { step, .. }
50            | Self::ToolCall { step, .. }
51            | Self::Observation { step, .. }
52            | Self::Final { step, .. }
53            | Self::Error { step, .. } => Some(*step),
54            Self::Metadata { .. } => None,
55        }
56    }
57
58    pub fn thread_id(&self) -> Option<&str> {
59        match self {
60            Self::Status { thread_id, .. } => Some(thread_id.as_str()),
61            _ => None,
62        }
63    }
64}