pub struct ToolResult {
pub content: Vec<ToolContent>,
pub structured_content: Option<Value>,
pub is_error: bool,
pub metadata: BTreeMap<String, Value>,
}Expand description
Source-neutral result for a completed tool call.
Successful output must include structured content when the declaration has an
output schema. Some(Value::Null) is present content and is validated normally;
None is missing. An error result remains a completed model-visible outcome.
§Examples
use tools_kit::execution::ToolResult;
let result = ToolResult::json(serde_json::json!({"count":2}));
assert_eq!(result.structured_content, Some(serde_json::json!({"count":2})));
assert!(!result.is_error);Fields§
§content: Vec<ToolContent>Ordered model-visible content items.
structured_content: Option<Value>Optional structured value validated against the tool output schema.
is_error: boolWhether this completed result represents a model-visible tool failure.
metadata: BTreeMap<String, Value>Uninterpreted source-neutral result metadata.
Implementations§
Source§impl ToolResult
impl ToolResult
Sourcepub fn new(content: Vec<ToolContent>) -> Result<Self, ToolError>
pub fn new(content: Vec<ToolContent>) -> Result<Self, ToolError>
Creates a completed result.
§Errors
Returns ToolError::InvalidOutput if content is empty. Output-schema validation occurs when the owning handler completes.
§Examples
use tools_kit::execution::{ToolContent, ToolResult};
let result = ToolResult::new(vec![ToolContent::Text { text: "done".into(), metadata: None }])?;
assert_eq!(result.content.len(), 1);
assert!(ToolResult::new(Vec::new()).is_err());
Sourcepub fn text(text: impl Into<String>) -> Self
pub fn text(text: impl Into<String>) -> Self
Creates a text result.
§Examples
let result = tools_kit::execution::ToolResult::text("done");
assert!(!result.is_error);
assert!(result.structured_content.is_none());Sourcepub fn json(value: Value) -> Self
pub fn json(value: Value) -> Self
Creates a structured JSON result.
See crate::execution::ToolResult for a complete example.
Sourcepub fn with_error(self, is_error: bool) -> Self
pub fn with_error(self, is_error: bool) -> Self
Marks this completed result as model-visible failure.
Use a completed error result for an accepted tool-authored failure. Outer
ToolError values describe input, state, protocol, transport, or lifecycle failures.
§Examples
let result = tools_kit::execution::ToolResult::text("record unavailable").with_error(true);
assert!(result.is_error);Sourcepub fn with_structured_content(self, value: Value) -> Self
pub fn with_structured_content(self, value: Value) -> Self
Sets structured output.
§Examples
let result = tools_kit::execution::ToolResult::text("no value")
.with_structured_content(serde_json::Value::Null);
assert_eq!(result.structured_content, Some(serde_json::Value::Null));