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)]
6#[non_exhaustive]
7pub enum AgentError {
8 /// The agent ran the maximum number of iterations without producing a final answer.
9 #[error("Max iterations ({0}) reached without final answer")]
10 MaxIterationsExceeded(u32),
11 /// A tool was requested that does not exist in the registry.
12 #[error("Tool '{name}' not found in registry")]
13 ToolNotFound {
14 /// Tool name.
15 name: String,
16 },
17 /// A tool was found but its execution failed.
18 #[error("Tool '{name}' execution failed: {reason}")]
19 ToolFailed {
20 /// Tool name.
21 name: String,
22 /// What went wrong.
23 reason: String,
24 },
25 /// The LLM response could not be parsed as a valid ReAct step.
26 #[error("Parse error in ReAct step: {0}")]
27 ParseError(String),
28 /// The agent exceeded its wall-clock time budget.
29 #[error("Timeout: agent exceeded {timeout_ms}ms budget")]
30 Timeout {
31 /// The time budget in milliseconds.
32 timeout_ms: u64,
33 },
34 /// The conversation history exceeded its token budget.
35 #[error("History overflow: {size} tokens exceeds context limit {limit}")]
36 HistoryOverflow {
37 /// Tokens the history would have had.
38 size: usize,
39 /// The token limit.
40 limit: usize,
41 },
42 /// A value could not be serialized.
43 #[error("Serialization error: {0}")]
44 Serialization(String),
45 /// A tool was registered with an invalid signature.
46 #[error("Invalid tool signature: {0}")]
47 InvalidToolSignature(String),
48}