> ## Documentation Index
> Fetch the complete documentation index at: https://docs.upsonic.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Team

> Build teams of AI agents that work together

<img src="https://mintcdn.com/upsonic/lEfVQiA3d4Ew-NMK/images/concepts-team.png?fit=max&auto=format&n=lEfVQiA3d4Ew-NMK&q=85&s=5d796530543ba3b6aa2b2471e0e29f2c" alt="Concepts Team" width="1728" height="573" data-path="images/concepts-team.png" />

## Overview

### What is Team?

The Team class is a callable class for multi-agent operations using the Upsonic client. It enables you to create teams of specialized AI agents that can work together to accomplish complex tasks that would be difficult for a single agent to handle.

### How Team Works?

Teams handle all the complexity automatically through several key mechanisms:

* **Smart Assignment** - Automatically picks the right agent for each task based on their roles and capabilities
* **Context Sharing** - Agents receive context from previous tasks and can see what other agents have accomplished
* **Result Combining** - Combines all outputs from multiple agents into one coherent final answer
* **Coordination** (in coordinate mode) - A leader agent plans and delegates work strategically
* **Routing** (in route mode) - Intelligent expert selection for specialized queries

You just define your agents and tasks - the team handles the rest.

## Attributes

The Team class accepts the following parameters:

| Parameter                | Type                                           | Default        | Description                                         |
| ------------------------ | ---------------------------------------------- | -------------- | --------------------------------------------------- |
| `agents`                 | `list[Any]`                                    | Required       | List of Agent instances to use as team members      |
| `tasks`                  | `list[Task] \| None`                           | `None`         | List of tasks to execute (optional)                 |
| `model`                  | `Optional[Any]`                                | `None`         | Model provider for internal agents (leader, router) |
| `response_format`        | `Any`                                          | `str`          | Response format for the final output                |
| `ask_other_team_members` | `bool`                                         | `False`        | Flag to add other agents as tools                   |
| `mode`                   | `Literal["sequential", "coordinate", "route"]` | `"sequential"` | Operational mode for the team                       |
| `memory`                 | `Optional[Memory]`                             | `None`         | Shared memory for team coordination                 |

## Choosing Right Team Mode

### What is The Selection Criteria?

Choose your team mode based on your workflow requirements:

* **Sequential**: For linear workflows where tasks flow from one agent to the next
* **Coordinate**: For complex projects requiring strategic planning and delegation
* **Route**: For routing queries to the best specialist agent

### Use Case for Sequential Mode

Use sequential mode when:

* You have a clear sequence of steps
* Each step needs a different skill
* Tasks build on previous results
* You want simple, automatic collaboration

**Example:** Research → Write → Edit → Publish

### Use Case for Coordinate Mode

Use coordinate mode when:

* Tasks are complex and interconnected
* You need strategic planning
* The workflow isn't linear
* You want a leader making decisions

**Example:** Building a complete software project with architecture, development, testing, and deployment

### Use Case for Route Mode

Use route mode when:

* You have specialized experts
* Each request goes to ONE expert
* You need fast routing decisions
* No multi-step collaboration needed

**Example:** Customer support routing (billing → billing expert, technical → tech support)

## Modes

### Sequential

#### What is Sequential Team mode

Sequential mode is the default and most straightforward team operation mode. Tasks flow from one agent to the next automatically, with the team intelligently selecting the best agent for each task based on their roles and capabilities.

#### Usage

```python theme={null}
from upsonic import Agent, Task, Team

# Create specialized agents
researcher = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Researcher",
    role="Research Specialist",
    goal="Find accurate information and data"
)

writer = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Writer",
    role="Content Writer",
    goal="Create clear and engaging content"
)

# Create sequential team
team = Team(
    agents=[researcher, writer],
    mode="sequential"
)

# Define tasks
tasks = [
    Task(description="Research the latest developments in quantum computing"),
    Task(description="Write a blog post about quantum computing for general audience")
]

# Execute team workflow
result = team.do(tasks)
print(result)
```

#### Params

* `agents`: List of Agent instances
* `mode`: Set to `"sequential"`
* `response_format`: Optional, defaults to `str`
* `ask_other_team_members`: Optional, enables inter-agent communication

### Coordinate

#### What is Coordinate Team mode

