patterns

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregateOutputs

func AggregateOutputs(results []ExecutionResult) string

AggregateOutputs combines outputs from all results

func GetFinalOutput

func GetFinalOutput(results []ExecutionResult) string

GetFinalOutput returns the output of the last successful execution

Types

type AgentClassification

type AgentClassification struct {
	AgentName  string
	Confidence float64
	Priority   int
}

AgentClassification represents a classified agent with confidence

type AgentExecutor

type AgentExecutor func(ctx context.Context, agentName, input string) (string, error)

AgentExecutor is the function signature for executing an agent

type AggregationConfig

type AggregationConfig struct {
	Method           AggregationMethod
	Timeout          time.Duration
	ConcurrencyLimit int
	Scorer           Scorer     // For AggregationBest
	Summarizer       Summarizer // For AggregationSummarize
	Delimiter        string     // For AggregationMerge
	MinimumResponses int        // Minimum responses required
}

AggregationConfig configures the aggregation pattern

type AggregationMethod

type AggregationMethod string

AggregationMethod defines how results are aggregated

const (
	AggregationMerge     AggregationMethod = "merge"     // Combine all outputs
	AggregationVote      AggregationMethod = "vote"      // Majority voting
	AggregationSummarize AggregationMethod = "summarize" // Summarize via agent
	AggregationBest      AggregationMethod = "best"      // Select best based on scorer
)

type AggregationPattern

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

AggregationPattern runs multiple agents and aggregates results

func NewAggregationPattern

func NewAggregationPattern(executor AgentExecutor, config AggregationConfig) *AggregationPattern

NewAggregationPattern creates a new aggregation pattern

func (*AggregationPattern) Execute

func (a *AggregationPattern) Execute(ctx context.Context, agents []string, input string) (*AggregationResult, error)

Execute runs all agents and aggregates their results

type AggregationResult

type AggregationResult struct {
	IndividualResults []ExecutionResult
	AggregatedOutput  string
	Method            AggregationMethod
	Scores            map[string]float64 // Agent scores if using scorer
}

AggregationResult contains execution and aggregation results

type AggregationStrategy

type AggregationStrategy string

AggregationStrategy defines how to aggregate results from parallel execution

const (
	AggregateAll      AggregationStrategy = "all"      // Wait for all results
	AggregateAny      AggregationStrategy = "any"      // Return first successful result
	AggregateMajority AggregationStrategy = "majority" // Return when majority complete
)

type ChainOfThoughtConfig

type ChainOfThoughtConfig struct {
	ReasoningAgent string        // Agent for reasoning steps
	ExecutionAgent string        // Agent for final execution
	MaxSteps       int           // Maximum reasoning steps
	Timeout        time.Duration // Timeout per step
}

ChainOfThoughtConfig configures chain-of-thought reasoning

type ChainOfThoughtPattern

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

ChainOfThoughtPattern implements chain-of-thought reasoning

func NewChainOfThoughtPattern

func NewChainOfThoughtPattern(executor AgentExecutor, config ChainOfThoughtConfig) *ChainOfThoughtPattern

NewChainOfThoughtPattern creates a new chain-of-thought pattern

func (*ChainOfThoughtPattern) Execute

Execute runs chain-of-thought reasoning

type ChainOfThoughtResult

type ChainOfThoughtResult struct {
	Steps       []ThoughtStep
	FinalAnswer string
	Error       error
}

ChainOfThoughtResult contains the full reasoning chain

type ClassificationResult

type ClassificationResult struct {
	ClassifiedAgent string
	Confidence      float64
	ExecutionResult
}

ClassificationResult contains the classification and execution result

type Classifier

type Classifier func(ctx context.Context, input string) (agentName string, confidence float64, err error)

Classifier determines which agent should handle a task

type ClassifierConfig

type ClassifierConfig struct {
	Classifier          Classifier    // Function to classify input
	ConfidenceThreshold float64       // Minimum confidence to proceed
	DefaultAgent        string        // Agent to use if classification fails
	Timeout             time.Duration // Timeout per execution
}

