orchestration

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConcatAggregator

func ConcatAggregator(separator string) func(results map[string]*agent.Message) (*agent.Message, error)

ConcatAggregator concatenates all text results

func FirstSuccessAggregator

func FirstSuccessAggregator() func(results map[string]*agent.Message) (*agent.Message, error)

FirstSuccessAggregator returns the first successful result

func MajorityVoteAggregator

func MajorityVoteAggregator() func(results map[string]*agent.Message) (*agent.Message, error)

MajorityVoteAggregator returns the most common result

Types

type BaseOrchestrator

type BaseOrchestrator struct {
	// contains filtered or unexported fields
}

BaseOrchestrator provides common functionality for orchestrators

func NewBaseOrchestrator

func NewBaseOrchestrator(name, pattern string, runtime agent.Runtime) *BaseOrchestrator

NewBaseOrchestrator creates a new base orchestrator

func (*BaseOrchestrator) Execute

func (b *BaseOrchestrator) Execute(ctx context.Context, input *agent.Message) (*agent.Message, error)

Execute provides a default implementation that returns an error

func (*BaseOrchestrator) Name

func (b *BaseOrchestrator) Name() string

Name returns the orchestrator identifier

func (*BaseOrchestrator) Pattern

func (b *BaseOrchestrator) Pattern() string

Pattern returns the pattern type

func (*BaseOrchestrator) Ready

func (b *BaseOrchestrator) Ready() bool

Ready returns true if the orchestrator is ready

func (*BaseOrchestrator) Runtime

func (b *BaseOrchestrator) Runtime() agent.Runtime

Runtime returns the runtime

func (*BaseOrchestrator) SetReady

func (b *BaseOrchestrator) SetReady(ready bool)

SetReady sets the ready state

func (*BaseOrchestrator) Start

func (b *BaseOrchestrator) Start(ctx context.Context) error

Start is a default no-op implementation

func (*BaseOrchestrator) Stop

func (b *BaseOrchestrator) Stop(ctx context.Context) error

Stop is a default no-op implementation

type Ensemble

type Ensemble struct {
	*BaseOrchestrator
	// contains filtered or unexported fields
}

Ensemble implements multi-model voting for improved accuracy. Multiple models generate outputs and vote on the best result. Provides 25-50% error reduction in high-stakes decisions.

Use cases: - Medical diagnosis - Financial forecasting - Content moderation - Critical decision-making

func NewContentModerationEnsemble

func NewContentModerationEnsemble(name string, runtime agent.Runtime, models []string) *Ensemble

NewContentModerationEnsemble creates an ensemble for content moderation

func NewEnsemble

func NewEnsemble(name string, runtime agent.Runtime, models []string, opts ...EnsembleOption) *Ensemble

NewEnsemble creates a new Ensemble orchestrator

func NewFinancialForecastEnsemble

func NewFinancialForecastEnsemble(name string, runtime agent.Runtime, models []string) *Ensemble

NewFinancialForecastEnsemble creates an ensemble for financial forecasting

func NewMedicalDiagnosisEnsemble

func NewMedicalDiagnosisEnsemble(name string, runtime agent.Runtime, models []string) *Ensemble

NewMedicalDiagnosisEnsemble creates an ensemble for medical diagnosis

func (*Ensemble) Execute

func (e *Ensemble) Execute(ctx context.Context, input *agent.Message) (*agent.Message, error)

Execute runs all models and aggregates via voting

type EnsembleOption

type EnsembleOption func(*Ensemble)

EnsembleOption configures an Ensemble orchestrator

func WithAgreementThreshold

func WithAgreementThreshold(threshold float64) EnsembleOption

WithAgreementThreshold sets the minimum agreement threshold

func WithVotingStrategy

func WithVotingStrategy(strategy VotingStrategy) EnsembleOption

WithVotingStrategy sets the voting strategy

type HandoffInstruction

type HandoffInstruction struct {
	TargetAgent string
	Context     string
	Reason      string
}

HandoffInstruction represents a handoff instruction from an agent

type Hierarchical

type Hierarchical struct {
	*BaseOrchestrator
	// contains filtered or unexported fields
}

Hierarchical implements multi-level delegation pattern. Managers delegate to sub-managers who delegate to workers. Perfect for complex task decomposition and organizational hierarchies.

Use cases: - Enterprise workflows - Project management - Complex multi-step processes - Organizational hierarchies

func NewEnterpriseWorkflow

func NewEnterpriseWorkflow(name string, runtime agent.Runtime, departments map[string][]string) *Hierarchical

