context

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextManager

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

ContextManager manages context windows for different models

func NewContextManager

func NewContextManager() *ContextManager

NewContextManager creates a new context manager

func (*ContextManager) CreateWindow

func (cm *ContextManager) CreateWindow(modelName string) *ContextWindow

CreateWindow creates a new context window for a model

func (*ContextManager) OptimizePrompt

func (cm *ContextManager) OptimizePrompt(
	window *ContextWindow,
	messages []prompt.Message,
	tools []prompt.Tool,
	systemPrompt string,
) (string, error)

OptimizePrompt optimizes a prompt to fit within the context window

type ContextWindow

type ContextWindow struct {
	MaxTokens      int
	CurrentTokens  int
	Messages       []Message
	Tools          []Tool
	SystemPrompt   string
	ReservedTokens int // Reserved for output generation
}

ContextWindow represents the context window state

func (*ContextWindow) GetStatistics

func (window *ContextWindow) GetStatistics() map[string]any

GetStatistics returns current window statistics

type Message

type Message struct {
	Role      string `json:"role"`
	Content   string `json:"content"`
	Tokens    int    `json:"tokens"`
	Timestamp int64  `json:"timestamp"`
	Priority  int    `json:"priority"` // Higher priority messages are kept longer
}

Message represents a conversation message with token count

type ModelContextConfig

type ModelContextConfig struct {
	ModelName        string
	MaxContextTokens int
	OutputReserve    int // Tokens reserved for output
	CompressionRatio float64
}

ModelContextConfig contains model-specific context configuration

type SimpleTokenEstimator

type SimpleTokenEstimator struct{}

SimpleTokenEstimator provides basic token estimation

func (*SimpleTokenEstimator) EstimateTokens

func (e *SimpleTokenEstimator) EstimateTokens(text string) int

type SummaryCache

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

SummaryCache caches conversation summaries

type TokenEstimator

type TokenEstimator interface {
	EstimateTokens(text string) int
}

TokenEstimator estimates token count for text

type Tool

type Tool struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Schema      map[string]any `json:"schema"`
	Tokens      int            `json:"tokens"`
	Essential   bool           `json:"essential"` // Essential tools are always included
}

Tool represents a tool with token count

Jump to

Keyboard shortcuts

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