Documentation
¶
Overview ¶
Package contextbudget is a leaf package (standard library only) holding the live context-window budget of one run: how many tokens the conversation has used against the model's window, whether a low-budget reminder has been delivered, and whether the model has asked to continue in a fresh window.
The agent loop owns the state's lifecycle: it creates one per run (or adopts the session-scoped one the driver passes in), publishes it into the run context, and observes the conversation size as the run progresses. The context-sensitive tools (get_context_remaining, new_context) and the budget reminder provider read the same object back from the context, so every surface sees one consistent figure without per-driver wiring — the same pattern as the judge's message snapshot.
Index ¶
- func WithState(ctx context.Context, s *State) context.Context
- type Notice
- type State
- func (s *State) Observe(used int)
- func (s *State) Remaining() (int, bool)
- func (s *State) RequestRollover()
- func (s *State) RolloverEnabled() bool
- func (s *State) SetRolloverEnabled(enabled bool)
- func (s *State) SetWindow(window int)
- func (s *State) TakeNotice() (Notice, bool)
- func (s *State) TakeRolloverRequest() bool
- func (s *State) Usage() (used, window int, ok bool)
- type Tier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the concurrency-safe context budget of one run. Use New; the zero value is not usable.
func FromContext ¶
FromContext returns the budget state carried by ctx, or nil when the caller runs outside a budget-aware loop.
func (*State) Remaining ¶
Remaining returns the tokens left in the window, or ok=false while unknown.
func (*State) RequestRollover ¶
func (s *State) RequestRollover()
RequestRollover asks the loop to start a fresh context window at the next turn boundary. It is unconditional; callers check RolloverEnabled first to explain why the request cannot be honored.
func (*State) RolloverEnabled ¶
RolloverEnabled reports whether new_context can be honored.
func (*State) SetRolloverEnabled ¶
SetRolloverEnabled records whether new_context can be honored this run.
func (*State) SetWindow ¶
SetWindow records the model's context window in tokens (<=0 means unknown).
func (*State) TakeNotice ¶
TakeNotice returns the next due low-budget reminder. A reminder fires once per tier per crossing; the escalation from notice to critical fires once more, and the ladder resets after the budget recovers (e.g. after compaction), so a later crossing reminds again.
func (*State) TakeRolloverRequest ¶
TakeRolloverRequest consumes and reports a pending rollover request.