Skip to main content

AgentOutput

Struct AgentOutput 

Source
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

Source

pub fn new(value: Value) -> Self

创建新的输出。

Source

pub fn with_history( value: Value, messages: Vec<ChatMessage>, tool_calls: Vec<ToolCallRecord>, ) -> Self

创建带历史的输出。

Source

pub fn with_usage( value: Value, messages: Vec<ChatMessage>, tool_calls: Vec<ToolCallRecord>, usage: Option<Usage>, ) -> Self

创建带 usage 的输出。

Source

pub fn text(&self) -> Option<&str>

获取文本内容(如果存在)。

Source

pub fn text_unwrap(&self) -> &str

获取文本内容,如果不存在则返回空字符串。

Source

pub fn text_or<'a>(&'a self, default: &'a str) -> &'a str

获取文本内容,如果不存在则返回默认值。

Source

pub fn into_text(self) -> String

消费自身,获取文本内容的所有权。

Source

pub fn message_count(&self) -> usize

获取对话历史长度。

Source

pub fn tool_call_count(&self) -> usize

获取工具调用次数。

Source

pub fn usage(&self) -> Option<&Usage>

获取 Token 使用统计。

Source

pub fn total_tokens(&self) -> u32

获取总 Token 数。

Source

pub fn prompt_tokens(&self) -> u32

获取提示词 Token 数。

Source

pub fn completion_tokens(&self) -> u32

获取输出 Token 数。

Source

pub fn usage_summary(&self) -> String

格式化 Token 使用信息。

Trait Implementations§

Source§

impl Clone for AgentOutput

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentOutput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for AgentOutput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more