pub struct AgentOutput {
pub value: Value,
pub messages: Vec<ChatMessage>,
pub tool_calls: Vec<ToolCallRecord>,
pub usage: Option<Usage>,
}Expand description
Agent 输出。
包含 Agent 执行的结果和相关信息。
§字段说明
value: 主要输出内容(通常是 JSON 格式)messages: 对话历史tool_calls: 工具调用记录
§使用示例
use rucora_core::agent::AgentOutput;
use serde_json::json;
// 创建输出
let output = AgentOutput::new(json!({"content": "Hello"}));
// 提取文本内容
if let Some(content) = output.value.get("content").and_then(|v| v.as_str()) {
assert_eq!(content, "Hello");
}
// 访问对话历史
assert_eq!(output.messages.len(), 0);
// 访问工具调用
assert_eq!(output.tool_calls.len(), 0);Fields§
§value: Value主要输出内容(通常是 JSON 格式,包含 content 字段)。
messages: Vec<ChatMessage>对话历史。
tool_calls: Vec<ToolCallRecord>工具调用记录。
usage: Option<Usage>Token 使用统计(累计所有 LLM 调用的 usage)。
Implementations§
Source§impl AgentOutput
impl AgentOutput
Sourcepub fn with_history(
value: Value,
messages: Vec<ChatMessage>,
tool_calls: Vec<ToolCallRecord>,
) -> Self
pub fn with_history( value: Value, messages: Vec<ChatMessage>, tool_calls: Vec<ToolCallRecord>, ) -> Self
创建带历史的输出。
Sourcepub fn with_usage(
value: Value,
messages: Vec<ChatMessage>,
tool_calls: Vec<ToolCallRecord>,
usage: Option<Usage>,
) -> Self
pub fn with_usage( value: Value, messages: Vec<ChatMessage>, tool_calls: Vec<ToolCallRecord>, usage: Option<Usage>, ) -> Self
创建带 usage 的输出。
Sourcepub fn text_unwrap(&self) -> &str
pub fn text_unwrap(&self) -> &str
获取文本内容,如果不存在则返回空字符串。
Sourcepub fn message_count(&self) -> usize
pub fn message_count(&self) -> usize
获取对话历史长度。
Sourcepub fn tool_call_count(&self) -> usize
pub fn tool_call_count(&self) -> usize
获取工具调用次数。
Sourcepub fn total_tokens(&self) -> u32
pub fn total_tokens(&self) -> u32
获取总 Token 数。
Sourcepub fn prompt_tokens(&self) -> u32
pub fn prompt_tokens(&self) -> u32
获取提示词 Token 数。
Sourcepub fn completion_tokens(&self) -> u32
pub fn completion_tokens(&self) -> u32
获取输出 Token 数。
Sourcepub fn usage_summary(&self) -> String
pub fn usage_summary(&self) -> String
格式化 Token 使用信息。
Trait Implementations§
Source§impl Clone for AgentOutput
impl Clone for AgentOutput
Source§fn clone(&self) -> AgentOutput
fn clone(&self) -> AgentOutput
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 AgentOutput
impl Debug for AgentOutput
Auto Trait Implementations§
impl Freeze for AgentOutput
impl RefUnwindSafe for AgentOutput
impl Send for AgentOutput
impl Sync for AgentOutput
impl Unpin for AgentOutput
impl UnsafeUnpin for AgentOutput
impl UnwindSafe for AgentOutput
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