> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Nested Team History

> Demonstrates how nested teams (teams as members of other teams) maintain their own conversation history across multiple delegations.

```python nested_team_history.py theme={null}
"""
Nested Team History
===================

Demonstrates how nested teams (teams as members of other teams) maintain
their own conversation history across multiple delegations.

Key concept: When a parent team delegates to a nested team, the nested team
receives its previous conversation history via `add_history_to_context=True`.
"""

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.team import Team

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = SqliteDb(db_file="tmp/nested_team_history.db")

# ---------------------------------------------------------------------------
# Create Nested Team
# ---------------------------------------------------------------------------
analyst = Agent(
    name="Data Analyst",
    model=OpenAIResponses(id="gpt-5.6-sol"),
    role="Analyze data and provide insights",
)

research_team = Team(
    name="Research Team",
    model=OpenAIResponses(id="gpt-5.6-sol"),
    members=[analyst],
    add_history_to_context=True,
    role="Conduct research and analysis",
)

# ---------------------------------------------------------------------------
# Create Parent Team
# ---------------------------------------------------------------------------
writer = Agent(
    name="Writer",
    model=OpenAIResponses(id="gpt-5.6-sol"),
    role="Write and format outputs",
)

main_team = Team(
    name="Main Team",
    model=OpenAIResponses(id="gpt-5.6-sol"),
    members=[writer, research_team],
    db=db,
    add_history_to_context=True,
    mode="route",
    show_members_responses=True,
)

# ---------------------------------------------------------------------------
# Run Multi-Turn Conversation
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    session_id = "nested-team-demo"

    # Turn 1: Research request
    main_team.print_response(
        "Research the top 3 benefits of AI coding assistants",
        session_id=session_id,
        stream=True,
    )

    # Turn 2: Follow-up - research team should remember Turn 1
    main_team.print_response(
        "Based on your research, which benefit is best for startups?",
        session_id=session_id,
        stream=True,
    )

    # Turn 3: Another follow-up
    main_team.print_response(
        "What challenges might startups face adopting that?",
        session_id=session_id,
        stream=True,
    )
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno openai sqlalchemy
```

**2. Export your OpenAI API key**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Run the example**

Save the code above as `nested_team_history.py`, then run:

```bash theme={null}
python nested_team_history.py
```

Full source: [cookbook/03\_teams/07\_session/nested\_team\_history.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/03_teams/07_session/nested_team_history.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.