#[non_exhaustive]pub struct ToolOutput {
pub parts: Vec<Part>,
}Expand description
What a tool sends back to the model: text and media (for example a generated image), in order.
Text converts into it, so a tool that only returns text can keep returning a String.
The model gets the text in the tool result and the media in a user message right after the
tool results, for every provider for now. A later release puts the media in the tool result
itself for the providers that accept it (Anthropic, Gemini, OpenAI Responses, Bedrock and
Ollama).
There is no structured (JSON) output: a tool that produces data converts it to text itself,
for example with serde_json::to_string, in the format it wants the model to read.
let png = [0x89, b'P', b'N', b'G'];
let output = ToolOutput::from_text("Here is the chart")
.with_media(Media::from_bytes("image/png", png));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.parts: Vec<Part>Part::Text and Part::Media parts.
Implementations§
Source§impl ToolOutput
impl ToolOutput
Sourcepub fn from_media(media: Media) -> Self
pub fn from_media(media: Media) -> Self
Creates an output with one media part.
Sourcepub fn with_media(self, media: Media) -> Self
pub fn with_media(self, media: Media) -> Self
Appends media.
Trait Implementations§
Source§impl Clone for ToolOutput
impl Clone for ToolOutput
Source§impl Debug for ToolOutput
impl Debug for ToolOutput
Source§impl Default for ToolOutput
impl Default for ToolOutput
Source§impl Display for ToolOutput
Text parts as they are, media as [content type], for example [image/png].
impl Display for ToolOutput
Text parts as they are, media as [content type], for example [image/png].