Documentation
¶
Index ¶
- func NewCachedSupervisorAgent(llm llm.Client, config *SupervisorConfig) core.Agent
- type AgentRouter
- type AggregationStrategy
- type CapabilityRouter
- func (r *CapabilityRouter) GetCapabilities(agentName string) []string
- func (r *CapabilityRouter) RegisterAgent(name string, capabilities []string, matcher func(Task) float64)
- func (r *CapabilityRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
- func (r *CapabilityRouter) UpdateRouting(agentName string, performance float64)
- type ExecutionPlan
- type ExecutionStage
- type HybridRouter
- func (h *HybridRouter) AddStrategy(router AgentRouter, weight float64)
- func (h *HybridRouter) GetCapabilities(agentName string) []string
- func (h *HybridRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
- func (h *HybridRouter) UpdateRouting(agentName string, performance float64)
- type LLMRouter
- func (r *LLMRouter) GetCapabilities(agentName string) []string
- func (r *LLMRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
- func (r *LLMRouter) SetCapabilities(agentName string, capabilities []string)
- func (r *LLMRouter) UpdateRouting(agentName string, performance float64)
- type LoadBalancingRouter
- func (r *LoadBalancingRouter) GetCapabilities(agentName string) []string
- func (r *LoadBalancingRouter) GetLoad(agentName string) int32
- func (r *LoadBalancingRouter) ReleaseTask(agentName string)
- func (r *LoadBalancingRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
- func (r *LoadBalancingRouter) UpdateRouting(agentName string, performance float64)
- type RandomRouter
- type ResultAggregator
- type RoundRobinRouter
- type RoutingRule
- type RoutingStrategy
- type RuleBasedRouter
- func (r *RuleBasedRouter) AddRule(rule RoutingRule)
- func (r *RuleBasedRouter) GetCapabilities(agentName string) []string
- func (r *RuleBasedRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
- func (r *RuleBasedRouter) UpdateRouting(agentName string, performance float64)
- type SupervisorAgent
- func (s *SupervisorAgent) AddSubAgent(name string, agent core.Agent) *SupervisorAgent
- func (s *SupervisorAgent) GetMetrics() map[string]interface{}
- func (s *SupervisorAgent) Invoke(ctx context.Context, input *core.AgentInput) (*core.AgentOutput, error)
- func (s *SupervisorAgent) RemoveSubAgent(name string)
- type SupervisorConfig
- type SupervisorMetrics
- type Task
- type TaskOrchestrator
- type TaskResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCachedSupervisorAgent ¶
func NewCachedSupervisorAgent(llm llm.Client, config *SupervisorConfig) core.Agent
NewCachedSupervisorAgent creates a supervisor agent with caching enabled This wraps a SupervisorAgent with performance.CachedAgent for automatic result caching. Cached supervisors are ideal for scenarios with repeated task patterns or queries.
Example:
config := agents.DefaultSupervisorConfig()
config.CacheConfig = &performance.CacheConfig{
TTL: 10 * time.Minute,
MaxSize: 1000,
}
cachedSupervisor := agents.NewCachedSupervisorAgent(llmClient, config)
Types ¶
type AgentRouter ¶
type AgentRouter interface {
Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
GetCapabilities(agentName string) []string
UpdateRouting(agentName string, performance float64)
}
AgentRouter decides which sub-agent to use for a task
type AggregationStrategy ¶
type AggregationStrategy string
AggregationStrategy defines how results are aggregated
const ( StrategyMerge AggregationStrategy = "merge" // Merge all results StrategyBest AggregationStrategy = "best" // Select best result StrategyConsensus AggregationStrategy = "consensus" // Majority vote StrategyHierarchy AggregationStrategy = "hierarchy" // Hierarchical aggregation )
type CapabilityRouter ¶
type CapabilityRouter struct {
// contains filtered or unexported fields
}
CapabilityRouter routes based on agent capabilities
func NewCapabilityRouter ¶
func NewCapabilityRouter() *CapabilityRouter
NewCapabilityRouter creates a new capability-based router
func (*CapabilityRouter) GetCapabilities ¶
func (r *CapabilityRouter) GetCapabilities(agentName string) []string
GetCapabilities returns the capabilities of an agent
func (*CapabilityRouter) RegisterAgent ¶
func (r *CapabilityRouter) RegisterAgent(name string, capabilities []string, matcher func(Task) float64)
RegisterAgent registers an agent with its capabilities and matcher
func (*CapabilityRouter) Route ¶
func (r *CapabilityRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
Route selects the agent with the best capability match
func (*CapabilityRouter) UpdateRouting ¶
func (r *CapabilityRouter) UpdateRouting(agentName string, performance float64)
UpdateRouting updates the performance score for an agent
type ExecutionPlan ¶
type ExecutionPlan struct {
Stages []ExecutionStage `json:"stages"`
}
ExecutionPlan represents a plan for executing tasks
type ExecutionStage ¶
type ExecutionStage struct {
ID string `json:"id"`
Tasks []Task `json:"tasks"`
Sequential bool `json:"sequential"`
}
ExecutionStage represents a stage in the execution plan
type HybridRouter ¶
type HybridRouter struct {
// contains filtered or unexported fields
}
HybridRouter combines multiple routing strategies
func NewHybridRouter ¶
func NewHybridRouter(fallback AgentRouter) *HybridRouter
NewHybridRouter creates a new hybrid router
func (*HybridRouter) AddStrategy ¶
func (h *HybridRouter) AddStrategy(router AgentRouter, weight float64)
AddStrategy adds a routing strategy with a weight
func (*HybridRouter) GetCapabilities ¶
func (h *HybridRouter) GetCapabilities(agentName string) []string
GetCapabilities returns the capabilities of an agent
func (*HybridRouter) Route ¶
func (h *HybridRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
Route uses weighted voting from multiple strategies
func (*HybridRouter) UpdateRouting ¶
func (h *HybridRouter) UpdateRouting(agentName string, performance float64)
UpdateRouting updates routing information across all strategies
type LLMRouter ¶
type LLMRouter struct {
// contains filtered or unexported fields
}
LLMRouter uses an LLM to route tasks to agents
func NewLLMRouter ¶
NewLLMRouter creates a new LLM-based router
func (*LLMRouter) GetCapabilities ¶
GetCapabilities returns the capabilities of an agent
func (*LLMRouter) Route ¶
func (r *LLMRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
Route uses LLM to decide which agent should handle the task
func (*LLMRouter) SetCapabilities ¶
SetCapabilities sets the capabilities for an agent
func (*LLMRouter) UpdateRouting ¶
UpdateRouting updates the performance score for an agent
type LoadBalancingRouter ¶
type LoadBalancingRouter struct {
// contains filtered or unexported fields
}
LoadBalancingRouter distributes tasks based on current load
func NewLoadBalancingRouter ¶
func NewLoadBalancingRouter(maxTasksPerAgent int32) *LoadBalancingRouter
NewLoadBalancingRouter creates a new load-balancing router
func (*LoadBalancingRouter) GetCapabilities ¶
func (r *LoadBalancingRouter) GetCapabilities(agentName string) []string
GetCapabilities returns the capabilities of an agent
func (*LoadBalancingRouter) GetLoad ¶
func (r *LoadBalancingRouter) GetLoad(agentName string) int32
GetLoad returns the current load for an agent
func (*LoadBalancingRouter) ReleaseTask ¶
func (r *LoadBalancingRouter) ReleaseTask(agentName string)
ReleaseTask decrements the task count for an agent
func (*LoadBalancingRouter) Route ¶
func (r *LoadBalancingRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
Route selects the agent with the lowest current load
func (*LoadBalancingRouter) UpdateRouting ¶
func (r *LoadBalancingRouter) UpdateRouting(agentName string, performance float64)
UpdateRouting updates the performance score for an agent
type RandomRouter ¶
type RandomRouter struct {
// contains filtered or unexported fields
}
RandomRouter randomly selects an agent
func NewRandomRouter ¶
func NewRandomRouter() *RandomRouter
NewRandomRouter creates a new random router
func (*RandomRouter) GetCapabilities ¶
func (r *RandomRouter) GetCapabilities(agentName string) []string
GetCapabilities returns the capabilities of an agent
func (*RandomRouter) Route ¶
func (r *RandomRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
Route randomly selects an agent
func (*RandomRouter) UpdateRouting ¶
func (r *RandomRouter) UpdateRouting(agentName string, performance float64)
UpdateRouting updates the performance score for an agent
type ResultAggregator ¶
type ResultAggregator struct {
// contains filtered or unexported fields
}
ResultAggregator aggregates results from multiple agents
func NewResultAggregator ¶
func NewResultAggregator(strategy AggregationStrategy) *ResultAggregator
NewResultAggregator creates a new result aggregator
func (*ResultAggregator) Aggregate ¶
func (a *ResultAggregator) Aggregate(results []TaskResult) interface{}
Aggregate combines multiple task results
type RoundRobinRouter ¶
type RoundRobinRouter struct {
// contains filtered or unexported fields
}
RoundRobinRouter distributes tasks evenly across agents
func NewRoundRobinRouter ¶
func NewRoundRobinRouter() *RoundRobinRouter
NewRoundRobinRouter creates a new round-robin router
func (*RoundRobinRouter) GetCapabilities ¶
func (r *RoundRobinRouter) GetCapabilities(agentName string) []string
GetCapabilities returns the capabilities of an agent
func (*RoundRobinRouter) Route ¶
func (r *RoundRobinRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
Route selects the next agent in round-robin fashion
func (*RoundRobinRouter) UpdateRouting ¶
func (r *RoundRobinRouter) UpdateRouting(agentName string, performance float64)
UpdateRouting updates the performance score for an agent
type RoutingRule ¶
RoutingRule defines a routing rule
type RoutingStrategy ¶
type RoutingStrategy string
RoutingStrategy defines how tasks are routed to sub-agents
const ( StrategyLLMBased RoutingStrategy = "llm" // Use LLM to decide StrategyRuleBased RoutingStrategy = "rules" // Use predefined rules StrategyRoundRobin RoutingStrategy = "round" // Round-robin distribution StrategyCapability RoutingStrategy = "capability" // Based on agent capabilities )
type RuleBasedRouter ¶
type RuleBasedRouter struct {
// contains filtered or unexported fields
}
RuleBasedRouter uses predefined rules to route tasks
func NewRuleBasedRouter ¶
func NewRuleBasedRouter() *RuleBasedRouter
NewRuleBasedRouter creates a new rule-based router
func (*RuleBasedRouter) AddRule ¶
func (r *RuleBasedRouter) AddRule(rule RoutingRule)
AddRule adds a routing rule
func (*RuleBasedRouter) GetCapabilities ¶
func (r *RuleBasedRouter) GetCapabilities(agentName string) []string
GetCapabilities returns the capabilities of an agent
func (*RuleBasedRouter) Route ¶
func (r *RuleBasedRouter) Route(ctx context.Context, task Task, agents map[string]core.Agent) (string, error)
Route uses rules to determine the appropriate agent
func (*RuleBasedRouter) UpdateRouting ¶
func (r *RuleBasedRouter) UpdateRouting(agentName string, performance float64)
UpdateRouting updates the performance score for an agent
type SupervisorAgent ¶
type SupervisorAgent struct {
*core.BaseAgent
SubAgents map[string]core.Agent
Router AgentRouter
Orchestrator *TaskOrchestrator
ResultAggregator *ResultAggregator
// contains filtered or unexported fields
}
SupervisorAgent coordinates multiple sub-agents to handle complex tasks
func NewSupervisorAgent ¶
func NewSupervisorAgent(llm llm.Client, config *SupervisorConfig) *SupervisorAgent
NewSupervisorAgent creates a new supervisor agent
func (*SupervisorAgent) AddSubAgent ¶
func (s *SupervisorAgent) AddSubAgent(name string, agent core.Agent) *SupervisorAgent
AddSubAgent adds a sub-agent to the supervisor
func (*SupervisorAgent) GetMetrics ¶
func (s *SupervisorAgent) GetMetrics() map[string]interface{}
GetMetrics returns supervisor metrics
func (*SupervisorAgent) Invoke ¶
func (s *SupervisorAgent) Invoke(ctx context.Context, input *core.AgentInput) (*core.AgentOutput, error)
Invoke executes a complex task by coordinating sub-agents
func (*SupervisorAgent) RemoveSubAgent ¶
func (s *SupervisorAgent) RemoveSubAgent(name string)
RemoveSubAgent removes a sub-agent
type SupervisorConfig ¶
type SupervisorConfig struct {
// MaxConcurrentAgents limits concurrent sub-agent executions
MaxConcurrentAgents int
// Timeout for sub-agent executions
SubAgentTimeout time.Duration
// RetryPolicy for failed sub-agent tasks
RetryPolicy *tools.RetryPolicy
// EnableCaching enables result caching
EnableCaching bool
// CacheTTL for cached results
CacheTTL time.Duration
// CacheConfig configures the caching behavior
// If nil and EnableCaching is true, default cache config will be used
CacheConfig *performance.CacheConfig
// EnableMetrics enables metrics collection
EnableMetrics bool
// RoutingStrategy defines how to route tasks
RoutingStrategy RoutingStrategy
// AggregationStrategy defines how to aggregate results
AggregationStrategy AggregationStrategy
}
SupervisorConfig configures the supervisor agent
func DefaultSupervisorConfig ¶
func DefaultSupervisorConfig() *SupervisorConfig
DefaultSupervisorConfig returns default configuration
type SupervisorMetrics ¶
type SupervisorMetrics struct {
// contains filtered or unexported fields
}
SupervisorMetrics tracks metrics for the supervisor
func NewSupervisorMetrics ¶
func NewSupervisorMetrics() *SupervisorMetrics
NewSupervisorMetrics creates new metrics tracker
func (*SupervisorMetrics) GetSnapshot ¶
func (m *SupervisorMetrics) GetSnapshot() map[string]interface{}
GetSnapshot returns a snapshot of metrics
func (*SupervisorMetrics) IncrementFailedTasks ¶
func (m *SupervisorMetrics) IncrementFailedTasks()
IncrementFailedTasks increments failed tasks counter
func (*SupervisorMetrics) IncrementSuccessfulTasks ¶
func (m *SupervisorMetrics) IncrementSuccessfulTasks()
IncrementSuccessfulTasks increments successful tasks counter
func (*SupervisorMetrics) IncrementTotalTasks ¶
func (m *SupervisorMetrics) IncrementTotalTasks()
IncrementTotalTasks increments total tasks counter
func (*SupervisorMetrics) UpdateExecutionTime ¶
func (m *SupervisorMetrics) UpdateExecutionTime(duration time.Duration)
UpdateExecutionTime updates execution time metrics
type Task ¶
type Task struct {
ID string `json:"id"`
Type string `json:"type"`
Description string `json:"description"`
Input interface{} `json:"input"`
Priority int `json:"priority"`
Deadline *time.Time `json:"deadline,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Task represents a task to be executed by an agent
type TaskOrchestrator ¶
type TaskOrchestrator struct {
// contains filtered or unexported fields
}
TaskOrchestrator creates execution plans for tasks
func NewTaskOrchestrator ¶
func NewTaskOrchestrator(maxConcurrent int) *TaskOrchestrator
NewTaskOrchestrator creates a new task orchestrator
func (*TaskOrchestrator) CreateExecutionPlan ¶
func (o *TaskOrchestrator) CreateExecutionPlan(tasks []Task) *ExecutionPlan
CreateExecutionPlan creates an execution plan for tasks
type TaskResult ¶
type TaskResult struct {
TaskID string `json:"task_id"`
AgentName string `json:"agent_name"`
Output interface{} `json:"output"`
Error error `json:"-"`
ErrorString string `json:"error,omitempty"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration time.Duration `json:"duration"`
Confidence float64 `json:"confidence"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
TaskResult represents the result of a task execution