potato_agent/agents/
error.rs1use potato_prompt::PromptError;
2use pyo3::exceptions::PyRuntimeError;
3use pyo3::PyErr;
4use reqwest::StatusCode;
5use thiserror::Error;
6use tracing::error;
7
8#[derive(Error, Debug)]
9pub enum AgentError {
10 #[error("Error: {0}")]
11 Error(String),
12
13 #[error("Failed to create header value for the agent client")]
14 CreateHeaderValueError(#[from] reqwest::header::InvalidHeaderValue),
15
16 #[error("Failed to create header name for the agent client")]
17 CreateHeaderNameError(#[from] reqwest::header::InvalidHeaderName),
18
19 #[error("Failed to create agent client: {0}")]
20 CreateClientError(#[source] reqwest::Error),
21
22 #[error("Request failed: {0}")]
23 RequestError(#[from] reqwest::Error),
24
25 #[error("Failed to serialize chat request: {0}")]
26 SerializationError(#[from] serde_json::Error),
27
28 #[error("Failed to get chat completion response: {0} with status code {1}")]
29 ChatCompletionError(String, StatusCode),
30
31 #[error("Failed to downcast Python object: {0}")]
32 DowncastError(String),
33
34 #[error("Failed to get environment variable: {0}")]
35 EnvVarError(#[from] std::env::VarError),
36
37 #[error("Failed to retrieve GEMINI_API_KEY from the environment")]
38 MissingGeminiApiKeyError,
39
40 #[error("Failed to retrieve OPENAI_API_KEY from the environment")]
41 MissingOpenAIApiKeyError,
42
43 #[error("Failed to extract client: {0}")]
44 ClientExtractionError(String),
45
46 #[error("Client did not provide response")]
47 ClientNoResponseError,
48
49 #[error("No ready tasks found but pending tasks remain. Possible circular dependency.")]
50 NoTaskFoundError,
51
52 #[error("Unsupported content type")]
53 UnsupportedContentTypeError,
54
55 #[error("Failed to create runtime: {0}")]
56 CreateRuntimeError(#[source] std::io::Error),
57
58 #[error(transparent)]
59 PromptError(#[from] PromptError),
60
61 #[error(transparent)]
62 UtilError(#[from] potato_util::UtilError),
63
64 #[error(transparent)]
65 TypeError(#[from] potato_type::error::TypeError),
66
67 #[error("Invalid output type: {0}")]
68 InvalidOutputType(String),
69
70 #[error("Failed to create tokio runtime: {0}")]
71 RuntimeError(String),
72
73 #[error("Undefined error: {0}")]
74 UndefinedError(String),
75
76 #[error("Failed to create tool: {0}")]
77 ToolCreationError(String),
78
79 #[error("Invalid tool definition")]
80 InvalidToolDefinitionError,
81
82 #[error("{0}")]
83 InvalidInput(String),
84
85 #[error("Provider mismatch: prompt provider {0}, agent provider {1}")]
86 ProviderMismatch(String, String),
87}
88
89impl<'a> From<pyo3::DowncastError<'a, 'a>> for AgentError {
90 fn from(err: pyo3::DowncastError) -> Self {
91 AgentError::DowncastError(err.to_string())
92 }
93}
94
95impl From<AgentError> for PyErr {
96 fn from(err: AgentError) -> PyErr {
97 let msg = err.to_string();
98 error!("{}", msg);
99 PyRuntimeError::new_err(msg)
100 }
101}
102
103impl From<PyErr> for AgentError {
104 fn from(err: PyErr) -> Self {
105 AgentError::Error(err.to_string())
106 }
107}