pub struct UsageStats {
pub prompt_tokens: AtomicU64,
pub completion_tokens: AtomicU64,
pub llm_calls: AtomicU64,
pub search_calls: AtomicU64,
pub fetch_calls: AtomicU64,
pub webbrowser_calls: AtomicU64,
pub custom_tool_calls: DashMap<String, AtomicU64>,
pub tool_calls: AtomicU64,
}Expand description
Usage statistics for tracking agent operations.
Uses atomic counters for lock-free concurrent updates.
Fields§
§prompt_tokens: AtomicU64Total LLM prompt tokens used.
completion_tokens: AtomicU64Total LLM completion tokens used.
llm_calls: AtomicU64Total LLM calls made.
search_calls: AtomicU64Total search calls made.
fetch_calls: AtomicU64Total HTTP fetch calls made.
webbrowser_calls: AtomicU64Total web browser calls made (Chrome/WebDriver combined).
custom_tool_calls: DashMap<String, AtomicU64>Custom tool calls tracked by tool name (lock-free via DashMap).
tool_calls: AtomicU64Total tool calls made.
Implementations§
Source§impl UsageStats
impl UsageStats
Sourcepub fn add_tokens(&self, prompt: u64, completion: u64)
pub fn add_tokens(&self, prompt: u64, completion: u64)
Add tokens from an LLM response.
Sourcepub fn increment_llm_calls(&self)
pub fn increment_llm_calls(&self)
Increment LLM call count.
Sourcepub fn increment_search_calls(&self)
pub fn increment_search_calls(&self)
Increment search call count.
Sourcepub fn increment_fetch_calls(&self)
pub fn increment_fetch_calls(&self)
Increment fetch call count.
Sourcepub fn increment_webbrowser_calls(&self)
pub fn increment_webbrowser_calls(&self)
Increment web browser call count (Chrome/WebDriver).
Sourcepub fn increment_custom_tool_calls(&self, tool_name: &str)
pub fn increment_custom_tool_calls(&self, tool_name: &str)
Increment custom tool call count for a specific tool.
Sourcepub fn get_custom_tool_calls(&self, tool_name: &str) -> u64
pub fn get_custom_tool_calls(&self, tool_name: &str) -> u64
Get custom tool call count for a specific tool.
Sourcepub fn total_custom_tool_calls(&self) -> u64
pub fn total_custom_tool_calls(&self) -> u64
Get total custom tool calls across all tools.
Sourcepub fn increment_tool_calls(&self)
pub fn increment_tool_calls(&self)
Increment tool call count.
Sourcepub fn total_tokens(&self) -> u64
pub fn total_tokens(&self) -> u64
Get total tokens used.
Sourcepub fn snapshot(&self) -> UsageSnapshot
pub fn snapshot(&self) -> UsageSnapshot
Get a snapshot of all stats.
Sourcepub fn check_llm_limit(&self, limits: &UsageLimits) -> Option<LimitType>
pub fn check_llm_limit(&self, limits: &UsageLimits) -> Option<LimitType>
Check if LLM call limit would be exceeded.
Sourcepub fn check_search_limit(&self, limits: &UsageLimits) -> Option<LimitType>
pub fn check_search_limit(&self, limits: &UsageLimits) -> Option<LimitType>
Check if search call limit would be exceeded.
Sourcepub fn check_fetch_limit(&self, limits: &UsageLimits) -> Option<LimitType>
pub fn check_fetch_limit(&self, limits: &UsageLimits) -> Option<LimitType>
Check if fetch call limit would be exceeded.
Sourcepub fn check_webbrowser_limit(&self, limits: &UsageLimits) -> Option<LimitType>
pub fn check_webbrowser_limit(&self, limits: &UsageLimits) -> Option<LimitType>
Check if web browser call limit would be exceeded.
Sourcepub fn check_custom_tool_limit(&self, limits: &UsageLimits) -> Option<LimitType>
pub fn check_custom_tool_limit(&self, limits: &UsageLimits) -> Option<LimitType>
Check if custom tool call limit would be exceeded (total across all tools).
Sourcepub fn check_tool_limit(&self, limits: &UsageLimits) -> Option<LimitType>
pub fn check_tool_limit(&self, limits: &UsageLimits) -> Option<LimitType>
Check if tool call limit would be exceeded.
Sourcepub fn check_token_limits(&self, limits: &UsageLimits) -> Option<LimitType>
pub fn check_token_limits(&self, limits: &UsageLimits) -> Option<LimitType>
Check if token limits would be exceeded.