pub enum ToolResult {
Done,
Text {
text: String,
},
Tsv {
text: String,
},
Json {
value: Value,
},
Binary {
mime: String,
content: Vec<u8>,
},
Error {
message: String,
},
Parts {
parts: Vec<ToolResultPart>,
},
}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.
Tsv
Tab-separated tabular output.
Json
Structured JSON output.
Binary
Binary or media payload.
Fields
Error
Tool-level error. This is distinct from transport/runtime failures.
Parts
Several content items produced by one tool call.
A single call can legitimately yield more than one payload — for
example a relayed MCP tool result that pairs explanatory text with a
screenshot. Parts never nest and never carry errors: tool-level
failures stay on ToolResult::Error.
Fields
parts: Vec<ToolResultPart>Ordered content items.
Implementations§
Source§impl ToolResult
impl ToolResult
Sourcepub const fn json_value(value: Value) -> Self
pub const fn json_value(value: Value) -> Self
Creates a JSON result from an already-materialized JSON value.
Sourcepub fn parts(parts: Vec<ToolResultPart>) -> Self
pub fn parts(parts: Vec<ToolResultPart>) -> Self
Creates a multi-part result.
An empty part list collapses to ToolResult::Done and a single part
collapses to the matching single-payload variant, so callers that
conditionally accumulate parts never produce a degenerate Parts.
Sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
Returns plain textual content when every payload this result carries is text-like.
Sourcepub fn error_message(&self) -> Option<&str>
pub fn error_message(&self) -> Option<&str>
Returns the error message if this is a typed tool error.
Sourcepub fn render_for_model(&self) -> Result<String>
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.
Sourcepub fn render_for_cli(&self) -> Result<String>
pub fn render_for_cli(&self) -> Result<String>
Sourcepub fn mime(&self) -> Option<Mime>
pub fn mime(&self) -> Option<Mime>
Parses and returns the MIME type when this result carries binary content.
A multi-part result yields a MIME type only when it holds exactly one binary part; mixed content has no single type to report.
Sourcepub fn content(&self) -> Option<&[u8]>
pub fn content(&self) -> Option<&[u8]>
Returns raw bytes when this result carries binary content.
Follows the same single-binary rule as Self::mime.
Trait Implementations§
Source§impl Clone for ToolResult
impl Clone for ToolResult
Source§fn clone(&self) -> ToolResult
fn clone(&self) -> ToolResult
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 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>,
impl Eq for ToolResult
Source§impl IntoToolResult for ToolResult
impl IntoToolResult for ToolResult
Source§fn into_tool_result(self) -> Result<ToolResult>
fn into_tool_result(self) -> Result<ToolResult>
ToolResult. Read more