ClassifierConfig configures the classifier pattern

type ClassifierPattern

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

ClassifierPattern routes tasks to agents based on classification

func NewClassifierPattern

func NewClassifierPattern(executor AgentExecutor, config ClassifierConfig) *ClassifierPattern

NewClassifierPattern creates a new classifier pattern

func (*ClassifierPattern) Execute

Execute classifies the input and routes to the appropriate agent

type ErrorStrategy

type ErrorStrategy string

ErrorStrategy defines how to handle errors in sequential execution

const (
	StopOnError     ErrorStrategy = "stop"     // Stop execution on first error
	ContinueOnError ErrorStrategy = "continue" // Continue despite errors
)

type ExecutionResult

type ExecutionResult struct {
	AgentName string
	Output    string
	Error     error
	Duration  int64 // milliseconds
}

ExecutionResult represents the result of executing an agent

type MapReduceConfig

type MapReduceConfig struct {
	Splitter         Splitter      // Function to split input
	Reducer          Reducer       // Function to reduce results
	ConcurrencyLimit int           // Max concurrent map operations
	Timeout          time.Duration // Timeout per map operation
}

MapReduceConfig configures the map-reduce pattern

type MapReducePattern

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

MapReducePattern implements map-reduce execution

func NewMapReducePattern

func NewMapReducePattern(executor AgentExecutor, config MapReduceConfig) *MapReducePattern

NewMapReducePattern creates a new map-reduce pattern

func (*MapReducePattern) Execute

func (m *MapReducePattern) Execute(ctx context.Context, agentName, input string) (string, []ExecutionResult, error)

Execute runs the map-reduce pattern

type MultiClassifier

type MultiClassifier func(ctx context.Context, input string) (agents []AgentClassification, err error)

MultiClassifier determines multiple agents that should handle a task

type MultiClassifierConfig

type MultiClassifierConfig struct {
	Classifier          MultiClassifier
	ConfidenceThreshold float64
	MaxAgents           int           // Maximum agents to execute
	Timeout             time.Duration // Timeout per agent
	Parallel            bool          // Execute agents in parallel
}

MultiClassifierConfig configures multi-agent classification

type MultiClassifierPattern

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

MultiClassifierPattern routes to multiple agents based on classification

func NewMultiClassifierPattern

func NewMultiClassifierPattern(executor AgentExecutor, config MultiClassifierConfig) *MultiClassifierPattern

NewMultiClassifierPattern creates a new multi-classifier pattern

func (*MultiClassifierPattern) Execute

Execute classifies and routes to multiple agents

type ParallelConfig

type ParallelConfig struct {
	ConcurrencyLimit int                 // Max concurrent executions (0 = unlimited)
	Timeout          time.Duration       // Timeout per agent
	Aggregation      AggregationStrategy // How to aggregate results
}

ParallelConfig configures parallel execution

type ParallelPattern

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

ParallelPattern executes multiple agents concurrently

func NewParallelPattern

func NewParallelPattern(executor AgentExecutor, config ParallelConfig) *ParallelPattern

NewParallelPattern creates a new parallel execution pattern

func (*ParallelPattern) Execute

func (p *ParallelPattern) Execute(ctx context.Context, agents []string, input string) ([]ExecutionResult, error)

Execute runs all agents in parallel and aggregates results

type Plan

type Plan struct {
	Steps       []PlanStep
	Description string
	Metadata    map[string]string
}

Plan represents an execution plan

type PlanStep

type PlanStep struct {
	ID           string            // Unique step identifier
	AgentName    string            // Agent to execute
	Input        string            // Input for this step
	Dependencies []string          // IDs of steps that must complete first
	Metadata     map[string]string // Optional metadata
}

PlanStep represents a single step in an execution plan

type PlanValidator

type PlanValidator func(plan *Plan) error

PlanValidator validates a plan before execution

type Planner

type Planner func(ctx context.Context, input string) (*Plan, error)

Planner creates an execution plan from input

type PlanningConfig

