autoagents_core/agent/
error.rs

1use std::fmt::Debug;
2use thiserror::Error;
3
4/// Error type for RunnableAgent operations
5#[derive(Debug, Error)]
6pub enum RunnableAgentError {
7    /// Error from the agent executor
8    #[error("Agent execution failed: {0}")]
9    ExecutorError(String),
10
11    /// Error during task processing
12    #[error("Task processing failed: {0}")]
13    TaskError(String),
14
15    /// Error when agent is not found
16    #[error("Agent not found: {0}")]
17    AgentNotFound(uuid::Uuid),
18
19    /// Error during agent initialization
20    #[error("Agent initialization failed: {0}")]
21    InitializationError(String),
22
23    /// Error when sending events
24    #[error("Failed to send event: {0}")]
25    EventSendError(String),
26
27    /// Error from agent state operations
28    #[error("Agent state error: {0}")]
29    StateError(String),
30
31    /// Generic error wrapper for any std::error::Error
32    #[error(transparent)]
33    Other(#[from] Box<dyn std::error::Error + Send + Sync>),
34}
35
36impl RunnableAgentError {
37    /// Create an executor error from any error type
38    pub fn executor_error(error: impl std::error::Error) -> Self {
39        Self::ExecutorError(error.to_string())
40    }
41
42    /// Create a task error
43    pub fn task_error(msg: impl Into<String>) -> Self {
44        Self::TaskError(msg.into())
45    }
46
47    /// Create an event send error
48    pub fn event_send_error(error: impl std::error::Error) -> Self {
49        Self::EventSendError(error.to_string())
50    }
51}
52
53/// Specific conversion for tokio mpsc send errors
54impl<T> From<tokio::sync::mpsc::error::SendError<T>> for RunnableAgentError
55where
56    T: Debug + Send + 'static,
57{
58    fn from(error: tokio::sync::mpsc::error::SendError<T>) -> Self {
59        Self::EventSendError(error.to_string())
60    }
61}
62
63#[derive(Debug, thiserror::Error)]
64pub enum AgentBuildError {
65    #[error("Build Failure")]
66    BuildFailure(String),
67}
68
69#[derive(Error, Debug)]
70pub enum AgentResultError {
71    #[error("No output available in result")]
72    NoOutput,
73
74    #[error("Failed to deserialize executor output: {0}")]
75    DeserializationError(#[from] serde_json::Error),
76
77    #[error("Agent output extraction error: {0}")]
78    AgentOutputError(String),
79}