Skip to main content

ToolResult

Enum ToolResult 

Source
pub enum ToolResult {
    Success {
        text: String,
        telemetry: Option<Box<ToolTelemetry>>,
    },
    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 carries a successful textual result plus (UI Phase 1) an optional ToolTelemetry side-channel; 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

Tool executed successfully.

text is the textual result fed back to the model. telemetry (UI Phase 1) is the structured account of what the tool actually did, which the agent loop forwards to its ToolEventSink — see crate::tools::telemetry for why this rides on the result rather than each tool holding a sink. None for every tool that has nothing structured to report, which is all but the retrieval tools.

Fields

§text: String
§

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 with no telemetry.

Why: Single canonical happy-path constructor used by every tool. Tools with structured telemetry chain Self::with_telemetry onto this rather than needing a second constructor. What: Wraps s in Success with telemetry: None. Test: Trivially exercised by every successful tool execute().

Source

pub fn with_telemetry(self, telemetry: ToolTelemetry) -> Self

Attach structured telemetry to a successful result (UI Phase 1).

Why: lets a tool report what it actually did (real search lane, which memories entered context) without knowing which agent runs it or owning an event sink — see crate::tools::telemetry’s module docs. What: builder-style; a no-op on an Error result, because the event shapes this feeds describe work that produced results, and an errored tool has none to describe — its failure is already narrated by ToolFinished/ToolError. Test: tests::tool_result_carries_optional_telemetry, tests::with_telemetry_is_a_no_op_on_error.

Source

pub fn telemetry(&self) -> Option<&ToolTelemetry>

The structured telemetry this result carries, if any (UI Phase 1).

Why: the agent loop reads this after every dispatch to decide whether to emit a structured event alongside the generic tool events. What: None for errors and for any tool that reported none. Test: tests::tool_result_carries_optional_telemetry.

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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