middleware

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adaptation

type Adaptation struct {
	Name      string
	Condition func(*PerformanceMetrics) bool
	Apply     func(map[string]interface{})
}

Adaptation defines an adaptation rule

type AdaptiveMiddleware

type AdaptiveMiddleware struct {
	*coremiddleware.BaseMiddleware
	Metrics       *PerformanceMetrics
	Adaptations   []Adaptation
	CurrentConfig map[string]interface{}
	// contains filtered or unexported fields
}

AdaptiveMiddleware adapts behavior based on runtime performance

func NewAdaptiveMiddleware

func NewAdaptiveMiddleware() *AdaptiveMiddleware

NewAdaptiveMiddleware creates a new adaptive middleware

func (*AdaptiveMiddleware) AddAdaptation

func (m *AdaptiveMiddleware) AddAdaptation(adaptation Adaptation) *AdaptiveMiddleware

AddAdaptation adds an adaptation rule

func (*AdaptiveMiddleware) Process

func (m *AdaptiveMiddleware) Process(ctx context.Context, state core.State) (core.State, error)

Process applies adaptations based on performance

type ContextEnricher

type ContextEnricher struct {
	Name    string
	Enrich  func(context.Context, core.State) (map[string]interface{}, error)
	Async   bool
	Timeout time.Duration
}

ContextEnricher enriches context with additional data

type ContextEnrichmentMiddleware

type ContextEnrichmentMiddleware struct {
	*coremiddleware.BaseMiddleware
	Enrichers []ContextEnricher
	Cache     map[string]interface{}
	CacheTTL  time.Duration
	// contains filtered or unexported fields
}

ContextEnrichmentMiddleware enriches context with additional information

func NewContextEnrichmentMiddleware

func NewContextEnrichmentMiddleware() *ContextEnrichmentMiddleware

NewContextEnrichmentMiddleware creates a new context enrichment middleware

func (*ContextEnrichmentMiddleware) AddEnricher

AddEnricher adds a context enricher

func (*ContextEnrichmentMiddleware) Process

Process enriches the context with additional data

type DynamicPromptMiddleware

type DynamicPromptMiddleware struct {
	*coremiddleware.BaseMiddleware
	PromptGenerators []PromptGenerator
	// contains filtered or unexported fields
}

DynamicPromptMiddleware generates dynamic prompts based on runtime context

func NewDynamicPromptMiddleware

func NewDynamicPromptMiddleware() *DynamicPromptMiddleware

NewDynamicPromptMiddleware creates a new dynamic prompt middleware

func (*DynamicPromptMiddleware) AddGenerator

AddGenerator adds a prompt generator

func (*DynamicPromptMiddleware) Process

func (m *DynamicPromptMiddleware) Process(ctx context.Context, state core.State) (core.State, error)

Process generates dynamic prompts

type LLMToolEmulatorMiddleware

type LLMToolEmulatorMiddleware struct {
	*coremiddleware.BaseMiddleware
	Model         llm.Client
	EmulatedTools map[string]bool // Tools to emulate
	EmulateAll    bool            // Emulate all tools
	// contains filtered or unexported fields
}

LLMToolEmulatorMiddleware emulates tool execution using an LLM

func NewLLMToolEmulatorMiddleware

func NewLLMToolEmulatorMiddleware(model llm.Client) *LLMToolEmulatorMiddleware

NewLLMToolEmulatorMiddleware creates a new tool emulator

func (*LLMToolEmulatorMiddleware) Process

func (m *LLMToolEmulatorMiddleware) Process(ctx context.Context, state core.State) (core.State, error)

Process intercepts tool calls and emulates them

func (*LLMToolEmulatorMiddleware) SetEmulateAll

func (m *LLMToolEmulatorMiddleware) SetEmulateAll(emulateAll bool) *LLMToolEmulatorMiddleware

SetEmulateAll sets whether to emulate all tools

func (*LLMToolEmulatorMiddleware) SetEmulatedTools

func (m *LLMToolEmulatorMiddleware) SetEmulatedTools(tools ...string) *LLMToolEmulatorMiddleware

SetEmulatedTools sets which tools to emulate

type LLMToolSelectorMiddleware

type LLMToolSelectorMiddleware struct {
	*coremiddleware.BaseMiddleware
	Model          llm.Client          // Cheaper model for selection
	MaxTools       int                 // Maximum tools to select
	AlwaysInclude  []string            // Tools to always include
	SelectionCache map[string][]string // Cache for tool selections
	CacheTTL       time.Duration
	// contains filtered or unexported fields
}

LLMToolSelectorMiddleware intelligently selects relevant tools using an LLM

func NewLLMToolSelectorMiddleware

func NewLLMToolSelectorMiddleware(model llm.Client, maxTools int) *LLMToolSelectorMiddleware

NewLLMToolSelectorMiddleware creates a new tool selector middleware

func (*LLMToolSelectorMiddleware) Process

func (m *LLMToolSelectorMiddleware) Process(ctx context.Context, state core.State) (core.State, error)

Process selects relevant tools before the main model call

func (*LLMToolSelectorMiddleware) WithAlwaysInclude

func (m *LLMToolSelectorMiddleware) WithAlwaysInclude(tools ...string) *LLMToolSelectorMiddleware

WithAlwaysInclude sets tools that should always be included

type ObservabilityMiddleware

type ObservabilityMiddleware struct {
	*coremiddleware.BaseMiddleware
	// contains filtered or unexported fields
}

ObservabilityMiddleware 可观测性中间件 集成 OpenTelemetry 追踪和指标

func NewObservabilityMiddleware

func NewObservabilityMiddleware(provider *observability.TelemetryProvider) (*ObservabilityMiddleware, error)

NewObservabilityMiddleware 创建可观测性中间件

func (*ObservabilityMiddleware) OnAfter

OnAfter 请求后处理 - 记录结果和指标

func (*ObservabilityMiddleware) OnBefore

OnBefore 请求前处理 - 启动 span 和记录指标

func (*ObservabilityMiddleware) OnError

func (m *ObservabilityMiddleware) OnError(ctx context.Context, err error) error

OnError 错误处理 - 记录错误到 span 和指标

func (*ObservabilityMiddleware) RecordLLMCall

func (m *ObservabilityMiddleware) RecordLLMCall(ctx context.Context, model, provider string, tokens int, duration time.Duration, err error)

RecordLLMCall 记录 LLM 调用 (辅助方法)

func (*ObservabilityMiddleware) RecordToolCall

func (m *ObservabilityMiddleware) RecordToolCall(ctx context.Context, toolName string, duration time.Duration, err error)

RecordToolCall 记录工具调用 (辅助方法)

type PerformanceMetrics

type PerformanceMetrics struct {
	ResponseTimes  []time.Duration
	ErrorRates     []float64
	TokenUsage     []int
	SuccessRate    float64
	AverageLatency time.Duration
	// contains filtered or unexported fields
}

PerformanceMetrics tracks performance metrics

func NewPerformanceMetrics

func NewPerformanceMetrics() *PerformanceMetrics

NewPerformanceMetrics creates new performance metrics

type PromptGenerator

type PromptGenerator struct {
	Name      string
	Priority  int
	Condition func(core.State) bool
	Generate  func(core.State) string
}

PromptGenerator generates prompts based on context

Jump to

Keyboard shortcuts

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