Skip to main content

ToolResult

Enum ToolResult 

Source
pub enum ToolResult {
    Done,
    Text {
        text: String,
    },
    Tsv {
        text: String,
    },
    Json {
        value: Value,
    },
    Binary {
        mime: String,
        content: Vec<u8>,
    },
    Error {
        message: String,
    },
}
Expand description

Final structured result from a tool execution.

This keeps successful content and tool-level failures in distinct variants so UIs and runtimes do not need to infer errors from free-form strings.

§Example

use aither::llm::tool::ToolResult;

fn search_tool() -> ToolResult {
    ToolResult::text("Found 3 results...")
}

fn delete_tool() -> ToolResult {
    ToolResult::Done
}

Variants§

§

Done

Tool completed with no output to return.

§

Text

UTF-8 plain text output.

Fields

§text: String

Plain text content.

§

Tsv

Tab-separated tabular output.

Fields

§text: String

TSV content.

§

Json

Structured JSON output.

Fields

§value: Value

JSON content.

§

Binary

Binary or media payload.

Fields

§mime: String

MIME type of the payload (for example image/png).

§content: Vec<u8>

Raw content bytes.

§

Error

Tool-level error. This is distinct from transport/runtime failures.

Fields

§message: String

Tool-level error message.

Implementations§

Source§

impl ToolResult

Source

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

Creates a plain text result.

Source

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

Creates a TSV result.

Source

pub fn json<T: Serialize>(value: &T) -> Result<Self>

Creates a JSON result from a serializable value.

§Errors

Returns an error if serialization fails.

Source

pub const fn json_value(value: Value) -> Self

Creates a JSON result from an already-materialized JSON value.

Source

pub fn image(data: Vec<u8>, media_type: &str) -> Self

Creates an image result.

Source

pub fn binary(data: Vec<u8>) -> Self

Creates a binary result.

Source

pub fn error(message: impl Into<String>) -> Self

Creates a typed tool error result.

Source

pub const fn is_done(&self) -> bool

Returns true if this is a Done variant.

Source

pub const fn is_error(&self) -> bool

Returns true if this is a typed tool error.

Source

pub fn as_text(&self) -> Option<&str>

Returns plain textual content for text-like variants.

Source

pub fn error_message(&self) -> Option<&str>

Returns the error message if this is a typed tool error.

Source

pub fn render_for_model(&self) -> Result<String>

Projects the result into a textual representation safe to re-inject into model context.

§Errors

Returns an error if JSON serialization fails.

Source

pub fn render_for_cli(&self) -> Result<String>

Renders the result for CLI display.

§Errors

Returns an error if JSON serialization fails.

Source

pub fn mime(&self) -> Option<Mime>

Parses and returns the MIME type when this result carries binary content.

Source

pub fn content(&self) -> Option<&[u8]>

Returns raw bytes for binary results.

Trait Implementations§

Source§

impl Clone for ToolResult

Source§

fn clone(&self) -> ToolResult

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

impl<'de> Deserialize<'de> for ToolResult

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ToolResult

Source§

impl IntoToolResult for ToolResult

Source§

fn into_tool_result(self) -> Result<ToolResult>

Converts the value into a final ToolResult. Read more
Source§

impl PartialEq for ToolResult

Source§

fn eq(&self, other: &ToolResult) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ToolResult

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ToolResult

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.