1use troupekit_agent::{AgentError, PersonaError};
2use troupekit_core::error::CoreError;
3use troupekit_core::event::PauseReason;
4use troupekit_core::ids::RunId;
5use troupekit_graph::{GraphError, WorkflowError};
6use troupekit_providers::CatalogError;
7use troupekit_tools::ToolError;
8
9#[derive(Debug, thiserror::Error)]
13#[non_exhaustive]
14pub enum KitError {
15 #[error("agent `{agent}`: {message}")]
16 Config { agent: String, message: String },
17 #[error("vendor `{vendor}` needs an API key: set {env} or call .api_key(..)")]
18 MissingKey { vendor: String, env: String },
19 #[error("agent `{agent}`: {source}; {hint}")]
20 Catalog {
21 agent: String,
22 source: CatalogError,
23 hint: String,
24 },
25 #[error(transparent)]
26 Persona(#[from] PersonaError),
27 #[error(transparent)]
28 Agent(#[from] AgentError),
29 #[error(transparent)]
30 Tool(#[from] ToolError),
31 #[error(transparent)]
32 Workflow(#[from] WorkflowError),
33 #[error(transparent)]
34 Graph(#[from] GraphError),
35 #[error(transparent)]
36 Store(#[from] CoreError),
37 #[cfg(feature = "knowledge")]
38 #[error(transparent)]
39 Context(#[from] troupekit_context::ContextError),
40 #[error(transparent)]
41 Route(troupekit_providers::route::RouteError),
42 #[cfg(feature = "local")]
43 #[error(transparent)]
44 Local(#[from] troupekit_local::LocalError),
45 #[error("run {run_id} failed: {reason}")]
46 Failed { run_id: RunId, reason: String },
47 #[error("run {run_id} paused: {reason:?}")]
48 Paused { run_id: RunId, reason: PauseReason },
49 #[error("run {run_id}: gave up after {attempts} retries: {last_error}")]
50 Retries {
51 run_id: RunId,
52 attempts: u32,
53 last_error: String,
54 },
55}
56
57impl KitError {
58 pub(crate) fn config(agent: &str, message: impl Into<String>) -> Self {
59 KitError::Config {
60 agent: agent.to_string(),
61 message: message.into(),
62 }
63 }
64
65 pub(crate) fn run_id(&self) -> Option<RunId> {
66 match self {
67 KitError::Failed { run_id, .. }
68 | KitError::Paused { run_id, .. }
69 | KitError::Retries { run_id, .. } => Some(*run_id),
70 _ => None,
71 }
72 }
73}