Documentation
¶
Overview ¶
Package modelusage keeps what a step's calls to models use while the step runs. A step's context carries its meter, and every model call made with that context adds to it.
Index ¶
- func SubRunSource(runID string) string
- func WithMeter(ctx context.Context, m *Meter) context.Context
- type Flusher
- type Meter
- func (m *Meter) Add(models []ir.ModelUsage)
- func (m *Meter) MarkNotReported(tool string)
- func (m *Meter) RecordLLMUsage(record llm.UsageRecord)
- func (m *Meter) SetReported(source string, models []ir.ModelUsage)
- func (m *Meter) Snapshot() *ir.StepModelUsage
- func (m *Meter) StartFlusher(every time.Duration, report func(*ir.StepModelUsage)) *Flusher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SubRunSource ¶
SubRunSource names a child run as the source of the usage its parent step reports, so each child keeps one entry however often it reports.
Types ¶
type Flusher ¶
type Flusher struct {
// contains filtered or unexported fields
}
Flusher reports a meter's usage while its step runs, at most once an interval and only after the usage changed since the last report, so a step that calls no model never reports.
type Meter ¶
type Meter struct {
// contains filtered or unexported fields
}
Meter adds up a step's calls to models, on top of what the step's earlier attempts used. Its methods do nothing on a nil meter, so an executor run without one needs no checks.
func FromContext ¶
FromContext returns the meter ctx carries, or nil.
func NewMeter ¶
func NewMeter(base *ir.StepModelUsage) *Meter
NewMeter returns a meter that starts from what the step used before, which may be nil.
func (*Meter) Add ¶
func (m *Meter) Add(models []ir.ModelUsage)
Add adds usage the step's own work spent elsewhere, such as the body of a foreach item, once that work is done.
func (*Meter) MarkNotReported ¶
MarkNotReported records that the step ran tool, whose model usage cannot be read.
func (*Meter) RecordLLMUsage ¶
func (m *Meter) RecordLLMUsage(record llm.UsageRecord)
RecordLLMUsage adds one call.
func (*Meter) SetReported ¶
func (m *Meter) SetReported(source string, models []ir.ModelUsage)
SetReported records source's latest total, as a coding agent's session reports it, replacing the one before. A source the step resumes keeps its entry, so what it used before is not counted twice.
func (*Meter) Snapshot ¶
func (m *Meter) Snapshot() *ir.StepModelUsage
Snapshot returns what the step has used so far, or nil when it has used nothing and reported nothing.
func (*Meter) StartFlusher ¶
StartFlusher has report called with the meter's usage, at most once every interval, after the meter records a call. Stop it before the step ends.