Skip to main content

temporal_agent_rs/
error.rs

1//! Error types raised by activities and the agent loop.
2
3use thiserror::Error;
4
5/// Errors surfaced by Temporal activities and the agent loop.
6///
7/// Variants split along two axes: where the error originated (LLM, tool
8/// registry, parser, serde) and whether it should be retried by Temporal
9/// — see [`AgentError::is_retryable`].
10#[derive(Error, Debug)]
11pub enum AgentError {
12    /// Upstream LLM provider error (network, rate limit, auth, etc.).
13    #[error("LLM provider error: {0}")]
14    Llm(String),
15
16    /// LLM returned a tool call that the worker hasn't registered.
17    #[error("tool '{0}' not registered with this worker")]
18    ToolNotFound(String),
19
20    /// LLM response couldn't be parsed into a [`crate::state::LlmResponse`].
21    #[error("could not parse LLM response: {0}")]
22    ResponseParse(String),
23
24    /// JSON ser/de failure crossing the activity boundary.
25    #[error("serde error: {0}")]
26    Serde(#[from] serde_json::Error),
27
28    /// Catch-all for activity-side failures we don't otherwise classify.
29    #[error("{0}")]
30    Other(String),
31}
32
33impl AgentError {
34    /// Returns `true` when the error is worth a Temporal retry.
35    ///
36    /// Network blips, rate limits, and transient provider hiccups are
37    /// retryable; missing tool registrations and parse failures are not —
38    /// they indicate a code bug, not a transient condition.
39    pub fn is_retryable(&self) -> bool {
40        matches!(self, AgentError::Llm(_) | AgentError::Other(_))
41    }
42}