Skip to main content

aidaemon_core/
error.rs

1use crate::safeguard::Safeguard;
2use crate::store::StoreError;
3
4/// Misconfiguration caught when building an agent.
5#[derive(Debug, Clone, PartialEq, thiserror::Error)]
6#[non_exhaustive]
7pub enum BuildError {
8    #[error("agent id must not be empty")]
9    EmptyAgentId,
10    #[error("no provider configured")]
11    MissingProvider,
12    /// No [`crate::AgentBuilder::model`], and the provider has no
13    /// [`crate::Provider::default_model`].
14    #[error("no model configured: call `.model(..)` (the provider names no default model)")]
15    MissingModel,
16    #[error("duplicate tool name `{0}`")]
17    DuplicateTool(String),
18    #[error("invalid tool name `{0}`: use 1-64 characters from [a-zA-Z0-9_-]")]
19    InvalidToolName(String),
20    #[error(
21        "agent has tools but no hook enforces or attestation covers the {0} safeguard; \
22         add the policy hook, `attest` it, or `allow_unguarded`"
23    )]
24    MissingSafeguard(Safeguard),
25}
26
27/// Errors from `run`/`resume` itself. Things that happen *inside* a run
28/// (tool failures, provider outages, limits) are reported through
29/// [`crate::RunStatus`], not here.
30#[derive(Debug, thiserror::Error)]
31#[non_exhaustive]
32pub enum CoreError {
33    #[error("state belongs to agent `{found}`, not `{expected}`")]
34    AgentMismatch { expected: String, found: String },
35    #[error("nothing to resume: the run is not interrupted")]
36    NotInterrupted,
37    #[error("the run is interrupted; settle it with `Agent::resume` first")]
38    PendingInterruption,
39    #[error("saved run state has schema {found}; this kernel resumes up to {supported}")]
40    UnsupportedRunState { found: u32, supported: u32 },
41    /// The approval in this state was already used: an answer runs its
42    /// call once, however many copies of the state are resumed.
43    #[error("this approval was already used; the call it approved does not run again")]
44    ApprovalAlreadyUsed,
45    #[error(transparent)]
46    Store(#[from] StoreError),
47}