contextpolicy

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package contextpolicy turns Kram's context limits into one explicit plan. Fixed prompt/tool-schema cost, conversation history, response headroom and tool-output growth all draw from the same model window instead of being governed by unrelated constants that can collectively overcommit it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int

Action is the cheapest intervention that can bring history under its share of the context window.

const (
	Keep Action = iota
	Prune
	Compact
)

type Plan

type Plan struct {
	MaxTokens             int
	FixedTokens           int
	ResponseReserveTokens int
	HistoryBudgetTokens   int
}

Plan is one iteration's concrete allocation. FixedTokens includes the system/project/memory preamble, postscript and tool definitions.

func New

func New(maxTokens, fixedTokens int) Plan

New allocates one eighth of the model window to the answer, capped at 8k tokens. Everything left after fixed prompt cost is the history budget.

func (Plan) Action

func (p Plan) Action(historyTokens, prunedHistoryTokens int) Action

Action compares the real history and its cheap structurally-pruned form.

func (Plan) RemainingHistoryTokens

func (p Plan) RemainingHistoryTokens(historyTokens int) int

RemainingHistoryTokens reports how much additional history can fit before the next iteration needs pruning/compaction.

func (Plan) ToolOutputBudgetChars

func (p Plan) ToolOutputBudgetChars(historyTokens, maxChars int) int

ToolOutputBudgetChars converts the remaining token allocation using the same chars/4 approximation as compaction and caps it at the producer-level aggregate limit supplied by the agent loop.

Jump to

Keyboard shortcuts

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