type PlanningConfig struct {
	Planner           Planner
	Validator         PlanValidator
	Timeout           time.Duration // Timeout per step
	MaxSteps          int           // Maximum steps allowed
	ContinueOnError   bool          // Continue executing if a step fails
	ReplanOnFailure   bool          // Attempt to create new plan on failure
	MaxReplanAttempts int
}

PlanningConfig configures the planning pattern

type PlanningPattern

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

PlanningPattern creates and executes plans

func NewPlanningPattern

func NewPlanningPattern(executor AgentExecutor, config PlanningConfig) *PlanningPattern

NewPlanningPattern creates a new planning pattern

func (*PlanningPattern) Execute

func (p *PlanningPattern) Execute(ctx context.Context, input string) (*PlanningResult, error)

Execute creates a plan and executes it

type PlanningResult

type PlanningResult struct {
	Plan          *Plan
	StepResults   []StepResult
	FinalOutput   string
	ReplanCount   int
	TotalDuration int64
}

PlanningResult contains the full planning and execution result

type QualityAssessor

type QualityAssessor func(ctx context.Context, iteration int, output string) (score float64, continueIterating bool)

QualityAssessor evaluates output quality and determines if improvement is needed Returns a score (0.0-1.0) and whether to continue iterating

type Reducer

type Reducer func(results []ExecutionResult) (string, error)

Reducer combines results from map phase

type ReflectionConfig

type ReflectionConfig struct {
	MaxIterations      int             // Maximum iterations
	Timeout            time.Duration   // Timeout per iteration
	QualityThreshold   float64         // Stop when quality reaches this level
	ConvergenceWindow  int             // Number of iterations to check for convergence
	ConvergenceEpsilon float64         // Minimum improvement to not be considered converged
	QualityAssessor    QualityAssessor // Function to assess quality
}

ReflectionConfig configures the reflection pattern

type ReflectionPattern

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

ReflectionPattern implements self-improvement through iterative feedback

func NewReflectionPattern

func NewReflectionPattern(executor AgentExecutor, config ReflectionConfig) *ReflectionPattern

NewReflectionPattern creates a new reflection pattern

func (*ReflectionPattern) Execute

func (r *ReflectionPattern) Execute(ctx context.Context, agentName, input string) ([]ReflectionResult, error)

Execute runs the reflection loop

type ReflectionResult

type ReflectionResult struct {
	Iteration int
	Output    string
	Score     float64
	Error     error
	Duration  int64
}

ReflectionResult represents the result of a reflection iteration

func GetBestResult

func GetBestResult(results []ReflectionResult) *ReflectionResult

GetBestResult returns the result with the highest score

type Scorer

type Scorer func(ctx context.Context, agentName, output string) float64

Scorer evaluates the quality of an output

type SequentialConfig

type SequentialConfig struct {
	ErrorStrategy ErrorStrategy       // How to handle errors
	Timeout       time.Duration       // Timeout per agent
	BranchFn      func(string) string // Optional: determine next agent based on output
}

SequentialConfig configures sequential execution

type SequentialPattern

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

SequentialPattern executes agents in sequence, passing output as input

func NewSequentialPattern

func NewSequentialPattern(executor AgentExecutor, config SequentialConfig) *SequentialPattern

NewSequentialPattern creates a new sequential execution pattern

func (*SequentialPattern) Execute

func (s *SequentialPattern) Execute(ctx context.Context, agents []string, input string) ([]ExecutionResult, error)

Execute runs agents in sequence

type Splitter

type Splitter func(input string) []string

Splitter divides input into chunks for parallel processing

type StepResult

type StepResult struct {
	StepID    string
	AgentName string
	Output    string
	Error     error
	Duration  int64
	Skipped   bool
}

StepResult represents the result of a plan step

type Summarizer

type Summarizer func(ctx context.Context, outputs []string) (string, error)

Summarizer creates a summary from multiple outputs

type ThoughtStep

type ThoughtStep struct {
	Step     int
	Thought  string
	Action   string
	Result   string
	Error    error
	Duration int64
}

ThoughtStep represents a step in chain-of-thought reasoning

Jump to

Keyboard shortcuts

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