pub struct ToolOutput { /* private fields */ }Expand description
The canonical model-visible output produced by a tool.
Every output is stored as one or more typed ToolResultContent blocks.
Ordinary serializable Rust values are converted through IntoToolOutput:
values that serialize as JSON strings become literal text blocks and all
other values become structured JSON blocks. An explicit
serde_json::Value, including a JSON string, stays JSON. Multimodal tools
opt in explicitly with Self::content. Rig never reparses text as JSON to
guess whether it represents rich content.
Implementations§
Source§impl ToolOutput
impl ToolOutput
Sourcepub fn text(text: impl Into<String>) -> ToolOutput
pub fn text(text: impl Into<String>) -> ToolOutput
Construct literal text output.
Sourcepub fn json(value: Value) -> ToolOutput
pub fn json(value: Value) -> ToolOutput
Construct structured JSON output.
Unlike an ordinary Rust string tool output, an explicit JSON string stays a JSON content block.
Sourcepub fn content(
content: Vec<ToolResultContent>,
) -> Result<ToolOutput, ToolExecutionError>
pub fn content( content: Vec<ToolResultContent>, ) -> Result<ToolOutput, ToolExecutionError>
Constructs explicit model content, rejecting an empty block list.
Use Self::text with "" to represent an empty text result.
Sourcepub fn one(content: ToolResultContent) -> ToolOutput
pub fn one(content: ToolResultContent) -> ToolOutput
Construct one explicit model-content block.
Sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
Return literal text when this output is exactly one plain text block.
Sourcepub fn as_json(&self) -> Option<&Value>
pub fn as_json(&self) -> Option<&Value>
Return structured JSON when this output is exactly one JSON block.
Sourcepub fn as_content(&self) -> &[ToolResultContent]
pub fn as_content(&self) -> &[ToolResultContent]
Borrow the canonical ordered content blocks.
Sourcepub fn into_content(self) -> Vec<ToolResultContent>
pub fn into_content(self) -> Vec<ToolResultContent>
Convert this output into the canonical message content sent to a model.
Trait Implementations§
Source§impl Clone for ToolOutput
impl Clone for ToolOutput
Source§fn clone(&self) -> ToolOutput
fn clone(&self) -> ToolOutput
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more