Skip to main content

ToolResult

Enum ToolResult 

Source
pub enum ToolResult {
    Success(String),
    Error {
        message: String,
        recoverable: bool,
    },
}
Expand description

Structured result of a tool execution.

Why: Hard-failing the LLM loop on every tool error is brittle — the model often can recover (retry with different args, fall back to another tool, or explain the failure in its final answer). A structured error lets the caller surface failure back to the LLM as a tool_result with is_error: true while keeping the loop running. What: Success(String) carries a successful textual result; Error carries a message plus a recoverable flag. Test: ToolResult::err(...).is_error() is true; ok(...).content() returns the success string. Exercised in tools::registry and delegate tests.

Variants§

§

Success(String)

Tool executed successfully; inner string is the textual result.

§

Error

Tool failed; message describes why; recoverable advises the LLM loop.

Fields

§message: String
§recoverable: bool

Implementations§

Source§

impl ToolResult

Source

pub fn ok(s: impl Into<String>) -> Self

Construct a successful result.

Why: Single canonical happy-path constructor used by every tool. What: Wraps s in Success. Test: Trivially exercised by every successful tool execute().

Source

pub fn err(msg: impl Into<String>) -> Self

Construct a recoverable error.

Why: Most tool failures are non-fatal — wrong arg, transient network, empty result. The LLM should see the error and decide. What: Wraps msg with recoverable = true. Test: Exercised by delegate and registry tests.

Source

pub fn fatal(msg: impl Into<String>) -> Self

Construct a fatal (non-recoverable) error.

Why: Some failures (invariant violations, credential rejection) should not be retried; callers should bail. What: Wraps msg with recoverable = false. Test: Checked by is_fatal predicates in tests.

Source

pub fn is_error(&self) -> bool

Whether this result is an error variant.

Why: Dispatch paths need a cheap predicate to log/branch on failure. What: Returns true for any Error, false for Success. Test: ToolResult::err("x").is_error() is true.

Source

pub fn is_fatal(&self) -> bool

Whether this error is fatal (not recoverable). false for Success.

Why: Callers that distinguish fatal-vs-recoverable need this to decide whether to retry or bail. What: True only for Error { recoverable: false, .. }. Test: ToolResult::fatal("x").is_fatal() is true.

Source

pub fn content(&self) -> &str

Extract the message string for both variants.

Why: Callers like the LLM loop need the raw string regardless of success/failure to pass back as tool_result content. What: Returns the payload string for both Success and Error. Test: ToolResult::ok("hi").content() == “hi”; ToolResult::err("oops").content() == “oops”.

Trait Implementations§

Source§

impl Debug for ToolResult

Source§

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

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

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

Source§

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
Source§

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
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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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