stats

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package stats provides statistics tracking for agent operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentStats

type AgentStats struct {
	TotalPromptTokens     int
	TotalCompletionTokens int
	TotalCacheReadTokens  int
	TotalAgentTime        time.Duration
	TotalLLMTime          time.Duration
	TotalToolTime         time.Duration
	Steps                 int // Number of LLM iterations
	MaxContextUsed        int
	TotalCost             float64
	CacheDiscount         float64

	// Timing stats from LLM server (in milliseconds)
	TotalPromptMS     float64
	TotalGenerationMS float64

	// Backtrack stats (discarded requests)
	DiscardedPromptTokens     int
	DiscardedCompletionTokens int
	DiscardedCost             float64
	BacktrackCount            int
}

AgentStats tracks cumulative statistics across all agent iterations

func (*AgentStats) Print

func (s *AgentStats) Print()

Print outputs the agent stats in a formatted JSON block to stdout

func (*AgentStats) PrintTo

func (s *AgentStats) PrintTo(w io.Writer)

PrintTo outputs the agent stats in a formatted JSON block to the given writer

func (*AgentStats) ToJSON

func (s *AgentStats) ToJSON() AgentStatsJSON

ToJSON converts AgentStats to its JSON representation

type AgentStatsJSON

type AgentStatsJSON struct {
	Tokens struct {
		Prompt     int `json:"prompt"`
		Completion int `json:"completion"`
		CacheRead  int `json:"cache_read"`
	} `json:"tokens"`
	Timing struct {
		TotalAgentSeconds float64 `json:"total_agent_seconds"`
		LLMSeconds        float64 `json:"llm_seconds"`
		ToolSeconds       float64 `json:"tool_seconds"`
		PromptMS          float64 `json:"prompt_ms"`
		GenerationMS      float64 `json:"generation_ms"`
	} `json:"timing"`
	Steps          int `json:"steps"`
	MaxContextUsed int `json:"max_context_used"`
	Cost           struct {
		CacheDiscountUSD float64 `json:"cache_discount_usd"`
		TotalCostUSD     float64 `json:"total_cost_usd"`
	} `json:"cost"`
	Backtrack struct {
		DiscardedPromptTokens     int     `json:"discarded_prompt_tokens,omitempty"`
		DiscardedCompletionTokens int     `json:"discarded_completion_tokens,omitempty"`
		DiscardedCostUSD          float64 `json:"discarded_cost_usd,omitempty"`
		BacktrackCount            int     `json:"backtrack_count,omitempty"`
	} `json:"backtrack,omitempty"`
}

AgentStatsJSON is the JSON output format for agent stats

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL