contextusage

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextUsage

type ContextUsage struct {
	TotalTokens      int                `json:"totalTokens"`
	MaxTokens        int                `json:"maxTokens"`
	Percentage       float64            `json:"percentage"`
	Model            string             `json:"model"`
	Categories       map[string]int     `json:"categories"`
	MessageBreakdown []MessageTokenInfo `json:"messageBreakdown,omitempty"`
}

ContextUsage summarises how much of the context window is consumed.

type MessageTokenInfo

type MessageTokenInfo struct {
	Role   string `json:"role"`
	Tokens int    `json:"tokens"`
	UUID   string `json:"uuid,omitempty"`
}

MessageTokenInfo describes token usage for a single message.

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

Tracker estimates and tracks context window usage.

func NewTracker

func NewTracker() *Tracker

NewTracker creates a new context usage tracker.

func (*Tracker) GetUsage

func (t *Tracker) GetUsage() *ContextUsage

GetUsage returns a copy of the current context usage.

func (*Tracker) SetMaxTokens

func (t *Tracker) SetMaxTokens(max int)

SetMaxTokens overrides the maximum context window size.

func (*Tracker) Update

func (t *Tracker) Update(model string, messages []types.Message, toolCount int)

Update re-estimates context usage from messages and tool count. If messages carry Usage info from the API, those values are used; otherwise a rough character-based estimate is applied.

Jump to

Keyboard shortcuts

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