NewEnterpriseWorkflow creates a hierarchical orchestrator for enterprise workflows

func NewHierarchical

func NewHierarchical(name string, runtime agent.Runtime, manager string, teams map[string][]string, opts ...HierarchicalOption) *Hierarchical

NewHierarchical creates a new Hierarchical orchestrator

func NewProjectManager

func NewProjectManager(name string, runtime agent.Runtime) *Hierarchical

NewProjectManager creates a hierarchical orchestrator for project management

func (*Hierarchical) Execute

func (h *Hierarchical) Execute(ctx context.Context, input *agent.Message) (*agent.Message, error)

Execute delegates task through hierarchical structure

type HierarchicalOption

type HierarchicalOption func(*Hierarchical)

HierarchicalOption configures a Hierarchical orchestrator

func WithMaxDepth

func WithMaxDepth(depth int) HierarchicalOption

WithMaxDepth sets the maximum delegation depth

type Orchestrator

type Orchestrator interface {
	// Name returns the orchestrator identifier
	Name() string

	// Pattern returns the pattern type (e.g., "parallel", "router", "rag")
	Pattern() string

	// Execute runs the orchestration pattern synchronously
	Execute(ctx context.Context, input *agent.Message) (*agent.Message, error)

	// Start runs the orchestration pattern asynchronously
	Start(ctx context.Context) error

	// Stop gracefully shuts down the orchestrator
	Stop(ctx context.Context) error

	// Ready returns true if the orchestrator is ready
	Ready() bool
}

Orchestrator defines the interface for agent orchestration patterns. All orchestration patterns implement this interface.

type Parallel

type Parallel struct {
	*BaseOrchestrator
	// contains filtered or unexported fields
}

Parallel executes multiple agents concurrently and aggregates results. Provides 3-4× speedup for independent tasks compared to sequential execution.

Use cases: - Multi-source research - Batch processing - A/B testing - Independent data gathering

func NewParallel

func NewParallel(name string, runtime agent.Runtime, agents []string, opts ...ParallelOption) *Parallel

NewParallel creates a new Parallel orchestrator

func (*Parallel) Execute

func (p *Parallel) Execute(ctx context.Context, input *agent.Message) (*agent.Message, error)

Execute runs all agents in parallel and aggregates results

type ParallelOption

type ParallelOption func(*Parallel)

ParallelOption configures a Parallel orchestrator

func WithAggregateFunc

func WithAggregateFunc(fn func(results map[string]*agent.Message) (*agent.Message, error)) ParallelOption

WithAggregateFunc sets a custom aggregation function

func WithFailFast

func WithFailFast(enabled bool) ParallelOption

WithFailFast enables fail-fast mode (stop on first error)

type RAG

type RAG struct {
	*BaseOrchestrator
	// contains filtered or unexported fields
}

RAG implements Retrieval-Augmented Generation pattern. Retrieves relevant documents from a vector store, then generates grounded answers. Most common enterprise pattern for chatbots and Q&A systems.

Use cases: - Enterprise chatbots - Documentation Q&A - Knowledge retrieval - Context-aware generation

func NewConversationalRAG

func NewConversationalRAG(name string, runtime agent.Runtime, retriever, generator string, historyAgent string) *RAG

NewConversationalRAG creates a RAG with conversation history

func NewHybridRAG

func NewHybridRAG(name string, runtime agent.Runtime, semanticRetriever, keywordRetriever, generator string) *RAG

NewHybridRAG creates a RAG with both semantic and keyword search

func NewMultiQueryRAG

func NewMultiQueryRAG(name string, runtime agent.Runtime, queryExpander, retriever, generator string) *RAG

NewMultiQueryRAG creates a RAG that generates multiple queries for retrieval

func NewRAG

func NewRAG(name string, runtime agent.Runtime, retriever, generator string, opts ...RAGOption) *RAG

NewRAG creates a new RAG orchestrator

func (*RAG) Execute

func (r *RAG) Execute(ctx context.Context, input *agent.Message) (*agent.Message, error)

Execute performs RAG: retrieve → (optional rerank) → generate

type RAGOption

type RAGOption func(*RAG)

RAGOption configures a RAG orchestrator

func WithReranker

func WithReranker(reranker string) RAGOption

WithReranker enables reranking with the specified agent

func WithTopK

func WithTopK(k int) RAGOption

WithTopK sets the number of documents to retrieve

type Reflection

