Documentation
¶
Index ¶
- type ActionRecord
- type CompressionStrategy
- type ExecutionMode
- type ExecutionRecord
- type ForgettingCurve
- type MemoryCompressor
- type MemoryIndex
- type MemoryItem
- type MemoryOptimizer
- type Option
- func WithContextEngineering(baseDir string, contextConfig contextmgmt.Config) Option
- func WithContextOptimization(level contextmgmt.CompressionPriority, maxTokens int, cacheTarget float64) Option
- func WithExecutionMode(mode ExecutionMode) Option
- func WithMaxIterations(max int) Option
- func WithMemoryOptimization(retention time.Duration, threshold float64) Option
- func WithNativeFunctionCalling(config interceptors.FunctionCallingConfig) Option
- func WithPlanning(strategy PlanningStrategy, maxDepth int) Option
- func WithProductionContextOptimization() 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) EnableNativeFunctionCalling(config *interceptors.FunctionCallingConfig) error
- 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) GetContextHealthStatus() map[string]interface{}
- func (r *ReActAgent) GetContextPerformanceMetrics() map[string]interface{}
- 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
// Context Engineering metrics
ContextVersion int64 `json:"context_version,omitempty"`
ContextResponse *contextmgmt.ContextResponse `json:"context_response,omitempty"`
OptimizationsApplied []string `json:"optimizations_applied,omitempty"`
CostSavings float64 `json:"cost_savings,omitempty"`
ProcessingTime time.Duration `json:"processing_time,omitempty"`
}
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 (*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 WithContextEngineering ¶
func WithContextEngineering(baseDir string, contextConfig contextmgmt.Config) Option
WithContextEngineering enables Manus-inspired context engineering for 10x cost reduction.
func WithContextOptimization ¶
func WithContextOptimization(level contextmgmt.CompressionPriority, maxTokens int, cacheTarget float64) Option
WithContextOptimization configures context optimization level.
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 WithNativeFunctionCalling ¶
func WithNativeFunctionCalling(config interceptors.FunctionCallingConfig) Option
WithNativeFunctionCalling enables native LLM function calling for tool selection. This uses the provider's built-in tool calling API instead of text-based parsing, which provides more reliable tool selection and eliminates parsing errors.
func WithPlanning ¶
func WithPlanning(strategy PlanningStrategy, maxDepth int) Option
WithPlanning configures planning.
func WithProductionContextOptimization ¶
func WithProductionContextOptimization() Option
WithProductionContextOptimization enables production-grade context optimization.
func WithReflection ¶
WithReflection enables or disables reflection.
func WithTimeout ¶
WithTimeout sets the execution timeout.
func WithXMLParsing ¶
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) EnableNativeFunctionCalling ¶
func (r *ReActAgent) EnableNativeFunctionCalling(config *interceptors.FunctionCallingConfig) error
EnableNativeFunctionCalling enables native LLM function calling on an already initialized agent. This allows enabling function calling after agent creation. If config is nil, uses the default configuration with the agent's tool registry.
func (*ReActAgent) EnableXMLParsing ¶
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) GetContextHealthStatus ¶
func (r *ReActAgent) GetContextHealthStatus() map[string]interface{}
GetContextHealthStatus returns health status of context management systems.
func (*ReActAgent) GetContextPerformanceMetrics ¶
func (r *ReActAgent) GetContextPerformanceMetrics() map[string]interface{}
GetContextPerformanceMetrics returns comprehensive context management metrics.
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
// Native function calling settings
EnableNativeFunctionCalling bool
FunctionCallingConfig *interceptors.FunctionCallingConfig
// Context Engineering settings (Manus-inspired patterns)
EnableContextEngineering bool `json:"enable_context_engineering"`
ContextConfig contextmgmt.Config `json:"context_config,omitempty"`
ContextBaseDir string `json:"context_base_dir"`
AutoTodoManagement bool `json:"auto_todo_management"`
AutoErrorLearning bool `json:"auto_error_learning"`
ContextOptLevel contextmgmt.CompressionPriority `json:"context_optimization_level"`
MaxContextTokens int `json:"max_context_tokens"`
CacheEfficiencyTarget float64 `json:"cache_efficiency_target"`
}
ReActAgentConfig configures the ReAct agent behavior.
func DefaultReActAgentConfig ¶
func DefaultReActAgentConfig() ReActAgentConfig
DefaultReActAgentConfig returns sensible defaults.
func ProductionReActAgentConfig ¶
func ProductionReActAgentConfig() ReActAgentConfig
ProductionReActAgentConfig returns a configuration optimized for production cost efficiency.
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 (thread-safe).
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 (thread-safe).
func (*SelfReflector) GetTopReflections ¶
func (sr *SelfReflector) GetTopReflections(n int) []Reflection
GetTopReflections returns the most confident reflections (thread-safe).
func (*SelfReflector) Reflect ¶
func (sr *SelfReflector) Reflect(ctx context.Context, record ExecutionRecord) []Reflection
Reflect analyzes an execution record and generates reflections.
func (*SelfReflector) Reset ¶
func (sr *SelfReflector) Reset()
Reset clears all reflection data (thread-safe).
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.