Skip to main content

ToolResult

Enum ToolResult 

Source
pub enum ToolResult {
    Success {
        tool_call_id: String,
        output: String,
        sources: Vec<Source>,
        diffs: Vec<FileDiff>,
        working_dir: Option<PathBuf>,
    },
    Failure {
        tool_call_id: String,
        output: String,
    },
    Interrupt {
        tool_call_id: String,
        payload: Arc<dyn InterruptPayload>,
    },
}
Expand description

Result of a tool execution, returned by Tool::execute and fed back to the LLM as a "role": "tool" message.

Three variants cover the full lifecycle of a tool call:

  • Success — The tool ran without error. The output field contains the text payload sent back to the model. Optional sources (URLs the agent can cite) and diffs (unified diffs for file-mutating tools) may be attached.
  • Failure — The tool encountered an error (invalid arguments, I/O failure, etc.). The output field carries a human- and LLM-readable error description. Unlike Success, no sources or diffs are included.
  • Interrupt — The tool needs user interaction before continuing (e.g. plan approval, choice picker). The agent loop should halt and surface the output (structured as JSON) to the caller for handling.

§Construction helpers

Prefer the associated constructors on the impl block rather than building variants directly:

ⓘ
use flashmind_types::tool::ToolResult;

// Basic success
ToolResult::success(call_id, "file written")

// Failure with error message
ToolResult::failure(call_id, "permission denied")

// Success with file diffs attached
ToolResult::success_with_diffs(call_id, "replaced", vec![diff])

// Interrupt for interactive prompt
ToolResult::interrupt(call_id, Arc::new(MyPayload { ... }))

// Chain .with_sources() onto any Success
ToolResult::success(call_id, results).with_sources(srcs)

§Relation to message::ToolResult

This type lives in the tool module and represents the raw outcome of executing a tool. It is converted into a Message with role: "tool" (via AgentEvent::ToolResult) before being appended to the conversation history sent to the LLM.

Variants§

§

Success

Tool executed successfully.

Fields

§tool_call_id: String
§output: String
§sources: Vec<Source>
§diffs: Vec<FileDiff>
§working_dir: Option<PathBuf>

New agent working directory after a successful workspace switch.

§

Failure

Tool execution failed.

Fields

§tool_call_id: String
§output: String
§

Interrupt

The agent loop should stop and return this result to the caller for interactive handling. The typed payload is downcast by the caller to determine the interrupt kind.

Fields

§tool_call_id: String
§payload: Arc<dyn InterruptPayload>

Implementations§

Source§

impl ToolResult

Source

pub fn success(tool_call_id: &str, output: impl Into<String>) -> Self

Create a basic success result with no sources or diffs.

Source

pub fn failure(tool_call_id: &str, output: impl Into<String>) -> Self

Create a failure result with an error message.

Source

pub fn success_with_diffs( tool_call_id: &str, output: impl Into<String>, diffs: Vec<FileDiff>, ) -> Self

Create a success result that includes file diffs for tools that mutate content (file write, text replace, etc.).

Source

pub fn interrupt(tool_call_id: &str, payload: Arc<dyn InterruptPayload>) -> Self

Create an interrupt result that pauses the agent loop for interactive user handling (command approval, OAuth, etc.).

NOTE: the agent turn ends without a tool result in the conversation, leaving a dangling tool call. Callers must add a ConversationEntry::tool with the same tool_call_id after handling the interrupt.

Source

pub fn with_sources(self, sources: Vec<Source>) -> Self

Attach source URLs to a Success result. Returns self unchanged if the variant is not Success.

This is designed for method chaining:

ⓘ
ToolResult::success(id, "results").with_sources(srcs)
Source

pub fn with_working_dir(self, path: PathBuf) -> Self

Change this agent’s working directory after the call succeeds. Tools returning this effect must set concurrent() to false.

Source

pub fn working_dir(&self) -> Option<&Path>

Working directory selected by a successful tool call.

Source

pub fn tool_call_id(&self) -> &str

Return the tool call ID echoed from the original invocation.

Source

pub fn output(&self) -> String

Return the text output payload (success result, error message, or interrupt display string).

Source

pub fn payload(&self) -> Option<&Arc<dyn InterruptPayload>>

Return the typed interrupt payload, if this is an Interrupt variant.

Source

pub fn is_success(&self) -> bool

Check whether this result represents a successful execution.

Source

pub fn is_interrupt(&self) -> bool

Check whether this result is an interrupt requiring user interaction.

Source

pub fn sources(&self) -> &[Source]

Return the attached source references, or an empty slice for non-success variants.

Source

pub fn diffs(&self) -> &[FileDiff]

Return the attached file diffs, or an empty slice for non-success variants.

Source

pub fn truncate_output(&mut self, max_bytes: usize, max_lines: usize)

Truncate output to fit within byte and line limits. Appends \n[truncated] when the output was cut.

Trait Implementations§

Source§

impl Clone for ToolResult

Source§

fn clone(&self) -> Self

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
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> 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> 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> 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, 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