Documentation
¶
Overview ¶
Package usage tracks token + cost accounting for the agent loop.
Every model call returns a UsageMetadata block with input and output token counts; a Tracker accumulates these across a session. Pricing numbers come from a built-in table that callers may override per model via .agents/config.json (model.pricing).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pricing ¶
type Pricing struct {
InputPerMTok float64 // USD per 1,000,000 input tokens
OutputPerMTok float64 // USD per 1,000,000 output tokens
}
Pricing is the per-million-token rate for one model. Both fields are in USD and apply to a single direction (input or output).
func PriceFor ¶
PriceFor returns the Pricing for modelID. Resolution order:
- Explicit cfg override (cfg.Model.Pricing) when modelID matches cfg.Model.Name (case-insensitive).
- Exact match in the built-in table.
- Prefix match in the built-in table (longest first).
- Zero pricing — caller should treat cost as unknown.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker accumulates per-turn usage for one Cogo session.
Thread-safe: the agent goroutine (or headless run loop) calls Append; the TUI's render path reads via Last/Totals/All.
func NewTracker ¶
func NewTracker() *Tracker
NewTracker returns a tracker with its session-start time set to now.
func (*Tracker) Append ¶
Append records one turn's usage. Cost is computed via the supplied Pricing; pass a zero Pricing to skip cost tracking.