Documentation
¶
Index ¶
- type Adaptation
- type AdaptiveMiddleware
- type ContextEnricher
- type ContextEnrichmentMiddleware
- type DynamicPromptMiddleware
- type LLMToolEmulatorMiddleware
- type LLMToolSelectorMiddleware
- type ObservabilityMiddleware
- func (m *ObservabilityMiddleware) OnAfter(ctx context.Context, response *coremiddleware.MiddlewareResponse) (*coremiddleware.MiddlewareResponse, error)
- func (m *ObservabilityMiddleware) OnBefore(ctx context.Context, request *coremiddleware.MiddlewareRequest) (*coremiddleware.MiddlewareRequest, error)
- func (m *ObservabilityMiddleware) OnError(ctx context.Context, err error) error
- func (m *ObservabilityMiddleware) RecordLLMCall(ctx context.Context, model, provider string, tokens int, ...)
- func (m *ObservabilityMiddleware) RecordToolCall(ctx context.Context, toolName string, duration time.Duration, err error)
- type PerformanceMetrics
- type PromptGenerator
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
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 ¶
func (m *ContextEnrichmentMiddleware) AddEnricher(enricher ContextEnricher) *ContextEnrichmentMiddleware
AddEnricher adds a context enricher
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 ¶
func (m *DynamicPromptMiddleware) AddGenerator(generator PromptGenerator) *DynamicPromptMiddleware
AddGenerator adds a prompt generator
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 ¶
func (m *ObservabilityMiddleware) OnAfter(ctx context.Context, response *coremiddleware.MiddlewareResponse) (*coremiddleware.MiddlewareResponse, error)
OnAfter 请求后处理 - 记录结果和指标
func (*ObservabilityMiddleware) OnBefore ¶
func (m *ObservabilityMiddleware) OnBefore(ctx context.Context, request *coremiddleware.MiddlewareRequest) (*coremiddleware.MiddlewareRequest, error)
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