Skip to main content

motosan_agent_loop/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during agent loop execution.
4#[derive(Debug, Error)]
5pub enum AgentError {
6    /// The LLM backend returned an error.
7    #[error("llm error: {0}")]
8    Llm(String),
9
10    /// A tool invocation failed.
11    #[error("tool error: {0}")]
12    Tool(String),
13
14    /// Serialization / deserialization failure.
15    #[error("serde error: {0}")]
16    Serde(#[from] serde_json::Error),
17
18    /// I/O failure.
19    #[error("io error: {0}")]
20    Io(#[from] std::io::Error),
21
22    /// The loop exceeded the configured maximum iterations.
23    #[error("max iterations ({0}) exceeded")]
24    MaxIterations(usize),
25
26    /// The operation was cancelled via a [`CancellationToken`](tokio_util::sync::CancellationToken).
27    #[cfg(feature = "cancellation")]
28    #[error("cancelled")]
29    Cancelled,
30
31    /// An MCP server operation failed.
32    #[cfg(feature = "mcp-client")]
33    #[error("mcp error: {0}")]
34    Mcp(String),
35}
36
37/// Convenience alias used throughout the crate.
38pub type Result<T> = std::result::Result<T, AgentError>;