Coordinate mode introduces a leader agent that takes charge of the entire workflow. The leader analyzes all tasks, creates a strategic plan, and delegates work to team members using a sophisticated delegation system.

#### Usage

```python theme={null}
from upsonic import Agent, Task, Team

# Create specialized agents
data_analyst = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Data Analyst",
    role="Data Analysis Expert",
    goal="Analyze data and extract insights"
)

report_writer = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Report Writer",
    role="Business Report Specialist",
    goal="Create professional business reports"
)

# Create team with coordination
team = Team(
    agents=[data_analyst, report_writer],
    mode="coordinate",
    model="anthropic/claude-sonnet-4-5"  # Required for leader agent
)

# Define tasks
tasks = [
    Task(description="Analyze Q4 sales data and identify trends"),
    Task(description="Create executive summary of findings")
]

# Leader agent coordinates the team
result = team.print_do(tasks)
print(result)
```

#### Params

* `agents`: List of Agent instances
* `mode`: Set to `"coordinate"`
* `model`: **Required** - Model provider for the leader agent
* `memory`: Optional - Shared memory for team coordination
* `response_format`: Optional, defaults to `str`

### Route

#### What is Route Team mode

Route mode uses an intelligent router agent to analyze incoming requests and select the single best specialist agent to handle the entire task. This is ideal for scenarios where you have domain experts and need to route queries efficiently.

#### Usage

```python theme={null}
from upsonic import Agent, Task, Team

# Create domain specialists
legal_expert = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Legal Expert",
    role="Legal Advisor",
    goal="Provide legal guidance and compliance information",
    system_prompt="You are an expert in corporate law and regulations"
)

tech_expert = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Tech Expert",
    role="Technology Specialist",
    goal="Provide technical solutions and architecture advice",
    system_prompt="You are an expert in software architecture and cloud systems"
)

# Create routing team
team = Team(
    agents=[legal_expert, tech_expert],
    mode="route",
    model="anthropic/claude-sonnet-4-5"  # Required for router agent
)

# Router selects best expert
task = Task(description="What are the best practices for implementing OAuth 2.0?")
result = team.do(task)  # Automatically routed to tech_expert
print(result)
```

#### Params

* `agents`: List of Agent instances
* `mode`: Set to `"route"`
* `model`: **Required** - Model provider for the router agent
* `response_format`: Optional, defaults to `str`

## Assigning Tasks Manually

### Assigning Tasks to Agents Manually

You can explicitly assign specific agents to tasks by setting the `agent` property on the Task object. This overrides the automatic agent selection process.

### Full Example Code

```python theme={null}
from upsonic import Agent, Task, Team

# Create specialized agents
writer = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Writer",
    role="Content Writer",
    goal="Create engaging content"
)

editor = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Editor",
    role="Content Editor",
    goal="Polish and improve content"
)

# Create team
team = Team(agents=[writer, editor], mode="sequential")

# Explicitly assign agents to tasks
task1 = Task(description="Write a product description")
task1.agent = writer  # Force this task to use writer

task2 = Task(description="Edit and polish the description")
task2.agent = editor  # Force this task to use editor

# Execute with manual assignments
result = team.do([task1, task2])
print(result)
```

## Examples

### Basic Team Example

#### About Example Scenario

This example demonstrates a content creation workflow where a research agent gathers information about AI trends, and a writer agent creates a blog post based on that research.

#### Team Configuration

* **Mode**: Sequential (default)
* **Agents**: Research Specialist + Content Writer
* **Workflow**: Research → Write
* **Context Sharing**: Automatic between tasks

#### Full Code

```python theme={null}
from upsonic import Agent, Task, Team

# Create specialized agents
researcher = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Researcher",
    role="Research Specialist",
    goal="Find accurate information and data"
)

writer = Agent(
    model="anthropic/claude-sonnet-4-5",
    name="Writer",
    role="Content Writer",
    goal="Create clear and engaging content"
)

# Create team
team = Team(
    agents=[researcher, writer],
    mode="sequential"
)

# Define tasks
tasks = [
    Task(description="Research the latest developments in quantum computing"),
    Task(description="Write a blog post about quantum computing for general audience")
]

# Execute team workflow
result = team.do(tasks)
print(result)
```