type Reflection struct {
	*BaseOrchestrator
	// contains filtered or unexported fields
}

Reflection implements iterative refinement with self-critique. Generator creates output, critic reviews it, generator refines. Provides 20-50% quality improvement through iterative refinement.

Use cases: - Code generation with review - Content creation with editing - Complex reasoning tasks - Quality assurance

func NewMultiCriticReflection

func NewMultiCriticReflection(name string, runtime agent.Runtime, generator string, critics []string, maxIterations int) *Reflection

NewMultiCriticReflection creates a reflection with multiple critics

func NewReflection

func NewReflection(name string, runtime agent.Runtime, generator, critic string, opts ...ReflectionOption) *Reflection

NewReflection creates a new Reflection orchestrator

func NewSelfReflection

func NewSelfReflection(name string, runtime agent.Runtime, agent string, maxIterations int) *Reflection

NewSelfReflection creates a reflection where generator acts as its own critic

func (*Reflection) Execute

func (r *Reflection) Execute(ctx context.Context, input *agent.Message) (*agent.Message, error)

Execute performs iterative refinement: generate → critique → refine

type ReflectionOption

type ReflectionOption func(*Reflection)

ReflectionOption configures a Reflection orchestrator

func WithImprovementThreshold

func WithImprovementThreshold(threshold float64) ReflectionOption

WithImprovementThreshold sets the minimum improvement threshold

func WithMaxIterations

func WithMaxIterations(max int) ReflectionOption

WithMaxIterations sets the maximum number of refinement iterations

type Router

type Router struct {
	*BaseOrchestrator
	// contains filtered or unexported fields
}

Router routes requests to different agents based on classification. Provides 25-50% cost reduction by routing simple queries to cheaper models.

Use cases: - Cost optimization (simple → cheap, complex → expensive models) - Intent-based routing - Skill-based agent selection - Load balancing

func NewCostOptimizingRouter

func NewCostOptimizingRouter(name string, runtime agent.Runtime, classifier string) *Router

NewCostOptimizingRouter creates a router that optimizes for cost Simple queries → cheap models (gpt-3.5, claude-haiku) Complex queries → expensive models (gpt-4, claude-opus)

func NewIntentRouter

func NewIntentRouter(name string, runtime agent.Runtime, classifier string, intentMap map[string]string) *Router

NewIntentRouter creates a router based on user intent

func NewRouter

func NewRouter(name string, runtime agent.Runtime, classifier string, routes map[string]string, opts ...RouterOption) *Router

NewRouter creates a new Router orchestrator

func NewSkillRouter

func NewSkillRouter(name string, runtime agent.Runtime, classifier string, skillMap map[string]string) *Router

NewSkillRouter creates a router based on required skills

func (*Router) Execute

func (r *Router) Execute(ctx context.Context, input *agent.Message) (*agent.Message, error)

Execute classifies the input and routes to the appropriate agent

type RouterOption

type RouterOption func(*Router)

RouterOption configures a Router orchestrator

func WithDefaultRoute

func WithDefaultRoute(agent string) RouterOption

WithDefaultRoute sets the fallback agent

type Swarm

type Swarm struct {
	*BaseOrchestrator
	// contains filtered or unexported fields
}

Swarm implements decentralized agent handoffs based on conversational context. Agents decide when to hand off to other agents dynamically. Popularized by OpenAI Swarm.

Use cases: - Customer service handoffs (general → billing → technical) - Adaptive routing based on conversation flow - Collaborative problem-solving

func NewSwarm

func NewSwarm(name string, runtime agent.Runtime, entryAgent string, agents []string, opts ...SwarmOption) *Swarm

NewSwarm creates a new Swarm orchestrator

func (*Swarm) Execute

func (s *Swarm) Execute(ctx context.Context, input *agent.Message) (*agent.Message, error)

Execute runs the swarm starting from the entry agent

type SwarmOption

type SwarmOption func(*Swarm)

SwarmOption configures a Swarm orchestrator

func WithMaxHandoffs

func WithMaxHandoffs(max int) SwarmOption

WithMaxHandoffs sets the maximum number of handoffs

type VotingStrategy

type VotingStrategy string

VotingStrategy defines how ensemble votes are aggregated

const (
	VotingMajority   VotingStrategy = "majority"   // Simple majority vote
	VotingUnanimous  VotingStrategy = "unanimous"  // All must agree
	VotingWeighted   VotingStrategy = "weighted"   // Weighted by model confidence
	VotingConfidence VotingStrategy = "confidence" // Highest confidence wins
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL