pub struct ToolOutput {
pub title: String,
pub content: String,
pub metadata: Value,
pub is_error: bool,
}Expand description
工具执行结果 — 返回给 agent loop 的输出。
设计参考 OpenCode 的 ExecuteResult:
content总是 string(LLM 只理解文本)metadata为结构化数据(UI/日志/遥测用,不发送给 LLM)is_error标记非抛异常的失败(如工具内部捕获的错误)
§Examples
use katu_core::ToolOutput;
use serde_json::json;
// 成功结果
let output = ToolOutput::success("File contents here");
assert!(!output.is_error);
// 错误结果
let output = ToolOutput::error("Permission denied: /etc/shadow");
assert!(output.is_error);Fields§
§title: String标题 — UI 显示用的简短描述。
例如 "Read file: src/main.rs", "Bash: ls -la"。
content: String主输出内容 — 发送回 LLM 的文本。
这是 LLM 在下一轮推理中看到的 tool result 内容。
metadata: Value结构化元数据 — UI/日志/遥测用,不发送给 LLM。
例如执行耗时、文件路径、diff 统计等。
is_error: bool是否为错误结果。
true 时 agent loop 将 content 作为错误信息反馈给 LLM,
LLM 可据此修正策略。区别于 Err(...) 的不可恢复错误,
is_error = true 表示工具执行完成但结果是失败的。
Implementations§
Source§impl ToolOutput
impl ToolOutput
Sourcepub fn success_with_title(
title: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn success_with_title( title: impl Into<String>, content: impl Into<String>, ) -> Self
创建带标题的成功工具输出。
Sourcepub fn error(content: impl Into<String>) -> Self
pub fn error(content: impl Into<String>) -> Self
创建错误的工具输出。
不同于 Err(...) — 这里工具执行完成了,但结果是失败的。
LLM 会看到错误信息并可以据此调整策略。
Sourcepub fn with_metadata(self, metadata: Value) -> Self
pub fn with_metadata(self, metadata: Value) -> Self
设置元数据(builder 模式)。
Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
设置标题(builder 模式)。
Trait Implementations§
Source§impl Clone for ToolOutput
impl Clone for ToolOutput
Source§fn clone(&self) -> ToolOutput
fn clone(&self) -> ToolOutput
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§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: __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 ToolOutput
impl PartialEq for ToolOutput
Source§fn eq(&self, other: &ToolOutput) -> bool
fn eq(&self, other: &ToolOutput) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for ToolOutput
impl Serialize for ToolOutput
impl StructuralPartialEq 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
Mutably borrows from an owned value. Read more