Skip to main content

runifold_agent/
error.rs

1use runifold_core::{BudgetExceeded, CheckpointError, JournalError};
2use runifold_effect::EffectExecutorError;
3use runifold_model::ModelError;
4use runifold_retrieval::RetrievalError;
5use runifold_tool::ToolError;
6use thiserror::Error;
7
8use crate::GatewayError;
9
10/// Failure of an agent run.
11#[derive(Debug, Error)]
12#[non_exhaustive]
13pub enum AgentError {
14    /// Model invocation failed.
15    #[error("model invocation failed: {0}")]
16    Model(#[from] ModelError),
17    /// Tool execution failed.
18    #[error("tool execution failed: {0}")]
19    Tool(#[from] ToolError),
20    /// Static or dynamic context retrieval failed.
21    #[error("agent retrieval failed: {0}")]
22    Retrieval(#[from] RetrievalError),
23    /// A shared run-tree budget was exceeded.
24    #[error("agent budget exceeded: {0}")]
25    Budget(#[from] BudgetExceeded),
26    /// Agent delegation failed.
27    #[error("agent delegation failed: {0}")]
28    Gateway(#[from] GatewayError),
29    /// Structured event recording failed.
30    #[error("agent observability failed: {0}")]
31    Journal(#[from] JournalError),
32    /// Checkpoint persistence or validation failed.
33    #[error("agent checkpoint failed: {0}")]
34    Checkpoint(#[from] CheckpointError),
35    /// Write-ahead effect coordination failed.
36    #[error("agent effect failed: {0}")]
37    Effect(#[from] EffectExecutorError),
38    /// Recovery would silently retry a possibly partial external turn.
39    #[error("checkpoint contains an ambiguous in-flight turn {turn}")]
40    AmbiguousCheckpoint {
41        /// One-based interrupted turn number.
42        turn: u32,
43    },
44    /// Agent configuration is invalid.
45    #[error("invalid agent configuration: {0}")]
46    InvalidConfig(String),
47    /// Model output violated the agent-loop protocol.
48    #[error("agent protocol error: {0}")]
49    Protocol(String),
50    /// The configured local turn bound was reached.
51    #[error("agent exceeded its local maximum of {max_turns} turns")]
52    MaxTurns {
53        /// Configured local turn bound.
54        max_turns: u32,
55    },
56    /// A tool produced output that policy forbids exposing to the model.
57    #[error("tool `{tool}` returned host-only output")]
58    ToolOutputNotVisible {
59        /// Tool name.
60        tool: String,
61    },
62}