contextusage

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package contextusage holds the latest size of each session's context window and the tool that lets the agent read it.

Index

Constants

View Source
const ToolName = "get_context_remaining"

ToolName is the name of the tool that reports the remaining context.

Variables

This section is empty.

Functions

func Forget

func Forget(id types.SessionID)

Forget drops a session's snapshot, when the session ends.

func Record

func Record(id types.SessionID, s Snapshot)

Record stores the latest snapshot of a session.

Types

type Snapshot

type Snapshot struct {
	UsedTokens          int    `json:"used_tokens"`
	WindowTokens        int    `json:"window_tokens"`
	AutoCompactAtTokens int    `json:"auto_compact_at_tokens"`
	BlockingLimitTokens int    `json:"blocking_limit_tokens"`
	Source              string `json:"source"`
}

Snapshot is where a session's context window stands.

func Get

func Get(id types.SessionID) (Snapshot, bool)

Get returns the latest snapshot of a session.

func (Snapshot) Remaining

func (s Snapshot) Remaining() int

Remaining is the tokens left before the window is full.

func (Snapshot) UntilCompaction

func (s Snapshot) UntilCompaction() int

UntilCompaction is the tokens left before the conversation is compacted automatically.

type Tool

type Tool struct{}

Tool implements get_context_remaining.

func NewTool

func NewTool() *Tool

NewTool creates the get_context_remaining tool.

func (*Tool) BackfillInput

func (t *Tool) BackfillInput(_ context.Context, in map[string]any) map[string]any

func (*Tool) Call

Call reports the session's latest snapshot.

func (*Tool) CheckPermissions

func (t *Tool) CheckPermissions(_ context.Context, in map[string]any, _ tool.ToolUseContext) types.PermissionResult

func (*Tool) Definition

func (t *Tool) Definition() tool.Definition

Definition returns the tool definition.

func (*Tool) Description

func (t *Tool) Description(_ context.Context) (string, error)

func (*Tool) FormatResult

func (t *Tool) FormatResult(data any) string

func (*Tool) IsConcurrencySafe

func (t *Tool) IsConcurrencySafe(_ map[string]any) bool

func (*Tool) IsEnabled

func (t *Tool) IsEnabled() bool

func (*Tool) IsReadOnly

func (t *Tool) IsReadOnly(_ map[string]any) bool

func (*Tool) ValidateInput

func (t *Tool) ValidateInput(_ context.Context, in map[string]any) (map[string]any, error)

Jump to

Keyboard shortcuts

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