Skip to main content

runifold_agent/
error.rs

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