team

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package team provides multi-agent orchestration with inter-agent communication.

Teams coordinate multiple agents working together using different strategies: sequential (pipeline), parallel (fan-out/fan-in), router (intelligent dispatch), or coordinator (LLM-driven task decomposition). Communication flows through the protocol.Bus with optional direct agent-to-agent channels for low-latency paths.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentInfo

type AgentInfo struct {
	ID           string   `json:"id"`
	Name         string   `json:"name"`
	Description  string   `json:"description"`
	Capabilities []string `json:"capabilities"`
}

AgentInfo is a lightweight descriptor exposed to routing functions.

type ErrorStrategy

type ErrorStrategy int

ErrorStrategy controls how agent failures are handled.

const (
	ErrorStrategyFailFast   ErrorStrategy = iota // abort on first error
	ErrorStrategyCollect                         // collect all errors, return combined
	ErrorStrategyBestEffort                      // ignore errors, return successful results
)

type MergeFunc

type MergeFunc func(results []graph.State) graph.State

MergeFunc combines results from parallel agent executions.

type ModelRouterFunc

type ModelRouterFunc func(ctx context.Context, state graph.State, agents []AgentInfo) (string, error)

ModelRouterFunc selects an agent using model-based reasoning. It receives the full state plus a list of available agents with descriptions.

type RouterFunc

type RouterFunc func(state graph.State) string

RouterFunc selects an agent ID based on the current state.

type Strategy

type Strategy string

Strategy defines how work is distributed across team members.

const (
	StrategySequential  Strategy = "sequential"
	StrategyParallel    Strategy = "parallel"
	StrategyRouter      Strategy = "router"
	StrategyCoordinator Strategy = "coordinator"
)

type Team

type Team struct {
	ID       string
	Name     string
	Agents   map[string]*agent.Agent
	Order    []string
	Strategy Strategy

	Router      RouterFunc
	ModelRouter ModelRouterFunc
	Merge       MergeFunc
	Bus         *protocol.Bus

	MaxConcurrency int           // for parallel strategy; 0 = unbounded
	ErrorMode      ErrorStrategy // how to handle agent failures
	Coordinator    *agent.Agent  // explicit coordinator agent (for StrategyCoordinator)
	MaxIterations  int           // max coordinator planning iterations; 0 = 1

	SharedContext map[string]any
}

Team orchestrates multiple agents working together.

func New

func New(id, name string, strategy Strategy) *Team

New creates a team with the given strategy.

func (*Team) AddAgent

func (t *Team) AddAgent(a *agent.Agent) *Team

AddAgent adds an agent to the team and registers it on the communication bus.

func (*Team) Broadcast

func (t *Team) Broadcast(ctx context.Context, fromAgent, subject string, data map[string]any) error

Broadcast sends a message from one agent to all others via the bus.

func (*Team) DelegateTask

func (t *Team) DelegateTask(ctx context.Context, from, to, subject string, task protocol.TaskPayload) (*protocol.ResultPayload, error)

DelegateTask uses the bus to delegate a task from one agent to another.

func (*Team) DirectChannel

func (t *Team) DirectChannel(agentA, agentB string, bufSize int) *protocol.DirectChannel

DirectChannel returns (or creates) a dedicated low-latency channel between two agents that bypasses the central bus.

func (*Team) MessageHistory

func (t *Team) MessageHistory() []*protocol.Envelope

MessageHistory returns all inter-agent messages exchanged during the team run.

func (*Team) Run

func (t *Team) Run(ctx context.Context, input graph.State) (graph.State, error)

Run executes the team's strategy with the given input.

func (*Team) SetCoordinator

func (t *Team) SetCoordinator(a *agent.Agent) *Team

SetCoordinator sets an explicit coordinator agent (for StrategyCoordinator). The coordinator is automatically registered on the bus so it can delegate tasks.

func (*Team) SetErrorStrategy

func (t *Team) SetErrorStrategy(es ErrorStrategy) *Team

SetErrorStrategy controls how agent failures are handled.

func (*Team) SetMaxConcurrency

func (t *Team) SetMaxConcurrency(n int) *Team

SetMaxConcurrency limits goroutines for parallel execution.

func (*Team) SetMaxIterations

func (t *Team) SetMaxIterations(n int) *Team

SetMaxIterations sets the max number of coordinator planning iterations.

func (*Team) SetMerge

func (t *Team) SetMerge(fn MergeFunc) *Team

SetMerge sets the merge function (for StrategyParallel).

func (*Team) SetModelRouter

func (t *Team) SetModelRouter(fn ModelRouterFunc) *Team

SetModelRouter sets a model-based routing function (for StrategyRouter).

func (*Team) SetRouter

func (t *Team) SetRouter(fn RouterFunc) *Team

SetRouter sets a static routing function (for StrategyRouter).

Jump to

Keyboard shortcuts

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