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 ¶
- func CreateHandoffTools(agents []*agent.Agent) map[string][]*tool.Definition
- func HandoffResult(result any) (agentID, response string, err error)
- func NewHandoffTool(cfg HandoffConfig) *tool.Definition
- func SwarmHandoffTool(targetID, targetName, description string) *tool.Definition
- type AgentInfo
- type ErrorStrategy
- type HandoffConfig
- type HierarchyConfig
- type MergeFunc
- type ModelRouterFunc
- type RouterFunc
- type Strategy
- type SupervisorNode
- type SwarmConfig
- type Team
- func (t *Team) AddAgent(a *agent.Agent) *Team
- func (t *Team) Broadcast(ctx context.Context, fromAgent, subject string, data map[string]any) error
- func (t *Team) DelegateTask(ctx context.Context, from, to, subject string, task protocol.TaskPayload) (*protocol.ResultPayload, error)
- func (t *Team) DirectChannel(agentA, agentB string, bufSize int) *protocol.DirectChannel
- func (t *Team) MessageHistory() []*protocol.Envelope
- func (t *Team) Run(ctx context.Context, input graph.State) (graph.State, error)
- func (t *Team) SetCoordinator(a *agent.Agent) *Team
- func (t *Team) SetErrorStrategy(es ErrorStrategy) *Team
- func (t *Team) SetMaxConcurrency(n int) *Team
- func (t *Team) SetMaxIterations(n int) *Team
- func (t *Team) SetMerge(fn MergeFunc) *Team
- func (t *Team) SetModelRouter(fn ModelRouterFunc) *Team
- func (t *Team) SetRouter(fn RouterFunc) *Team
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateHandoffTools ¶ added in v0.3.0
func CreateHandoffTools(agents []*agent.Agent) map[string][]*tool.Definition
CreateHandoffTools generates transfer tools for a set of agents. Each agent gets a tool to transfer to every other agent.
func HandoffResult ¶ added in v0.3.0
HandoffResult extracts the handoff result from a tool call response.
func NewHandoffTool ¶ added in v0.3.0
func NewHandoffTool(cfg HandoffConfig) *tool.Definition
NewHandoffTool creates a tool that hands off conversation to another agent. The calling agent can invoke this tool to delegate work to the target agent with specific instructions.
func SwarmHandoffTool ¶ added in v0.3.0
func SwarmHandoffTool(targetID, targetName, description string) *tool.Definition
SwarmHandoffTool creates a tool for peer-to-peer handoff in a swarm. Unlike the standard handoff tool, this one includes the full task context.
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 HandoffConfig ¶ added in v0.3.0
HandoffConfig configures a handoff tool for a specific target agent.
type HierarchyConfig ¶ added in v0.3.0
type HierarchyConfig struct {
// Root is the top-level supervisor.
Root *SupervisorNode
}
HierarchyConfig configures a hierarchical multi-level supervisor team.
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 ¶
RouterFunc selects an agent ID based on the current state.
type SupervisorNode ¶ added in v0.3.0
type SupervisorNode struct {
// Supervisor is the agent that manages this level.
Supervisor *agent.Agent
// Workers are leaf-level agents at this level.
Workers []*agent.Agent
// SubTeams are nested supervisor nodes.
SubTeams []*SupervisorNode
}
SupervisorNode represents a node in the supervisor hierarchy. It can contain either agents (leaf workers) or other supervisors (sub-teams).
type SwarmConfig ¶ added in v0.3.0
type SwarmConfig struct {
// Agents is the set of agents in the swarm.
Agents []*agent.Agent
// InitialAgent is the agent that handles the first message.
InitialAgent string
// MaxHandoffs limits the total number of handoffs (0 = 10 default).
MaxHandoffs int
}
SwarmConfig configures a swarm-style team where agents hand off directly to each other without a central 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
CompiledGraph *graph.CompiledGraph // for swarm/hierarchy graph-based execution
// contains filtered or unexported fields
}
Team orchestrates multiple agents working together.
func NewHierarchy ¶ added in v0.3.0
func NewHierarchy(cfg HierarchyConfig) (*Team, error)
NewHierarchy creates a hierarchical team where supervisors delegate to mid-level supervisors, which delegate to worker agents.
func NewSwarm ¶ added in v0.3.0
func NewSwarm(cfg SwarmConfig) (*Team, error)
NewSwarm creates a swarm team where any agent can hand off to any other agent. Each agent receives handoff tools for all other agents in the swarm.
func (*Team) AddAgent ¶
AddAgent adds an agent to the team and registers it on the communication 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 ¶
MessageHistory returns all inter-agent messages exchanged during the team run.
func (*Team) SetCoordinator ¶
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 ¶
SetMaxConcurrency limits goroutines for parallel execution.
func (*Team) SetMaxIterations ¶
SetMaxIterations sets the max number of coordinator planning iterations.
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).