pub struct ToolResult {
pub success: bool,
pub output: String,
pub data: Option<Value>,
pub documents: Vec<ContentSource>,
pub duration_ms: Option<u64>,
}Expand description
Result of a tool execution
Fields§
§success: boolWhether the tool execution succeeded
output: StringOutput content (displayed to user and fed back to LLM)
data: Option<Value>Optional structured data
documents: Vec<ContentSource>Optional documents (PDFs, images) to pass back to the LLM as native content blocks.
The agent appends these as ContentBlock::Document / ContentBlock::Image blocks
in the same user message as the tool result, so the model can read them directly.
duration_ms: Option<u64>Duration of the tool execution in milliseconds
Implementations§
Source§impl ToolResult
impl ToolResult
pub fn success(output: impl Into<String>) -> Self
pub fn success_with_data(output: impl Into<String>, data: Value) -> Self
pub fn error(message: impl Into<String>) -> Self
pub const fn with_duration(self, duration_ms: u64) -> Self
Sourcepub fn with_documents(self, documents: Vec<ContentSource>) -> Self
pub fn with_documents(self, documents: Vec<ContentSource>) -> Self
Attach documents (PDFs, images) to be sent back to the LLM as native content blocks.
Use this when a tool produces a binary document that the model should read directly, e.g. a decrypted PDF that Anthropic can parse natively via its document API.
§Example
ⓘ
use agent_sdk::{ToolResult, ContentSource};
Ok(ToolResult::success("PDF decrypted.").with_documents(vec![
ContentSource::new("application/pdf", base64_data),
]))Trait Implementations§
Source§impl Clone for ToolResult
impl Clone for ToolResult
Source§fn clone(&self) -> ToolResult
fn clone(&self) -> ToolResult
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ToolResult
impl Debug for ToolResult
Source§impl<'de> Deserialize<'de> for ToolResult
impl<'de> Deserialize<'de> for ToolResult
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>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more