1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum SchemaError {
5 #[error("tool schema must be a JSON object")]
6 SchemaNotObject,
7 #[error("tool schema must declare type=object")]
8 RootTypeMustBeObject,
9 #[error("required must be an array of strings")]
10 InvalidRequired,
11}
12
13#[derive(Debug, Error)]
14pub enum ToolError {
15 #[error("tool not found: {0}")]
16 NotFound(String),
17 #[error("invalid tool arguments for {tool}: {message}")]
18 InvalidArguments { tool: String, message: String },
19 #[error("dependency missing: {0}")]
20 MissingDependency(&'static str),
21 #[error("tool execution failed: {0}")]
22 Execution(String),
23 #[error(transparent)]
24 Schema(#[from] SchemaError),
25}
26
27#[derive(Debug, Error)]
28pub enum ProviderError {
29 #[error("provider request failed: {0}")]
30 Request(String),
31 #[error("provider response invalid: {0}")]
32 Response(String),
33}
34
35#[derive(Debug, Error)]
36pub enum AgentError {
37 #[error(transparent)]
38 Tool(#[from] ToolError),
39 #[error(transparent)]
40 Provider(#[from] ProviderError),
41 #[error("max iterations reached ({max_iterations})")]
42 MaxIterationsReached { max_iterations: u32 },
43 #[error("agent stream ended without final response")]
44 MissingFinalResponse,
45 #[error("agent configuration error: {0}")]
46 Config(String),
47}