contextsummary

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package contextsummary turns the messages a compaction drops into one validated, bounded summary document, through one bounded provider.Completer call. A summary failure is a caller-visible error; no structural fallback exists. Compaction policy lives in contextplan; the loop wiring lives in agentloop.

Index

Constants

View Source
const MaxExcerptTotalBytes = 16 * 1024

MaxExcerptTotalBytes bounds the whole source-excerpt section of one summarize prompt.

View Source
const MaxFieldBytes = 2 * 1024

MaxFieldBytes bounds every individual Summary text field and every list item.

View Source
const MaxItems = 32

MaxItems bounds every Summary list.

View Source
const SummaryMessageName = "context-summary"

SummaryMessageName is the provider.Message.Name of the injected summary message. Compaction preserves it through PreserveNames.

View Source
const SummaryTimeout = 20 * time.Second

SummaryTimeout bounds one summarize call.

Variables

View Source
var (
	// ErrNilCompleter is NewSummarizer's error for a nil Completer.
	ErrNilCompleter = errors.New("contextsummary: completer is required")
	// ErrNoMessages is Summarize's error for an empty message list.
	ErrNoMessages = errors.New("contextsummary: no messages to summarize")
	// ErrInvalidReply is Summarize's error when the reply fails
	// strict parsing or Summary.Validate.
	ErrInvalidReply = errors.New("contextsummary: reply failed strict parsing or validation")
	// ErrCallFailed is Summarize's error when the Completer call
	// itself fails.
	ErrCallFailed = errors.New("contextsummary: summary call failed")
)

Sentinel errors; test with errors.Is.

Functions

func SummaryMessage

func SummaryMessage(s Summary) provider.Message

SummaryMessage renders s as one RoleUser message named SummaryMessageName, whose Content is s.Render().

func TokenEstimate

func TokenEstimate(n int) int

TokenEstimate prices n bytes at n/4 tokens, minimum one for non-zero input, zero for zero input.

Types

type Summarizer

type Summarizer struct {
	// contains filtered or unexported fields
}

Summarizer adapts one provider.Completer to summary generation.

func NewSummarizer

func NewSummarizer(c provider.Completer) (*Summarizer, error)

NewSummarizer binds one Completer. A nil Completer wraps ErrNilCompleter.

func (*Summarizer) Summarize

func (s *Summarizer) Summarize(ctx context.Context, msgs []provider.Message) (Summary, error)

Summarize makes one bounded Completer call over msgs and returns the validated Summary. Never retries. Any failure is caller-visible.

type Summary

type Summary struct {
	Objective string
	State     string
	Decisions []string
	OpenWork  []string
	Risks     []string
}

Summary is one validated summary document. Data only: no tool, policy, or credential fields.

func (Summary) Render

func (s Summary) Render() string

Render returns the deterministic text form of s: one labeled line or bullet per field, in field order.

func (Summary) Validate

func (s Summary) Validate() error

Validate enforces every bound this package claims: valid UTF-8, no control characters, non-empty Objective and State, MaxFieldBytes per field and per item, at most MaxItems per list, no duplicate items, and no blank item (empty or whitespace-only).

Jump to

Keyboard shortcuts

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