Skip to main content

ToolResultContent

Struct ToolResultContent 

Source
#[non_exhaustive]
pub struct ToolResultContent { pub blocks: Vec<ToolResultBlock>, pub is_error: bool, }
Expand description

Body of a tool reply sent back to the model in a UserBlock::ToolResult.

The body is a list of ToolResultBlocks (text, image, …) plus an is_error flag. The flag is the wire-level error signal — Anthropic emits it as tool_result.is_error; Chat Completions has no field for it and treats the body as the error message.

is_error is not a Rust Result::Err — both forms represent successful tool calls whose outcome the engine relays to the model. is_error = true flags the reply as a failure the model should account for (e.g. “the API returned 404”). Engine-level errors (panic in the handler, arguments that don’t deserialize, registry lookup miss) are converted to a synthesized error reply so the loop can continue; transport errors propagate through Result channels instead.

Most callers build replies through the Self::text / Self::error constructors; multi-block replies use Self::from_blocks.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§blocks: Vec<ToolResultBlock>

Content blocks in order. A “normal” text reply has a single ToolResultBlock::Text here.

§is_error: bool

true flags the reply as a tool-reported failure (Anthropic is_error: true). Adapters that don’t speak the flag on the wire just emit the text body.

Implementations§

Source§

impl ToolResultContent

Source

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

Build a successful text-only tool reply (is_error = false).

Source

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

Build a failing text-only tool reply (is_error = true).

Source

pub fn image(source: Source) -> Self

Build a successful image-only tool reply (is_error = false).

Source

pub fn from_blocks(blocks: Vec<ToolResultBlock>) -> Self

Build a reply from arbitrary blocks. Defaults is_error: false; chain Self::with_is_error to flag failure.

Source

pub fn with_is_error(self, is_error: bool) -> Self

Builder-style helper: set the is_error flag.

Source

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

First ToolResultBlock::Text body, if any. Useful when the caller only cares about the text portion of a reply.

Source

pub fn collect_text(&self) -> String

Concatenate every ToolResultBlock::Text body in order, joined by newlines. Returns an empty string when there are no text blocks (the reply was image-only).

Trait Implementations§

Source§

impl Clone for ToolResultContent

Source§

fn clone(&self) -> ToolResultContent

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 ToolResultContent

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ToolResultContent

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 From<&str> for ToolResultContent

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for ToolResultContent

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ToolResultContent

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ToolResultContent

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 ToolResultContent

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