Documentation
¶
Overview ¶
Package boundctx keeps an agent prompt under a model's context window.
A ticket log, a command's output or a diff can be megabytes; one such prompt was rejected as "~1241087 tokens (limit 1000000)". A Set bounds each input: one that fits is passed through untouched, one that does not is written in full to a file and replaced by a head and tail excerpt, the path, and a line saying the agent may read the file.
Index ¶
Constants ¶
const ( // DefaultPerInput bounds one log entry or output in the prompt. DefaultPerInput = 24 << 10 // DefaultTotal bounds all log entries together. The diff is bounded // separately by its own limit. DefaultTotal = 128 << 10 // DefaultDiffLimit bounds a diff in the prompt unless the caller says more. DefaultDiffLimit = 100 << 10 // MaxRolePrompt is the ceiling on the instruction part of a prompt. MaxRolePrompt = 64 << 10 )
Variables ¶
This section is empty.
Functions ¶
func DiffSummary ¶
DiffSummary lists the files, line counts and largest files of a unified diff, marking generated and fixture files.
func Excerpt ¶
Excerpt returns text unchanged when it fits max bytes, and otherwise its first and last halves around a marker saying how much was left out. Cuts move to the nearest rune start, so a multi-byte character is dropped whole rather than split; bytes that were never valid UTF-8 are left alone.
Types ¶
type Set ¶
type Set struct {
// Dir is where full inputs go. Files are named by content, so building the
// same prompt again reuses them. Empty means do not write files.
Dir string
PerInput int
Total int
// Unreadable means the agent has no tools: files are saved for the operator
// and the prompt does not point the agent at them.
Unreadable bool
// contains filtered or unexported fields
}
Set bounds the inputs of one prompt. The zero value uses the defaults and writes no files, so an overflow leaves only the excerpt.
func (*Set) Bound ¶
Bound returns text when it fits the per-input limit and the remaining total. Otherwise it saves text under name and returns an excerpt with a pointer, or only the pointer when little room is left.
func (*Set) BoundDiff ¶
BoundDiff returns diff when it is at most limit bytes. A larger diff becomes a per-file summary, an excerpt, a statement of what was not seen, and the path of the full diff.
func (*Set) BoundSeq ¶
BoundSeq bounds items, oldest first, spending the budget on the newest. When the budget runs out the older items are replaced by a single note at the front, with their full text in one file; the result then has one more element than the kept items. The total stays within the Set's Total plus that one note.