Documentation
¶
Overview ¶
Package agentpool manages a pool of discovered P2P agents with health checking, weighted selection, and capability-based filtering.
Index ¶
- Variables
- type Agent
- type AgentPerformance
- type AgentStatus
- type DynamicAgentInfo
- type DynamicAgentProvider
- type HealthCheckFunc
- type HealthChecker
- type Pool
- func (p *Pool) Add(agent *Agent) error
- func (p *Pool) EvictStale(threshold time.Duration) int
- func (p *Pool) FindByCapability(cap string) []*Agent
- func (p *Pool) Get(did string) *Agent
- func (p *Pool) List() []*Agent
- func (p *Pool) MarkHealthy(did string, latency time.Duration)
- func (p *Pool) MarkUnhealthy(did string)
- func (p *Pool) Remove(did string)
- func (p *Pool) Size() int
- func (p *Pool) Update(agent *Agent)
- func (p *Pool) UpdatePerformance(did string, latencyMs float64, success bool)
- type PoolProvider
- type Selector
- func (s *Selector) ScoreWithCaps(a *Agent, requiredCaps []string) float64
- func (s *Selector) Select(capability string) (*Agent, error)
- func (s *Selector) SelectBest(agents []*Agent, requiredCaps []string, n int) []*Agent
- func (s *Selector) SelectN(capability string, n int) ([]*Agent, error)
- func (s *Selector) SelectRandom(capability string) (*Agent, error)
- type SelectorWeights
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoAgents = errors.New("no agents available") ErrAgentExists = errors.New("agent already registered") ErrNotFound = errors.New("agent not found") )
Sentinel errors for pool operations.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
DID string `json:"did"`
Name string `json:"name"`
PeerID string `json:"peerId"`
Capabilities []string `json:"capabilities"`
Metadata map[string]string `json:"metadata,omitempty"`
Status AgentStatus `json:"status"`
TrustScore float64 `json:"trustScore"`
PricePerCall float64 `json:"pricePerCall"`
Available bool `json:"available"`
Performance AgentPerformance `json:"performance"`
Latency time.Duration `json:"latency"`
LastSeen time.Time `json:"lastSeen"`
LastHealthy time.Time `json:"lastHealthy"`
FailCount int `json:"failCount"`
}
Agent represents a discovered P2P agent in the pool.
func (*Agent) HasCapability ¶
HasCapability reports whether the agent advertises the given capability.
type AgentPerformance ¶
type AgentPerformance struct {
AvgLatencyMs float64 `json:"avgLatencyMs"`
SuccessRate float64 `json:"successRate"`
TotalCalls int `json:"totalCalls"`
}
AgentPerformance tracks runtime performance metrics for a pooled agent.
type AgentStatus ¶
type AgentStatus string
AgentStatus represents the health status of a pooled agent.
const ( StatusHealthy AgentStatus = "healthy" StatusDegraded AgentStatus = "degraded" StatusUnhealthy AgentStatus = "unhealthy" StatusUnknown AgentStatus = "unknown" )
type DynamicAgentInfo ¶
type DynamicAgentInfo struct {
Name string
DID string
PeerID string
Description string
Capabilities []string
TrustScore float64
PricePerCall float64
}
DynamicAgentInfo describes a discovered agent for routing purposes. It is a lightweight descriptor that avoids importing ADK agent types.
type DynamicAgentProvider ¶
type DynamicAgentProvider interface {
// AvailableAgents returns all healthy agents currently in the pool.
AvailableAgents() []DynamicAgentInfo
// FindForCapability returns agents that match the given capability.
FindForCapability(capability string) []DynamicAgentInfo
}
DynamicAgentProvider discovers remote agents dynamically at runtime. The orchestrator queries this interface to integrate P2P agents into its routing table without requiring them to implement adk_agent.Agent.
type HealthCheckFunc ¶
HealthCheckFunc pings an agent and returns its latency if reachable.
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker periodically checks agent health.
func NewHealthChecker ¶
func NewHealthChecker(pool *Pool, checkFn HealthCheckFunc, interval time.Duration, logger *zap.SugaredLogger) *HealthChecker
NewHealthChecker creates a health checker for the given pool.
func (*HealthChecker) Start ¶
func (hc *HealthChecker) Start(wg *sync.WaitGroup)
Start begins periodic health checking.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a set of P2P agents with thread-safe access.
func (*Pool) Add ¶
Add registers an agent in the pool. Returns ErrAgentExists if the DID is already registered.
func (*Pool) EvictStale ¶
EvictStale removes agents not seen within the given threshold.
func (*Pool) FindByCapability ¶
FindByCapability returns all healthy agents that advertise the given capability.
func (*Pool) MarkHealthy ¶
MarkHealthy updates an agent's status and records the health check time.
func (*Pool) MarkUnhealthy ¶
MarkUnhealthy updates an agent's status after a failed health check.
type PoolProvider ¶
type PoolProvider struct {
// contains filtered or unexported fields
}
PoolProvider adapts an agentpool.Pool into a DynamicAgentProvider.
func NewPoolProvider ¶
func NewPoolProvider(pool *Pool, selector *Selector) *PoolProvider
NewPoolProvider creates a DynamicAgentProvider backed by a Pool.
func (*PoolProvider) AvailableAgents ¶
func (p *PoolProvider) AvailableAgents() []DynamicAgentInfo
AvailableAgents returns all healthy agents in the pool.
func (*PoolProvider) FindForCapability ¶
func (p *PoolProvider) FindForCapability(capability string) []DynamicAgentInfo
FindForCapability returns agents matching the given capability.
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
Selector picks agents from the pool using weighted scoring.
func NewSelector ¶
func NewSelector(pool *Pool, weights SelectorWeights) *Selector
NewSelector creates a weighted selector for the given pool.
func (*Selector) ScoreWithCaps ¶
ScoreWithCaps computes a weighted score considering required capabilities.
func (*Selector) Select ¶
Select picks the best agent for the given capability. Returns ErrNoAgents if no suitable agent is found.
func (*Selector) SelectBest ¶
SelectBest picks the top N agents for the given required capabilities.
type SelectorWeights ¶
type SelectorWeights struct {
Trust float64 // weight for trust score [0,1]
Capability float64 // weight for capability match breadth
Performance float64 // weight for success rate / latency
Price float64 // weight for price (lower is better)
Availability float64 // weight for availability / health status
// Legacy aliases (used if the new fields are zero).
Latency float64 // weight for latency (lower is better)
Health float64 // weight for health status
}
SelectorWeights configures the relative importance of selection criteria.
func DefaultWeights ¶
func DefaultWeights() SelectorWeights
DefaultWeights returns production-default selector weights.