af_agent_runtime/
error.rs1use af_llm::{FinishReason, LlmError};
2
3#[derive(Debug, thiserror::Error)]
4pub enum RuntimeError {
5 #[error("invalid input: {0}")]
6 InvalidInput(String),
7 #[error("session already has an active run")]
8 SessionBusy,
9 #[error("session invariant failed: {0}")]
10 Invariant(String),
11 #[error("model failed: {0}")]
12 Model(String),
13 #[error("run cancelled")]
14 Cancelled,
15 #[error("model attempt interrupted by steering input")]
16 Steered,
17 #[error("model returned no choice")]
18 EmptyModelResponse,
19 #[error("model stopped with finish reason: {0}")]
20 FinishReason(FinishReason),
21 #[error("invalid arguments for tool {0}: {1}")]
22 InvalidToolArguments(String, String),
23 #[error("tool {0} denied: {1}")]
24 ToolDenied(String, String),
25 #[error("plugin hook failed: {0}")]
26 Hook(String),
27 #[error("extension deadline exceeded: {0}")]
28 ExtensionDeadline(String),
29 #[error("context contribution failed: {0}")]
30 Context(String),
31 #[error("conversation changed while compaction was running")]
32 CompactionConflict,
33 #[error("event append failed: {0}")]
34 Event(String),
35}
36
37impl RuntimeError {
38 pub fn code(&self) -> &'static str {
39 match self {
40 Self::InvalidInput(_) => "invalid_input",
41 Self::SessionBusy => "session_busy",
42 Self::CompactionConflict => "compaction_conflict",
43 Self::Cancelled => "cancelled",
44 Self::Steered => "steered",
45 Self::ToolDenied(_, _) => "tool_denied",
46 _ => "agent_run_failed",
47 }
48 }
49}
50
51impl From<LlmError> for RuntimeError {
52 fn from(error: LlmError) -> Self {
53 Self::Model(error.to_string())
54 }
55}