Skip to main content

wasm_agent/
error.rs

1// SPDX-License-Identifier: MIT
2use thiserror::Error;
3
4/// All errors that can occur in the wasm-agent ReAct loop.
5#[derive(Debug, Error, Clone)]
6pub enum AgentError {
7    /// The agent ran the maximum number of iterations without producing a final answer.
8    #[error("Max iterations ({0}) reached without final answer")]
9    MaxIterationsExceeded(u32),
10    /// A tool was requested that does not exist in the registry.
11    #[error("Tool '{name}' not found in registry")]
12    ToolNotFound { name: String },
13    /// A tool was found but its execution failed.
14    #[error("Tool '{name}' execution failed: {reason}")]
15    ToolFailed { name: String, reason: String },
16    /// The LLM response could not be parsed as a valid ReAct step.
17    #[error("Parse error in ReAct step: {0}")]
18    ParseError(String),
19    /// The agent exceeded its wall-clock time budget.
20    #[error("Timeout: agent exceeded {timeout_ms}ms budget")]
21    Timeout { timeout_ms: u64 },
22    /// The conversation history exceeded its token budget.
23    #[error("History overflow: {size} tokens exceeds context limit {limit}")]
24    HistoryOverflow { size: usize, limit: usize },
25    /// A value could not be serialized.
26    #[error("Serialization error: {0}")]
27    Serialization(String),
28    /// A tool was registered with an invalid signature.
29    #[error("Invalid tool signature: {0}")]
30    InvalidToolSignature(String),
31}