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.
Implementations§
Source§impl ToolResult
impl ToolResult
Sourcepub fn ok(s: impl Into<String>) -> Self
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().
Sourcepub fn err(msg: impl Into<String>) -> Self
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.
Sourcepub fn fatal(msg: impl Into<String>) -> Self
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.
Sourcepub fn is_error(&self) -> bool
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.
Sourcepub fn is_fatal(&self) -> bool
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.
Sourcepub fn content(&self) -> &str
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§
Auto Trait Implementations§
impl Freeze for ToolResult
impl RefUnwindSafe for ToolResult
impl Send for ToolResult
impl Sync for ToolResult
impl Unpin for ToolResult
impl UnsafeUnpin for ToolResult
impl UnwindSafe for ToolResult
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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