Skip to main content

ToolError

Enum ToolError 

#[non_exhaustive]
pub enum ToolError { Transient(String), Retryable { message: String, class: ErrorClass, }, Permanent(String), NeedsInput { question: String, ui: Option<Value>, }, AwaitRun { run: RunId, }, AwaitRemote { task: String, timeout_ms: Option<u64>, }, AwaitSession { session: RunId, }, }
Expand description

Why a tool call did not produce an output.

Journaled, hence serializable: the strings are the record and the serde shape is frozen, so old journals stay replayable. That is why it carries no source: a tool flattens its own cause into the message (with [adam_error::report]) before returning it.

Classes: Transient is [ErrorClass::Transient], Retryable is its own class (RateLimited or Conflict), Permanent is [ErrorClass::Invalid] (the model asked for something that cannot work, and is told so), and NeedsInput, AwaitRun and AwaitRemote are [ErrorClass::Rejected] (valid, but they need the user, a child run, or a remote task, first).

The enum only grows: a variant added later decodes in journals written before it existed (they never contain it), and a journal that contains a new variant is not readable by a build that predates it, so the tool that returns AwaitRun or AwaitRemote ships with the build that understands it.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Transient(String)

Worth retrying (a timeout, a busy backend). The run’s step fails with AgentError::Transient and the runtime retries it with backoff.

§

Retryable

Worth retrying, of a retryable class that is not Transient: a rate limit, a lost race (ADR 0061). The run’s step fails with an AgentError::Transient of that class, which a policy that names its classes may retry or not. from_classified and retryable build it; a class this build does not know reads as transient. A build older than the one that wrote it cannot read the journal entry: roll a deployment forward, not back.

Fields

§message: String

What happened.

§class: ErrorClass

Its retryable class, written by name (rate-limited, conflict).

§

Permanent(String)

Not worth retrying. The run continues: the message becomes an error tool result for the model.

§

NeedsInput

The tool cannot go on without an answer from the user. The agent emits the question and parks; the next inbound message becomes this call’s result.

Fields

§question: String

What to ask the user.

§ui: Option<Value>

An interface the question comes with: an array of A2UI messages (a surface with the choices to draw), which the A2A server sends beside the question in the input-required status. None for a question that is only text. The agent does not read it: it keeps it with the question (PendingQuestion::ui) and whoever serves the run draws it. Absent from journals written before it existed, which decode as None, and not written while it is None.

§

AwaitRun

The answer is the result of a child run this tool started (or found: see below). The agent parks with a timer, and the child’s outcome becomes this call’s result, as text, or as an error result when the child failed.

The tool starts the child with Runtime::start_child, under an id it derives from the call (ToolCtx::child_run_id), so that running the tool again, after a crash or a retry, finds the child it already started. The error is journaled like any other result, and the tool is not called again for this call: the wait is settled from the run’s state.

Fields

§run: RunId

The child run whose outcome is the result.

§

AwaitRemote

The answer is the outcome of a task the tool started on another system (an A2A agent, a job queue). The agent parks with a timer (LlmAgentBuilder::wait_poll) and, each time it fires, asks the tool how the task stands with Tool::poll_remote, as a journaled step. The tool’s answer becomes this call’s result.

The tool starts the task in the same journaled step that returns this error, and must make the start idempotent, keyed by the call (ToolCtx::call_id, ToolCtx::child_run_id), so that a step which ran but was not recorded does not start a second task. The error is journaled, and the tool is not called again for this call.

Fields

§task: String

The tool’s own name for the task, handed back to Tool::poll_remote. It is stored in the run’s state and visible to whoever can read it: put no secret in it.

§timeout_ms: Option<u64>

Give up after this many milliseconds of waiting: the call is answered with an error result and the task is left where it is. None: wait for ever.

§

AwaitSession

The answer is the report of the round a child session is working on (ADR 0045). The agent parks with a timer, records a PendingWait::Session, and each time it wakes (the round’s end wakes it, the timer is the fallback) asks the tool how the session stands with Tool::poll_remote, the session id as the task, in a journaled step, until the tool answers RemotePoll::Ready with the report.

Fields

§session: RunId

The session whose round is awaited: the run id of its first round.

Implementations§

§

impl ToolError

pub fn needs_input(question: impl Into<String>) -> ToolError

A question for the user that is only text: ToolError::NeedsInput with no interface.

pub fn needs_input_with_ui(question: impl Into<String>, ui: Value) -> ToolError

A question for the user that comes with an interface (ui, an array of A2UI messages): ToolError::NeedsInput.

pub fn retryable(message: impl Into<String>, class: ErrorClass) -> ToolError

A failure of class with message: Transient for Transient, Retryable for another retryable class (RateLimited, Conflict), and Permanent for a class that is not retryable.

pub fn retry_parts(&self) -> Option<(&str, ErrorClass)>

The message and the class of a failure worth retrying (Transient or Retryable); None for any other.

pub fn from_classified<E>(err: &E) -> ToolError
where E: Classify + 'static,

Turn a classified error into a tool error: a retryable one ([ErrorClass::is_retryable]) becomes Transient, or Retryable with its class when that is not Transient, anything else Permanent. The message is the error and its whole source chain ([adam_error::report]), because a ToolError is journaled as text.

use adam_error::{Classify, ErrorClass};
use adam_llm_agent::ToolError;

#[derive(Debug, thiserror::Error)]
#[error("backend busy")]
struct Busy;
impl Classify for Busy {
    fn class(&self) -> ErrorClass {
        ErrorClass::Transient
    }
}

assert_eq!(ToolError::from_classified(&Busy), ToolError::Transient("backend busy".into()));

Trait Implementations§

§

impl Classify for ToolError

§

fn class(&self) -> ErrorClass

What to do about this error.
§

fn retry_after(&self) -> Option<Duration>

How long to wait before retrying, when the peer said so.
§

fn is_retryable(&self) -> bool

Derived from class; never hand-written.
§

impl Clone for ToolError

§

fn clone(&self) -> ToolError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for ToolError

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for ToolError

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ToolError, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for ToolError

§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Error for ToolError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
§

impl PartialEq for ToolError

§

fn eq(&self, other: &ToolError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for ToolError

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl StructuralPartialEq for ToolError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more