Team - Multi-Agent Collaboration
Build powerful multi-agent systems with 4 coordination modes.
What is Team?
A Team is a collection of agents working together to solve complex tasks. Different coordination modes enable various collaboration patterns.
Key Features
- 4 Coordination Modes: Sequential, Parallel, Leader-Follower, Consensus
- Dynamic Membership: Add/remove agents at runtime
- Flexible Configuration: Customize behavior per mode
- Type-Safe: Full Go type checking
Creating a Team
Basic Example
package main
import (
"context"
"fmt"
"log"
"github.com/rexleimo/agno-go/pkg/agno/agent"
"github.com/rexleimo/agno-go/pkg/agno/team"
"github.com/rexleimo/agno-go/pkg/agno/models/openai"
)
func main() {
// Create model
model, _ := openai.New("gpt-4o-mini", openai.Config{
APIKey: "your-api-key",
})
// Create team members
researcher, _ := agent.New(agent.Config{
Name: "Researcher",
Model: model,
Instructions: "You are a research expert.",
})
writer, _ := agent.New(agent.Config{
Name: "Writer",
Model: model,
Instructions: "You are a technical writer.",
})
// Create team
t, err := team.New(team.Config{
Name: "Content Team",
Agents: []*agent.Agent{researcher, writer},
Mode: team.ModeSequential,
})
if err != nil {
log.Fatal(err)
}
// Run team
output, _ := t.Run(context.Background(), "Write about AI")
fmt.Println(output.Content)
}
Coordination Modes
1. Sequential Mode
Agents execute one after another, output feeds to next agent.
t, _ := team.New(team.Config{
Name: "Pipeline",
Agents: []*agent.Agent{agent1, agent2, agent3},
Mode: team.ModeSequential,
})
Use Cases:
- Content pipelines (research → write → edit)
- Data processing workflows
- Multi-step reasoning
How it Works:
- Agent 1 processes input → Output A
- Agent 2 processes Output A → Output B
- Agent 3 processes Output B → Final Output
2. Parallel Mode
All agents execute simultaneously, results combined.
t, _ := team.New(team.Config{
Name: "Multi-Perspective",
Agents: []*agent.Agent{techAgent, bizAgent, ethicsAgent},
Mode: team.ModeParallel,
})
Use Cases:
- Multi-perspective analysis
- Parallel data processing
- Diverse opinions generation
How it Works:
- All agents receive same input
- Execute concurrently (Go goroutines)
- Results combined into single output
3. Leader-Follower Mode
Leader delegates tasks to followers and synthesizes results.
t, _ := team.New(team.Config{
Name: "Project Team",
Leader: leaderAgent,
Agents: []*agent.Agent{follower1, follower2},
Mode: team.ModeLeaderFollower,
})
Use Cases:
- Task delegation
- Hierarchical workflows
- Expert consultation
How it Works:
- Leader analyzes task and creates subtasks
- Delegates to appropriate followers
- Synthesizes follower outputs into final result
4. Consensus Mode
Agents discuss until reaching agreement.
t, _ := team.New(team.Config{
Name: "Decision Team",
Agents: []*agent.Agent{optimist, realist, critic},
Mode: team.ModeConsensus,
MaxRounds: 3, // Maximum discussion rounds
})
Use Cases:
- Decision making
- Quality assurance
- Debate and refinement
How it Works:
- All agents provide initial opinions
- Agents review others' opinions
- Iterate until consensus or max rounds
- Final consensus output
Configuration
Config Struct
type Config struct {
// Required
Agents []*agent.Agent // Team members
// Optional
Name string // Team name (default: "Team")
Mode CoordinationMode // Coordination mode (default: Sequential)
Leader *agent.Agent // Leader (for LeaderFollower mode)
MaxRounds int // Max rounds (for Consensus mode, default: 3)
}
Coordination Modes
const (
ModeSequential CoordinationMode = "sequential"
ModeParallel CoordinationMode = "parallel"
ModeLeaderFollower CoordinationMode = "leader-follower"
ModeConsensus CoordinationMode = "consensus"
)
API Reference
team.New
Create a new team instance.
Signature:
func New(config Config) (*Team, error)
Returns:
*Team
: Created team instanceerror
: Error if agents list is empty or invalid config
Team.Run
Execute the team with input.
Signature:
func (t *Team) Run(ctx context.Context, input string) (*RunOutput, error)
Parameters:
ctx
: Context for cancellation/timeoutinput
: User input string
Returns:
type RunOutput struct {
Content string // Final team output
AgentOutputs []AgentOutput // Individual agent outputs
Metadata map[string]interface{} // Additional metadata
}
Team.AddAgent / RemoveAgent
Manage team members dynamically.
Signatures:
func (t *Team) AddAgent(ag *agent.Agent)
func (t *Team) RemoveAgent(name string) error
func (t *Team) GetAgents() []*agent.Agent
Example:
// Add new agent
t.AddAgent(newAgent)
// Remove agent by name
err := t.RemoveAgent("OldAgent")
// Get all agents
agents := t.GetAgents()
Complete Examples
Sequential Team Example
Content creation pipeline with research → analysis → writing.
func createContentPipeline(apiKey string) {
model, _ := openai.New("gpt-4o-mini", openai.Config{APIKey: apiKey})
researcher, _ := agent.New(agent.Config{
Name: "Researcher",
Model: model,
Instructions: "Research the topic and provide key facts.",
})
analyst, _ := agent.New(agent.Config{
Name: "Analyst",
Model: model,
Instructions: "Analyze research findings and extract insights.",
})
writer, _ := agent.New(agent.Config{
Name: "Writer",
Model: model,
Instructions: "Write a concise summary based on insights.",
})
t, _ := team.New(team.Config{
Name: "Content Pipeline",
Agents: []*agent.Agent{researcher, analyst, writer},
Mode: team.ModeSequential,
})
output, _ := t.Run(context.Background(),
"Write about the benefits of AI in healthcare")
fmt.Println(output.Content)
}
Parallel Team Example
Multi-perspective analysis with concurrent execution.
func multiPerspectiveAnalysis(apiKey string) {
model, _ := openai.New("gpt-4o-mini", openai.Config{APIKey: apiKey})
techAgent, _ := agent.New(agent.Config{
Name: "Tech Specialist",
Model: model,
Instructions: "Focus on technical aspects.",
})
bizAgent, _ := agent.New(agent.Config{
Name: "Business Specialist",
Model: model,
Instructions: "Focus on business implications.",
})
ethicsAgent, _ := agent.New(agent.Config{
Name: "Ethics Specialist",
Model: model,
Instructions: "Focus on ethical considerations.",
})
t, _ := team.New(team.Config{
Name: "Analysis Team",
Agents: []*agent.Agent{techAgent, bizAgent, ethicsAgent},
Mode: team.ModeParallel,
})
output, _ := t.Run(context.Background(),
"Evaluate the impact of autonomous vehicles")
fmt.Println(output.Content)
}
Best Practices
1. Choose the Right Mode
- Sequential: Use when output depends on previous steps
- Parallel: Use when perspectives are independent
- Leader-Follower: Use when task delegation is needed
- Consensus: Use when quality and agreement are critical
2. Agent Specialization
Give each agent clear, specific instructions:
// Good ✅
Instructions: "You are a Python expert. Focus on code quality."
// Bad ❌
Instructions: "You help with coding."
3. Error Handling
Always handle errors from team operations:
output, err := t.Run(ctx, input)
if err != nil {
log.Printf("Team execution failed: %v", err)
return
}
4. Context Management
Use context for timeouts and cancellation:
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
output, err := t.Run(ctx, input)
Performance Considerations
Parallel Execution
Parallel mode uses Go goroutines for true concurrency:
// 3 agents execute simultaneously
t, _ := team.New(team.Config{
Agents: []*agent.Agent{a1, a2, a3},
Mode: team.ModeParallel,
})
// Total time ≈ slowest agent (not sum of all)
Memory Usage
Each agent maintains its own memory. For large teams:
// Clear memory after each run
output, _ := t.Run(ctx, input)
for _, ag := range t.GetAgents() {
ag.ClearMemory()
}
Next Steps
- Learn about Workflow for step-based orchestration
- Explore Models for different LLM providers
- Add Tools to enhance agent capabilities
- Check Team API Reference for detailed API docs
Related Examples
- Team Demo - Full working example
- Leader-Follower Pattern
- Consensus Decision Making