#[non_exhaustive]pub struct ToolResult {
pub text: String,
pub structured: Option<Value>,
}Expand description
What a tool answered: the text the model is shown, and the structured
value beside it when the tool’s source returned one (MCP’s
structuredContent).
The model gets a string either way — into_model_text — because that is
what every chat-completion API takes for a tool message. The structured
value is for whoever holds the result: a consumer that wants to check it
against the tool’s output_schema or render it, without re-parsing prose.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.text: StringThe text content, joined. Empty when the tool returned only structure.
structured: Option<Value>The structured result, where the source gave one.
Implementations§
Source§impl ToolResult
impl ToolResult
pub fn new(text: impl Into<String>) -> Self
pub fn with_structured(self, value: Value) -> Self
Sourcepub fn into_model_text(self) -> String
pub fn into_model_text(self) -> String
The string the model is told. The text when there is any; otherwise the structured value serialized, so a tool that answered only in structure is not reported as having said nothing.
Trait Implementations§
Source§impl Clone for ToolResult
impl Clone for ToolResult
Source§impl Debug for ToolResult
impl Debug for ToolResult
Source§impl Default for ToolResult
impl Default 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
Source§impl PartialEq for ToolResult
impl PartialEq for ToolResult
Source§impl Serialize for ToolResult
impl Serialize for ToolResult
impl StructuralPartialEq for ToolResult
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