Documentation
¶
Overview ¶
Package extract is the cheap-model tool-output extractor. A small model returns a SMALLER value of the same shape (selecting records/fields, never paraphrasing); the containment validator here PROVES the result is a lossless projection of the original, so a chatty model can never corrupt a value the agent relies on. On any failure it falls back to a deterministic projection, then to the original (fail-open). Ported from the reference prototype's actions/llm_compact.py.
ponytail: the model returns the selected JSON directly and containment verifies it — no model-generated code (the reference prototype's Python sandbox) and no custom spec language. The containment proof is what makes the mechanism safe, whatever produced the subset.
Index ¶
- func ContentKey(text string) string
- func DeterministicProject(value any, keepIDs []string, maxChars int) any
- func HarvestIdentifiers(text string, cap int) []string
- func IsContained(result, original any) bool
- func RunExtraction(ctx context.Context, body, goal string, keepIDs []string, tokenEst int, ...) (string, string)
- func RunExtractionSummary(ctx context.Context, body, goal string, keepIDs []string, tokenEst int, ...) (string, string, string)
- type Cfg
- type Model
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentKey ¶
ContentKey is a stable, marker- and whitespace-insensitive key for a body, so the same output re-sent on a later turn hits the extraction cache.
func DeterministicProject ¶
DeterministicProject filters a parsed value to the keep-set + important-key spine. Never empties: a value that projects to nothing falls back to a truncated copy.
func HarvestIdentifiers ¶
HarvestIdentifiers pulls distinctive identifiers (paths, symbols, ids, numbers) from the agent's recent turns — the keep-set the extractor must retain.
func IsContained ¶
IsContained reports whether result is a lossless projection of original (both parsed values): string → an order-preserving **character subsequence** of the original (result must be obtainable by DELETING characters — so a filter may drop whole lines/records OR trim words/sentences/parts within a line, but can never fabricate, reorder, or reword; this subsumes substring and whole-line subsequence); list → order-preserving subsequence of contained items; dict → keys subset with contained values; numbers/bools/nil → equal where present; nil result → always allowed (dropping is fine).
func RunExtraction ¶
func RunExtraction(ctx context.Context, body, goal string, keepIDs []string, tokenEst int, cfg Cfg, model Model) (string, string)
RunExtraction tries strategies in order, returning the first candidate that is strictly smaller AND passes the validation gate, else ("", "none"). Fail-open: the caller keeps the original on "none".
func RunExtractionSummary ¶
func RunExtractionSummary(ctx context.Context, body, goal string, keepIDs []string, tokenEst int, cfg Cfg, model Model) (string, string, string)
RunExtractionSummary is RunExtraction plus the one-line SUMMARY the "code" strategy's program optionally emitted (empty for the other strategies). The summary is used as the marker digest so the agent sees the gist of the elided output inline.
Types ¶
type Cfg ¶
type Cfg struct {
Mode string // auto | single | rlm | deterministic
Floor int // token floor; rlm kicks in at max(floor*4, 8000) in auto
MinKeepRatio float64 // 0 disables the blunt ratio backstop (keep-set check governs)
AllowDeterministic bool
MaxChars int // deterministic projection window
// AllowedStrategies, when non-empty, restricts strategyOrder to these strategy names
// (code | single | rlm | deterministic) preserving the computed order. Empty means
// "all" — prior behavior. Lets config enable/disable strategies purely by name.
AllowedStrategies []string
// Rewrite opts out of the containment proof (deletion-only guarantee): the model
// may reword/summarize/rewrite freely. Lossy + unverified — the caller must accept
// that (e.g. a non-full marker_mode). Default false keeps the verified guarantee.
Rewrite bool
}
Cfg configures extraction.
func DefaultCfg ¶
func DefaultCfg() Cfg
DefaultCfg mirrors the reference prototype's ExtractCfg defaults.