Documentation
¶
Overview ¶
Package orchestrator manages multi-agent conversations with different orchestration modes. It coordinates agent interactions, handles turn-taking, and manages message history.
Index ¶
- type ConversationMode
- type Orchestrator
- func (o *Orchestrator) AddAgent(a agent.Agent)
- func (o *Orchestrator) AddMiddleware(m middleware.Middleware)
- func (o *Orchestrator) GetMessages() []agent.Message
- func (o *Orchestrator) GetMetrics() *metrics.Metrics
- func (o *Orchestrator) SetBridgeEmitter(emitter *bridge.Emitter)
- func (o *Orchestrator) SetLogger(logger *logger.ChatLogger)
- func (o *Orchestrator) SetMetrics(m *metrics.Metrics)
- func (o *Orchestrator) SetupDefaultMiddleware()
- func (o *Orchestrator) Start(ctx context.Context) error
- type OrchestratorConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConversationMode ¶
type ConversationMode string
ConversationMode defines how agents take turns in a conversation.
const ( // ModeRoundRobin has agents take turns in a fixed circular order ModeRoundRobin ConversationMode = "round-robin" // ModeReactive randomly selects the next agent, but never the same agent twice in a row ModeReactive ConversationMode = "reactive" // ModeFreeForm allows all agents to respond if they want to participate ModeFreeForm ConversationMode = "free-form" )
type Orchestrator ¶
type Orchestrator struct {
// contains filtered or unexported fields
}
Orchestrator coordinates multi-agent conversations. It manages agent registration, turn-taking, message history, and logging. All methods are safe for concurrent use.
func NewOrchestrator ¶
func NewOrchestrator(config OrchestratorConfig, writer io.Writer) *Orchestrator
NewOrchestrator creates a new Orchestrator with the given configuration. Default values are applied if TurnTimeout (30s) or ResponseDelay (1s) are zero. Retry defaults: MaxRetries=3, InitialDelay=1s, MaxDelay=30s, Multiplier=2.0. To disable retries, explicitly set all retry fields (at minimum RetryInitialDelay) The writer receives formatted conversation output for display (e.g., TUI).
func (*Orchestrator) AddAgent ¶
func (o *Orchestrator) AddAgent(a agent.Agent)
AddAgent registers an agent with the orchestrator. The agent's announcement is added to the conversation history and logged. A rate limiter is created for the agent based on its configuration. This method is thread-safe.
func (*Orchestrator) AddMiddleware ¶ added in v0.0.16
func (o *Orchestrator) AddMiddleware(m middleware.Middleware)
AddMiddleware adds a middleware to the orchestrator's processing chain. Middleware is executed in the order it is added (first added = first executed). This method is thread-safe.
func (*Orchestrator) GetMessages ¶
func (o *Orchestrator) GetMessages() []agent.Message
GetMessages returns a copy of all messages in the conversation history. The returned slice is a copy and can be safely modified without affecting the orchestrator's state. This method is thread-safe.
func (*Orchestrator) GetMetrics ¶ added in v0.0.16
func (o *Orchestrator) GetMetrics() *metrics.Metrics
GetMetrics returns the current metrics instance. Returns nil if metrics are not enabled. This method is thread-safe.
func (*Orchestrator) SetBridgeEmitter ¶ added in v0.3.0
func (o *Orchestrator) SetBridgeEmitter(emitter *bridge.Emitter)
SetBridgeEmitter sets the streaming bridge emitter for real-time conversation updates. If set, the orchestrator will emit events for conversation lifecycle and messages. This method is thread-safe.
func (*Orchestrator) SetLogger ¶
func (o *Orchestrator) SetLogger(logger *logger.ChatLogger)
SetLogger sets the chat logger for the orchestrator. The logger receives all conversation messages for persistence.
func (*Orchestrator) SetMetrics ¶ added in v0.0.16
func (o *Orchestrator) SetMetrics(m *metrics.Metrics)
SetMetrics sets the Prometheus metrics for the orchestrator. If metrics are set, the orchestrator will record metrics for all operations. This method is thread-safe.
func (*Orchestrator) SetupDefaultMiddleware ¶ added in v0.0.16
func (o *Orchestrator) SetupDefaultMiddleware()
SetupDefaultMiddleware configures a sensible default middleware chain. This includes logging, metrics, validation, and error recovery.
func (*Orchestrator) Start ¶
func (o *Orchestrator) Start(ctx context.Context) error
Start begins the multi-agent conversation using the configured orchestration mode. It returns an error if no agents are registered or if the orchestration mode is invalid. The conversation continues until MaxTurns is reached, the context is canceled, or an error occurs. This method blocks until the conversation completes.
type OrchestratorConfig ¶
type OrchestratorConfig struct {
// Mode determines how agents take turns (round-robin, reactive, or free-form)
Mode ConversationMode
// TurnTimeout is the maximum time an agent has to respond
TurnTimeout time.Duration
// MaxTurns is the maximum number of conversation turns (0 = unlimited)
MaxTurns int
// ResponseDelay is the pause between agent responses
ResponseDelay time.Duration
// InitialPrompt is an optional starting prompt for the conversation
InitialPrompt string
// MaxRetries is the maximum number of retry attempts for failed agent responses (0 = no retries)
MaxRetries int
// RetryInitialDelay is the initial delay before the first retry
RetryInitialDelay time.Duration
// RetryMaxDelay is the maximum delay between retries
RetryMaxDelay time.Duration
// RetryMultiplier is the multiplier for exponential backoff (typically 2.0)
RetryMultiplier float64
}
OrchestratorConfig contains configuration for an Orchestrator instance.