context

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HaikuModel is the model used for summarization.
	HaikuModel = anthropic.ModelClaude3_5HaikuLatest
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CompactionResult

type CompactionResult struct {
	// Messages is the compacted message list.
	Messages []anthropic.MessageParam
	// OriginalTokens is the token count before compaction.
	OriginalTokens int
	// CompactedTokens is the token count after compaction.
	CompactedTokens int
	// SummaryAdded indicates if a summary message was added.
	SummaryAdded bool
}

CompactionResult contains the result of a compaction operation.

type HaikuSummarizer

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

HaikuSummarizer uses Claude Haiku to summarize conversation segments.

func NewHaikuSummarizer

func NewHaikuSummarizer(client anthropic.Client) *HaikuSummarizer

NewHaikuSummarizer creates a new summarizer using the provided client.

func (*HaikuSummarizer) Summarize

func (s *HaikuSummarizer) Summarize(ctx context.Context, messages []anthropic.MessageParam) (string, error)

Summarize generates a summary of the given messages using Haiku.

type Manager

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

Manager handles context window management for conversations.

func NewManager

func NewManager(limits token.ContextLimits, summarizer Summarizer) *Manager

NewManager creates a new context manager with the given limits and summarizer.

func NewManagerWithDefaults

func NewManagerWithDefaults(summarizer Summarizer) *Manager

NewManagerWithDefaults creates a context manager with default limits.

func (*Manager) Compact

func (m *Manager) Compact(ctx context.Context, messages []anthropic.MessageParam) (*CompactionResult, error)

Compact reduces the context size using the smart hybrid strategy: 1. Aggressively truncate tool results (keep only last N) 2. Summarize older conversation turns with Haiku 3. Preserve recent messages intact

func (*Manager) Limits

func (m *Manager) Limits() token.ContextLimits

Limits returns the context limits configuration.

func (*Manager) NeedsCompaction

func (m *Manager) NeedsCompaction(messages []anthropic.MessageParam) bool

NeedsCompaction checks if the messages exceed the summarization threshold.

func (*Manager) TokenCount

func (m *Manager) TokenCount(messages []anthropic.MessageParam) int

TokenCount returns the current token count for the given messages.

type Summarizer

type Summarizer interface {
	Summarize(ctx context.Context, messages []anthropic.MessageParam) (string, error)
}

Summarizer generates summaries of conversation segments using an LLM.

Jump to

Keyboard shortcuts

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