Skip to main content
This example demonstrates how agents automatically inherit the model from their parent team. When the Team has a model:
  • Agents without a model use the Team’s model
  • Agents with their own model keep their own model
  • In nested teams, agents use the model from their direct parent team
  • All model types are inherited: model, reasoning_model, parser_model, output_model
When the Team has no model:
  • The Team and all agents default to OpenAI gpt-4o
model_inheritance.py
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.models.openai import OpenAIChat
from agno.team.team import Team

# These agents don't have models set
researcher = Agent(
    name="Researcher",
    role="Research and gather information",
    instructions=["Be thorough and detailed"],
)

writer = Agent(
    name="Writer",
    role="Write content based on research",
    instructions=["Write clearly and concisely"],
)

# This agent has a model set
editor = Agent(
    name="Editor",
    role="Edit and refine content",
    model=OpenAIChat(id="gpt-4o-mini"),
    instructions=["Ensure clarity and correctness"],
)

# Nested team setup
analyst = Agent(
    name="Analyst",
    role="Analyze data and provide insights",
)

sub_team = Team(
    name="Analysis Team",
    model=Claude(id="claude-3-5-haiku-20241022"),
    members=[analyst],
)

team = Team(
    name="Content Production Team",
    model=Claude(id="claude-3-5-sonnet-20241022"),
    members=[researcher, writer, editor, sub_team],
    instructions=[
        "Research the topic thoroughly",
        "Write clear and engaging content",
        "Edit for quality and clarity",
        "Coordinate the entire process",
    ],
    show_members_responses=True,
)

team.initialize_team()

# researcher and writer inherit Claude Sonnet from team
print(f"Researcher model: {researcher.model.id}")
print(f"Writer model: {writer.model.id}")

# editor keeps its explicit model
print(f"Editor model: {editor.model.id}")

# analyst inherits Claude Haiku from its sub-team
print(f"Analyst model: {analyst.model.id}")

team.print_response(
    "Write a brief article about AI", stream=True
)

Usage

1

Create a virtual environment

Open the Terminal and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
2

Install required libraries

pip install agno anthropic openai
3

Set environment variables

export ANTHROPIC_API_KEY=****
export OPENAI_API_KEY=****
4

Run the agent

python model_inheritance.py