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 json(value: Value) -> Self
pub fn json(value: Value) -> Self
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<Self, ToolExecutionError>
pub fn content( content: Vec<ToolResultContent>, ) -> Result<Self, 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) -> Self
pub fn one(content: ToolResultContent) -> Self
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§impl Debug for ToolOutput
impl Debug for ToolOutput
Source§impl<'de> Deserialize<'de> for ToolOutput
impl<'de> Deserialize<'de> for ToolOutput
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl From<&str> for ToolOutput
impl From<&str> for ToolOutput
Source§impl From<String> for ToolOutput
impl From<String> for ToolOutput
Source§impl From<ToolResultContent> for ToolOutput
impl From<ToolResultContent> for ToolOutput
Source§fn from(content: ToolResultContent) -> Self
fn from(content: ToolResultContent) -> Self
Source§impl From<Value> for ToolOutput
impl From<Value> for ToolOutput
Source§impl PartialEq for ToolOutput
impl PartialEq for ToolOutput
Source§impl Serialize for ToolOutput
impl Serialize for ToolOutput
impl StructuralPartialEq for ToolOutput
Source§impl TryFrom<Vec<ToolResultContent>> for ToolOutput
impl TryFrom<Vec<ToolResultContent>> for ToolOutput
Auto Trait Implementations§
impl Freeze for ToolOutput
impl RefUnwindSafe for ToolOutput
impl Send for ToolOutput
impl Sync for ToolOutput
impl Unpin for ToolOutput
impl UnsafeUnpin for ToolOutput
impl UnwindSafe for ToolOutput
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more