Documentation
ΒΆ
Index ΒΆ
- type ActionRecord
- type CompressionStrategy
- type ExecutionMode
- type ExecutionRecord
- type ForgettingCurve
- type MemoryCompressor
- type MemoryIndex
- type MemoryItem
- type MemoryOptimizer
- type Option
- func WithExecutionMode(mode ExecutionMode) Option
- func WithMaxIterations(max int) Option
- func WithMemoryOptimization(retention time.Duration, threshold float64) Option
- func WithPlanning(strategy PlanningStrategy, maxDepth int) Option
- func WithReflection(enabled bool, depth int) Option
- func WithTimeout(timeout time.Duration) Option
- func WithXMLParsing(config interceptors.XMLConfig) Option
- type Pattern
- type PerformanceMetrics
- type Plan
- type PlanStep
- type PlanStepTemplate
- type PlanTemplate
- type PlanTemplateLibrary
- type PlanningStrategy
- type ReActAgent
- func (r *ReActAgent) ClearInterceptors()
- func (r *ReActAgent) EnableXMLParsing(config interceptors.XMLConfig) error
- func (r *ReActAgent) Execute(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error)
- func (r *ReActAgent) ExecuteWithInterceptors(ctx context.Context, input map[string]interface{}, ...) (map[string]interface{}, error)
- func (r *ReActAgent) GetAgentID() string
- func (r *ReActAgent) GetAgentType() string
- func (r *ReActAgent) GetCapabilities() []core.Tool
- func (r *ReActAgent) GetExecutionHistory() []ExecutionRecord
- func (r *ReActAgent) GetInterceptors() []core.AgentInterceptor
- func (r *ReActAgent) GetMemory() agents.Memory
- func (r *ReActAgent) Initialize(llm core.LLM, signature core.Signature) error
- func (r *ReActAgent) RegisterTool(tool core.Tool) error
- func (r *ReActAgent) SetInterceptors(interceptors []core.AgentInterceptor)
- type ReActAgentConfig
- type Reflection
- type ReflectionType
- type SelfReflector
- func (sr *SelfReflector) CalculateImprovement(windowSize int) float64
- func (sr *SelfReflector) GetMetrics() *PerformanceMetrics
- func (sr *SelfReflector) GetPatterns() map[string]*Pattern
- func (sr *SelfReflector) GetTopReflections(n int) []Reflection
- func (sr *SelfReflector) Reflect(ctx context.Context, record ExecutionRecord) []Reflection
- func (sr *SelfReflector) Reset()
- type TaskDecomposer
- type TaskPlanner
- type ToolStats
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type ActionRecord ΒΆ
type ActionRecord struct {
Thought string
Action string
Tool string
Arguments map[string]interface{}
Observation string
Success bool
Duration time.Duration
}
ActionRecord tracks individual actions taken.
type CompressionStrategy ΒΆ
type CompressionStrategy int
CompressionStrategy defines how memory is compressed.
const ( // CompressionSummarize creates summaries of similar memories. CompressionSummarize CompressionStrategy = iota // CompressionMerge merges similar memories. CompressionMerge // CompressionPrune removes low-importance memories. CompressionPrune )
type ExecutionMode ΒΆ
type ExecutionMode int
ExecutionMode defines how the agent executes tasks.
const ( // ModeReAct uses classic ReAct loop (Thought -> Action -> Observation). ModeReAct ExecutionMode = iota // ModeReWOO uses Reasoning Without Observation (plan-then-execute). ModeReWOO // ModeHybrid adaptively switches between ReAct and ReWOO. ModeHybrid )
type ExecutionRecord ΒΆ
type ExecutionRecord struct {
Timestamp time.Time
Input map[string]interface{}
Output map[string]interface{}
Actions []ActionRecord
Success bool
Error error
Reflections []string
}
ExecutionRecord tracks execution history for reflection.
type ForgettingCurve ΒΆ
type ForgettingCurve struct {
// contains filtered or unexported fields
}
ForgettingCurve implements Ebbinghaus forgetting curve.
func NewForgettingCurve ΒΆ
func NewForgettingCurve() *ForgettingCurve
NewForgettingCurve creates a new forgetting curve calculator.
type MemoryCompressor ΒΆ
type MemoryCompressor struct {
// contains filtered or unexported fields
}
MemoryCompressor reduces memory footprint.
func NewMemoryCompressor ΒΆ
func NewMemoryCompressor() *MemoryCompressor
NewMemoryCompressor creates a new memory compressor.
type MemoryIndex ΒΆ
type MemoryIndex struct {
// contains filtered or unexported fields
}
MemoryIndex provides fast access to memory items.
func NewMemoryIndex ΒΆ
func NewMemoryIndex() *MemoryIndex
NewMemoryIndex creates a new memory index.
func (*MemoryIndex) Add ΒΆ
func (mi *MemoryIndex) Add(item *MemoryItem)
Add adds an item to the index.
func (*MemoryIndex) Get ΒΆ
func (mi *MemoryIndex) Get(key string) (*MemoryItem, bool)
Get retrieves an item from the index.
func (*MemoryIndex) GetByCategory ΒΆ
func (mi *MemoryIndex) GetByCategory(category string) []*MemoryItem
GetByCategory retrieves items by category.
func (*MemoryIndex) Remove ΒΆ
func (mi *MemoryIndex) Remove(key string)
Remove removes an item from the index.
func (*MemoryIndex) Size ΒΆ
func (mi *MemoryIndex) Size() int
Size returns the number of items in the index.
type MemoryItem ΒΆ
type MemoryItem struct {
Key string
Value interface{}
Category string
Importance float64
AccessCount int
LastAccessed time.Time
Created time.Time
Embedding []float64 // For semantic similarity
Hash string
}
MemoryItem represents an item in memory.
type MemoryOptimizer ΒΆ
type MemoryOptimizer struct {
// contains filtered or unexported fields
}
MemoryOptimizer implements memory optimization with forgetting curve.
func NewMemoryOptimizer ΒΆ
func NewMemoryOptimizer(retention time.Duration, threshold float64) *MemoryOptimizer
NewMemoryOptimizer creates a new memory optimizer.
func NewMemoryOptimizerWithCompressionThreshold ΒΆ
func NewMemoryOptimizerWithCompressionThreshold(retention time.Duration, threshold float64, compressionThreshold int) *MemoryOptimizer
NewMemoryOptimizerWithCompressionThreshold creates a new memory optimizer with configurable compression threshold.
func (*MemoryOptimizer) GetStatistics ΒΆ
func (mo *MemoryOptimizer) GetStatistics() map[string]interface{}
GetStatistics returns memory statistics.
type Option ΒΆ
type Option func(*ReActAgentConfig)
Option configures a ReActAgent.
func WithExecutionMode ΒΆ
func WithExecutionMode(mode ExecutionMode) Option
WithExecutionMode sets the execution mode.
func WithMaxIterations ΒΆ
WithMaxIterations sets the maximum iterations.
func WithMemoryOptimization ΒΆ
WithMemoryOptimization enables memory optimization.
func WithPlanning ΒΆ
func WithPlanning(strategy PlanningStrategy, maxDepth int) Option
WithPlanning configures planning.
func WithReflection ΒΆ
WithReflection enables or disables reflection.
func WithTimeout ΒΆ
WithTimeout sets the execution timeout.
func WithXMLParsing ΒΆ added in v0.54.0
func WithXMLParsing(config interceptors.XMLConfig) Option
WithXMLParsing enables XML interceptor-based parsing for tool actions. This provides enhanced XML validation, security features, and error handling.
type Pattern ΒΆ
type Pattern struct {
Name string
Occurrences int
SuccessRate float64
LastSeen time.Time
Context map[string]interface{}
}
Pattern represents a recurring pattern in agent behavior.
type PerformanceMetrics ΒΆ
type PerformanceMetrics struct {
TotalExecutions int
SuccessfulRuns int
FailedRuns int
AverageIterations float64
AverageDuration time.Duration
ToolUsageStats map[string]*ToolStats
ErrorPatterns map[string]int
}
PerformanceMetrics tracks agent performance over time.
type Plan ΒΆ
type Plan struct {
ID string
Goal string
Steps []PlanStep
Strategy PlanningStrategy
CreatedAt time.Time
EstimatedDuration time.Duration
Dependencies map[string][]string // step dependencies
}
Plan represents a structured plan for task execution.
type PlanStep ΒΆ
type PlanStep struct {
ID string
Description string
Tool string
Arguments map[string]interface{}
Expected string // expected outcome
Critical bool // if true, failure stops execution
Parallel bool // can be executed in parallel
DependsOn []string // IDs of steps this depends on
Timeout time.Duration
}
PlanStep represents a single step in a plan.
type PlanStepTemplate ΒΆ
type PlanStepTemplate struct {
Description string
ToolType string
ArgumentsFunc func(map[string]interface{}) map[string]interface{}
Critical bool
}
PlanStepTemplate is a template for a plan step.
type PlanTemplate ΒΆ
type PlanTemplate struct {
Name string
TaskPattern string // regex or keyword pattern
Steps []PlanStepTemplate
SuccessRate float64
LastUsed time.Time
}
PlanTemplate is a reusable plan structure.
type PlanTemplateLibrary ΒΆ
type PlanTemplateLibrary struct {
// contains filtered or unexported fields
}
PlanTemplateLibrary stores reusable plan templates.
func NewPlanTemplateLibrary ΒΆ
func NewPlanTemplateLibrary() *PlanTemplateLibrary
NewPlanTemplateLibrary creates a new plan template library with common templates.
func (*PlanTemplateLibrary) AddTemplate ΒΆ
func (ptl *PlanTemplateLibrary) AddTemplate(template *PlanTemplate)
AddTemplate adds a plan template to the library.
func (*PlanTemplateLibrary) FindTemplate ΒΆ
func (ptl *PlanTemplateLibrary) FindTemplate(task string) *PlanTemplate
FindTemplate finds a matching template for a task.
type PlanningStrategy ΒΆ
type PlanningStrategy int
PlanningStrategy defines how the agent plans tasks.
const ( // DecompositionFirst breaks down tasks upfront before execution. DecompositionFirst PlanningStrategy = iota // Interleaved adapts the plan during execution. Interleaved )
type ReActAgent ΒΆ
type ReActAgent struct {
// Modern patterns
Reflector *SelfReflector
Planner *TaskPlanner
Optimizer *MemoryOptimizer
// contains filtered or unexported fields
}
ReActAgent implements a generic ReAct-based agent with modern patterns.
func NewReActAgent ΒΆ
func NewReActAgent(id, name string, opts ...Option) *ReActAgent
NewReActAgent creates a new ReAct agent with modern patterns.
func (*ReActAgent) ClearInterceptors ΒΆ
func (r *ReActAgent) ClearInterceptors()
ClearInterceptors removes all interceptors.
func (*ReActAgent) EnableXMLParsing ΒΆ added in v0.54.0
func (r *ReActAgent) EnableXMLParsing(config interceptors.XMLConfig) error
EnableXMLParsing enables XML interceptor-based parsing on an already initialized agent. This allows enabling XML parsing after agent creation.
func (*ReActAgent) Execute ΒΆ
func (r *ReActAgent) Execute(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error)
Execute runs the agent's task with given input.
func (*ReActAgent) ExecuteWithInterceptors ΒΆ
func (r *ReActAgent) ExecuteWithInterceptors(ctx context.Context, input map[string]interface{}, interceptors []core.AgentInterceptor) (map[string]interface{}, error)
ExecuteWithInterceptors runs the agent with interceptor support.
func (*ReActAgent) GetAgentID ΒΆ
func (r *ReActAgent) GetAgentID() string
GetAgentID returns the unique identifier for this agent.
func (*ReActAgent) GetAgentType ΒΆ
func (r *ReActAgent) GetAgentType() string
GetAgentType returns the type of this agent.
func (*ReActAgent) GetCapabilities ΒΆ
func (r *ReActAgent) GetCapabilities() []core.Tool
GetCapabilities returns the tools/capabilities available to this agent.
func (*ReActAgent) GetExecutionHistory ΒΆ
func (r *ReActAgent) GetExecutionHistory() []ExecutionRecord
GetExecutionHistory returns the execution history for analysis.
func (*ReActAgent) GetInterceptors ΒΆ
func (r *ReActAgent) GetInterceptors() []core.AgentInterceptor
GetInterceptors returns the current interceptors.
func (*ReActAgent) GetMemory ΒΆ
func (r *ReActAgent) GetMemory() agents.Memory
GetMemory returns the agent's memory store.
func (*ReActAgent) Initialize ΒΆ
Initialize sets up the agent with an LLM and creates the ReAct module.
func (*ReActAgent) RegisterTool ΒΆ
func (r *ReActAgent) RegisterTool(tool core.Tool) error
RegisterTool adds a tool to the agent's registry.
func (*ReActAgent) SetInterceptors ΒΆ
func (r *ReActAgent) SetInterceptors(interceptors []core.AgentInterceptor)
SetInterceptors sets the default interceptors for this agent.
type ReActAgentConfig ΒΆ
type ReActAgentConfig struct {
// Core settings
MaxIterations int
ExecutionMode ExecutionMode
Timeout time.Duration
// Memory settings
MemoryRetention time.Duration
ForgetThreshold float64
EnableMemoryOpt bool
// Reflection settings
EnableReflection bool
ReflectionDepth int
ReflectionDelay time.Duration
// Planning settings
PlanningStrategy PlanningStrategy
MaxPlanDepth int
EnablePlanning bool
// Tool settings
ToolTimeout time.Duration
ParallelTools bool
MaxToolRetries int
// Interceptor settings
EnableInterceptors bool
// XML parsing settings
EnableXMLParsing bool
XMLConfig *interceptors.XMLConfig
}
ReActAgentConfig configures the ReAct agent behavior.
func DefaultReActAgentConfig ΒΆ
func DefaultReActAgentConfig() ReActAgentConfig
DefaultReActAgentConfig returns sensible defaults.
type Reflection ΒΆ
type Reflection struct {
Type ReflectionType
Insight string
Confidence float64
Recommendation string
Evidence []string
Timestamp time.Time
}
Reflection represents an insight gained from analyzing past executions.
type ReflectionType ΒΆ
type ReflectionType int
ReflectionType categorizes different types of reflections.
const ( // ReflectionTypeStrategy reflects on overall strategy effectiveness. ReflectionTypeStrategy ReflectionType = iota // ReflectionTypePerformance reflects on performance metrics. ReflectionTypePerformance // ReflectionTypeLearning reflects on learned patterns. ReflectionTypeLearning // ReflectionTypeError reflects on errors and failures. ReflectionTypeError )
type SelfReflector ΒΆ
type SelfReflector struct {
// contains filtered or unexported fields
}
SelfReflector implements self-reflection capabilities for agents.
func NewSelfReflector ΒΆ
func NewSelfReflector(depth int, delay time.Duration) *SelfReflector
NewSelfReflector creates a new self-reflection module.
func NewSelfReflectorWithThreshold ΒΆ
func NewSelfReflectorWithThreshold(depth int, delay time.Duration, successRateThreshold float64) *SelfReflector
NewSelfReflectorWithThreshold creates a new self-reflection module with configurable success rate threshold.
func (*SelfReflector) CalculateImprovement ΒΆ
func (sr *SelfReflector) CalculateImprovement(windowSize int) float64
CalculateImprovement compares metrics over time windows.
func (*SelfReflector) GetMetrics ΒΆ
func (sr *SelfReflector) GetMetrics() *PerformanceMetrics
GetMetrics returns current performance metrics.
func (*SelfReflector) GetPatterns ΒΆ
func (sr *SelfReflector) GetPatterns() map[string]*Pattern
GetPatterns returns identified patterns.
func (*SelfReflector) GetTopReflections ΒΆ
func (sr *SelfReflector) GetTopReflections(n int) []Reflection
GetTopReflections returns the most confident reflections.
func (*SelfReflector) Reflect ΒΆ
func (sr *SelfReflector) Reflect(ctx context.Context, record ExecutionRecord) []Reflection
Reflect analyzes an execution record and generates reflections.
type TaskDecomposer ΒΆ
type TaskDecomposer struct {
// contains filtered or unexported fields
}
TaskDecomposer breaks down complex tasks into subtasks.
func NewTaskDecomposer ΒΆ
func NewTaskDecomposer(maxDepth int) *TaskDecomposer
NewTaskDecomposer creates a new task decomposer.
type TaskPlanner ΒΆ
type TaskPlanner struct {
// contains filtered or unexported fields
}
TaskPlanner implements task planning and decomposition.
func NewTaskPlanner ΒΆ
func NewTaskPlanner(strategy PlanningStrategy, maxDepth int) *TaskPlanner
NewTaskPlanner creates a new task planner.
func (*TaskPlanner) CreatePlan ΒΆ
func (tp *TaskPlanner) CreatePlan(ctx context.Context, input map[string]interface{}, tools []core.Tool) (*Plan, error)
CreatePlan creates an execution plan for a task.
func (*TaskPlanner) GetPlanMetrics ΒΆ
func (tp *TaskPlanner) GetPlanMetrics(plan *Plan) map[string]interface{}
GetPlanMetrics returns metrics about a plan.
func (*TaskPlanner) ValidatePlan ΒΆ
func (tp *TaskPlanner) ValidatePlan(plan *Plan) error
ValidatePlan checks if a plan is valid and executable.