oris_kernel/kernel/
action.rs1use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8use crate::kernel::identity::RunId;
9use crate::kernel::KernelError;
10
11#[derive(Clone, Debug, Serialize, Deserialize)]
13pub enum Action {
14 CallTool {
15 tool: String,
16 input: Value,
17 },
18 CallLLM {
19 provider: String,
20 input: Value,
21 },
22 Sleep {
23 millis: u64,
24 },
25 WaitSignal {
27 name: String,
28 },
29}
30
31#[derive(Clone, Debug)]
33pub enum ActionResult {
34 Success(Value),
35 Failure(String),
36}
37
38#[derive(Clone, Debug)]
40pub enum ActionErrorKind {
41 Transient,
43 Permanent,
45 RateLimited,
47}
48
49#[derive(Clone, Debug)]
51pub struct ActionError {
52 pub kind: ActionErrorKind,
53 pub message: String,
54 pub retry_after_ms: Option<u64>,
55}
56
57impl ActionError {
58 pub fn transient(message: impl Into<String>) -> Self {
59 Self {
60 kind: ActionErrorKind::Transient,
61 message: message.into(),
62 retry_after_ms: None,
63 }
64 }
65
66 pub fn permanent(message: impl Into<String>) -> Self {
67 Self {
68 kind: ActionErrorKind::Permanent,
69 message: message.into(),
70 retry_after_ms: None,
71 }
72 }
73
74 pub fn rate_limited(message: impl Into<String>, retry_after_ms: u64) -> Self {
75 Self {
76 kind: ActionErrorKind::RateLimited,
77 message: message.into(),
78 retry_after_ms: Some(retry_after_ms),
79 }
80 }
81
82 pub fn from_kernel_error(e: &KernelError) -> Self {
85 if let KernelError::Executor(ae) = e {
86 ae.clone()
87 } else {
88 Self::permanent(e.to_string())
89 }
90 }
91}
92
93impl std::fmt::Display for ActionError {
94 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95 write!(f, "{}", self.message)
96 }
97}
98
99pub trait ActionExecutor: Send + Sync {
102 fn execute(&self, run_id: &RunId, action: &Action) -> Result<ActionResult, KernelError>;
103}