extract

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentKey

func ContentKey(text string) string

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

func DeterministicProject(value any, keepIDs []string, maxChars int) any

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

func HarvestIdentifiers(text string, cap int) []string

HarvestIdentifiers pulls distinctive identifiers (paths, symbols, ids, numbers) from the agent's recent turns — the keep-set the extractor must retain.

func IsContained

func IsContained(result, original any) bool

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.

type Model

type Model interface {
	Complete(ctx context.Context, prompt string) (string, error)
}

Model is the cheap-model client the extractor calls. The host (proxy / plugin) injects a concrete implementation; the extractor core stays transport-free.

Jump to

Keyboard shortcuts

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