rpi_agent/error.rs
1//! Mirrors `packages/agent/src` error surface. Pi's agent layer reports failures
2//! via thrown errors that the loop catches and encodes into tool results / event
3//! sequences; Rust encodes the same cases as a per-crate `thiserror` enum.
4
5/// Failures raised inside the agent loop. Cannot cross the provider boundary
6/// (provider failures arrive as `AssistantMessageEvent::Error`); these surface
7/// from tool execution, argument validation, queue/state misuse, or abort.
8#[derive(Debug, Clone, thiserror::Error)]
9pub enum AgentError {
10 #[error("tool error: {0}")]
11 Tool(String),
12
13 #[error("validation error: {0}")]
14 Validation(String),
15
16 #[error("operation aborted")]
17 Abort,
18
19 #[error("provider error: {0}")]
20 Provider(String),
21
22 #[error("queue error: {0}")]
23 Queue(String),
24
25 #[error("invalid state: {0}")]
26 State(String),
27}
28
29impl AgentError {
30 pub fn tool(message: impl Into<String>) -> Self {
31 AgentError::Tool(message.into())
32 }
33
34 /// True when the error originated from an abort. Used by the loop to decide
35 /// the terminal event shape (`Aborted` vs `Error`).
36 pub fn is_abort(&self) -> bool {
37 matches!(self, AgentError::Abort)
38 }
39}