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
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
class: ErrorClassIts 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
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: RunIdThe 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: StringThe 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.
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: RunIdThe session whose round is awaited: the run id of its first round.
Implementations§
§impl ToolError
impl ToolError
pub fn needs_input(question: impl Into<String>) -> 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
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 retry_parts(&self) -> Option<(&str, ErrorClass)>
pub fn retry_parts(&self) -> Option<(&str, ErrorClass)>
pub fn from_classified<E>(err: &E) -> ToolErrorwhere
E: Classify + 'static,
pub fn from_classified<E>(err: &E) -> ToolErrorwhere
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
impl Classify for ToolError
§fn retry_after(&self) -> Option<Duration>
fn retry_after(&self) -> Option<Duration>
§fn is_retryable(&self) -> bool
fn is_retryable(&self) -> bool
class; never hand-written.§impl<'de> Deserialize<'de> for ToolError
impl<'de> Deserialize<'de> for ToolError
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ToolError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ToolError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Error for ToolError
impl Error for ToolError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
§impl Serialize for ToolError
impl Serialize for ToolError
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for ToolError
Auto Trait Implementations§
impl Freeze for ToolError
impl RefUnwindSafe for ToolError
impl Send for ToolError
impl Sync for ToolError
impl Unpin for ToolError
impl UnsafeUnpin for ToolError
impl UnwindSafe for ToolError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].