Help us shape the future of Go! Take the 2026 Go Developer Survey

context

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdditionalContextText added in v1.11.0

func AdditionalContextText(values map[string]any) string

Types

type AgentContextConfig

type AgentContextConfig struct {
	Enabled              bool     `json:"enabled"`
	MaxContextTokens     int      `json:"max_context_tokens"`
	ReserveForOutput     int      `json:"reserve_for_output"`
	SoftLimit            float64  `json:"soft_limit"`
	WarnLimit            float64  `json:"warn_limit"`
	HardLimit            float64  `json:"hard_limit"`
	TargetUsage          float64  `json:"target_usage"`
	KeepSystem           bool     `json:"keep_system"`
	KeepLastN            int      `json:"keep_last_n"`
	EnableSummarize      bool     `json:"enable_summarize"`
	EnableMetrics        bool     `json:"enable_metrics"`
	MemoryBudgetRatio    float64  `json:"memory_budget_ratio"`
	RetrievalBudgetRatio float64  `json:"retrieval_budget_ratio"`
	ToolStateBudgetRatio float64  `json:"tool_state_budget_ratio"`
	Strategy             Strategy `json:"strategy"`
}

AgentContextConfig configures the context runtime.

func ConfigFromAgentConfig added in v1.11.0

func ConfigFromAgentConfig(cfg types.AgentConfig) AgentContextConfig

func DefaultAgentContextConfig

func DefaultAgentContextConfig(modelFamily string) AgentContextConfig

type AgentContextManager

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

AgentContextManager is the standard context orchestration component used by agents.

func NewAgentContextManager

func NewAgentContextManager(cfg AgentContextConfig, logger *zap.Logger) *AgentContextManager

func (*AgentContextManager) Assemble added in v1.11.0

func (*AgentContextManager) CanAddMessage

func (m *AgentContextManager) CanAddMessage(messages []types.Message, newMsg types.Message) bool

func (*AgentContextManager) EstimateTokens

func (m *AgentContextManager) EstimateTokens(messages []types.Message) int

func (*AgentContextManager) GetRecommendation

func (m *AgentContextManager) GetRecommendation(messages []types.Message) string

func (*AgentContextManager) GetStats

func (m *AgentContextManager) GetStats() Stats

func (*AgentContextManager) GetStatus

func (m *AgentContextManager) GetStatus(messages []types.Message) Status

func (*AgentContextManager) PrepareMessages

func (m *AgentContextManager) PrepareMessages(ctx context.Context, messages []types.Message, currentQuery string) ([]types.Message, error)

func (*AgentContextManager) SetSummaryProvider

func (m *AgentContextManager) SetSummaryProvider(fn func(context.Context, []types.Message) (string, error))

func (*AgentContextManager) ShouldCompress

func (m *AgentContextManager) ShouldCompress(messages []types.Message) bool

type AssembleRequest added in v1.11.0

type AssembleRequest struct {
	SystemPrompt      string
	AdditionalContext map[string]any
	EphemeralLayers   []PromptLayer
	SkillContext      []string
	MemoryContext     []string
	Conversation      []types.Message
	Retrieval         []RetrievalItem
	ToolState         []ToolState
	UserInput         string
	Query             string
}

type AssembleResult added in v1.11.0

type AssembleResult struct {
	Messages           []types.Message  `json:"messages"`
	SegmentsKept       []ContextSegment `json:"segments_kept,omitempty"`
	SegmentsDropped    []ContextSegment `json:"segments_dropped,omitempty"`
	SegmentsSummarized []ContextSegment `json:"segments_summarized,omitempty"`
	TokensBefore       int              `json:"tokens_before"`
	TokensAfter        int              `json:"tokens_after"`
	Plan               ContextPlan      `json:"plan"`
}

type Assembler added in v1.11.0

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

func (*Assembler) Assemble added in v1.11.0

func (a *Assembler) Assemble(ctx context.Context, req *AssembleRequest) (*AssembleResult, error)

type ContextPlan added in v1.11.0

type ContextPlan struct {
	Budget            int                 `json:"budget"`
	Used              int                 `json:"used"`
	Strategy          string              `json:"strategy"`
	CompressionReason string              `json:"compression_reason,omitempty"`
	Breakdown         map[SegmentType]int `json:"breakdown,omitempty"`
	AppliedLayers     []PromptLayerMeta   `json:"applied_layers,omitempty"`
}

type ContextSegment added in v1.11.0

type ContextSegment struct {
	ID        string
	Type      SegmentType
	Role      types.Role
	Content   string
	Source    string
	Priority  int
	Sticky    bool
	TokenCost int
	Metadata  map[string]any
}

type Level

type Level int
const (
	LevelNone Level = iota
	LevelNormal
	LevelAggressive
	LevelEmergency
)

func (Level) String

func (l Level) String() string

type PromptLayer added in v1.11.0

type PromptLayer struct {
	ID       string
	Type     SegmentType
	Role     types.Role
	Content  string
	Priority int
	Sticky   bool
	Metadata map[string]any
}

type PromptLayerMeta added in v1.11.0

type PromptLayerMeta struct {
	ID        string         `json:"id"`
	Type      SegmentType    `json:"type"`
	Priority  int            `json:"priority,omitempty"`
	Sticky    bool           `json:"sticky,omitempty"`
	TokenCost int            `json:"token_cost,omitempty"`
	Metadata  map[string]any `json:"metadata,omitempty"`
}

type RetrievalItem added in v1.11.0

type RetrievalItem struct {
	Title   string
	Content string
	Source  string
	Score   float64
}

type SegmentType added in v1.11.0

type SegmentType string
const (
	SegmentSystem       SegmentType = "system"
	SegmentEphemeral    SegmentType = "ephemeral"
	SegmentSkill        SegmentType = "skill"
	SegmentMemory       SegmentType = "memory"
	SegmentConversation SegmentType = "conversation"
	SegmentRetrieval    SegmentType = "retrieval"
	SegmentToolState    SegmentType = "tool_state"
	SegmentInput        SegmentType = "input"
	SegmentSummary      SegmentType = "summary"
)

type Stats

type Stats struct {
	TotalCompressions   int64   `json:"total_compressions"`
	EmergencyCount      int64   `json:"emergency_count"`
	AvgCompressionRatio float64 `json:"avg_compression_ratio"`
	TokensSaved         int64   `json:"tokens_saved"`
}

type Status

type Status struct {
	CurrentTokens  int     `json:"current_tokens"`
	MaxTokens      int     `json:"max_tokens"`
	UsageRatio     float64 `json:"usage_ratio"`
	Level          Level   `json:"level"`
	Recommendation string  `json:"recommendation"`
}

type Strategy

type Strategy string
const (
	StrategyAdaptive   Strategy = "adaptive"
	StrategySummary    Strategy = "summary"
	StrategyPruning    Strategy = "pruning"
	StrategySliding    Strategy = "sliding"
	StrategyAggressive Strategy = "aggressive"
)

type ToolState added in v1.11.0

type ToolState struct {
	ToolName   string
	Summary    string
	ArtifactID string
}

Jump to

Keyboard shortcuts

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