pub struct AgentMetrics {
pub trace_id: Option<String>,
pub llm_calls: usize,
pub cache_hits: usize,
pub tool_calls: usize,
pub compactions: usize,
pub total_tokens: Option<usize>,
pub duration: Duration,
}Expand description
Aggregated metrics for a single agent execution.
Fields§
§trace_id: Option<String>trace_id of this execution (None if absent).
llm_calls: usizeNumber of LLM planning calls (plan iterations).
cache_hits: usizeNumber of LLM result cache hits that skipped an LLM call.
tool_calls: usizeNumber of tool executions (including parallel).
compactions: usizeNumber of context compactions performed during the run (0.21.0 S6.1).
#[serde(default)] keeps pre-0.21.0 payloads deserializable.
total_tokens: Option<usize>Cumulative token usage (None if the agent does not report tokens).
duration: DurationTotal duration of a single invoke.
Implementations§
Source§impl AgentMetrics
impl AgentMetrics
Sourcepub fn add_token_usage(&mut self, usage: &TokenUsage)
pub fn add_token_usage(&mut self, usage: &TokenUsage)
Accumulates token usage from one LLM call.
Sourcepub fn tokens_per_call(&self) -> Option<f64>
pub fn tokens_per_call(&self) -> Option<f64>
Average tokens per LLM call.
Sourcepub fn log_summary(&self)
pub fn log_summary(&self)
Emits the metrics audit-log line (target: lc_agents::metrics).
Trait Implementations§
Source§impl Clone for AgentMetrics
impl Clone for AgentMetrics
Source§fn clone(&self) -> AgentMetrics
fn clone(&self) -> AgentMetrics
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 AgentMetrics
impl Debug for AgentMetrics
Source§impl Default for AgentMetrics
impl Default for AgentMetrics
Source§fn default() -> AgentMetrics
fn default() -> AgentMetrics
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for AgentMetrics
impl<'de> Deserialize<'de> for AgentMetrics
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<AgentMetrics, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<AgentMetrics, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for AgentMetrics
impl Serialize for AgentMetrics
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for AgentMetrics
impl RefUnwindSafe for AgentMetrics
impl Send for AgentMetrics
impl Sync for AgentMetrics
impl Unpin for AgentMetrics
impl UnsafeUnpin for AgentMetrics
impl UnwindSafe for AgentMetrics
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