#[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
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: booltrue 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
impl ToolResultContent
Sourcepub fn text(text: impl Into<String>) -> Self
pub fn text(text: impl Into<String>) -> Self
Build a successful text-only tool reply (is_error = false).
Sourcepub fn error(text: impl Into<String>) -> Self
pub fn error(text: impl Into<String>) -> Self
Build a failing text-only tool reply (is_error = true).
Sourcepub fn image(source: Source) -> Self
pub fn image(source: Source) -> Self
Build a successful image-only tool reply (is_error = false).
Sourcepub fn from_blocks(blocks: Vec<ToolResultBlock>) -> Self
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.
Sourcepub fn with_is_error(self, is_error: bool) -> Self
pub fn with_is_error(self, is_error: bool) -> Self
Builder-style helper: set the is_error flag.
Sourcepub fn as_text(&self) -> Option<&str>
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.
Sourcepub fn collect_text(&self) -> String
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
impl Clone for ToolResultContent
Source§fn clone(&self) -> ToolResultContent
fn clone(&self) -> ToolResultContent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ToolResultContent
impl Debug for ToolResultContent
Source§impl<'de> Deserialize<'de> for ToolResultContent
impl<'de> Deserialize<'de> for ToolResultContent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&str> for ToolResultContent
impl From<&str> for ToolResultContent
Source§impl From<String> for ToolResultContent
impl From<String> for ToolResultContent
Source§impl PartialEq for ToolResultContent
impl PartialEq for ToolResultContent
Source§fn eq(&self, other: &ToolResultContent) -> bool
fn eq(&self, other: &ToolResultContent) -> bool
self and other values to be equal, and is used by ==.