Load Team from Database
Fetch a stored team from PostgresDb with get_team_by_id and stream its response, with get_teams shown for listing all.
Demonstrates loading a team from the database by ID and running it.
"""
Load Team from Database
=======================
Demonstrates loading a team from the database by ID and running it.
"""
from agno.db.postgres import PostgresDb
from agno.team.team import get_team_by_id, get_teams # noqa: F401
# ---------------------------------------------------------------------------
# Create Database Client
# ---------------------------------------------------------------------------
db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")
# ---------------------------------------------------------------------------
# Run Team Load Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
team = get_team_by_id(db=db, id="content-team")
if team:
team.print_response("Write about the history of the internet.", stream=True)
else:
print("Team not found")
# You can also get all teams from the database
# teams = get_teams(db=db)
# for team in teams:
# print(team)Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno "psycopg[binary]" openai sqlalchemyExport your API keys
export OPENAI_API_KEY="your_openai_api_key_here"Run PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql \
-v pgvolume:/var/lib/postgresql \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18Clone Agno
Clone the pinned Agno source and run the remaining commands from its root:
git clone https://github.com/agno-agi/agno.git
cd agno
git checkout v3.0.4Save the team
Persist the content-team record before loading it:
python cookbook/93_components/save_team.pyRun the example
Run the example from the repository root:
python cookbook/93_components/get_team.pyFull source: cookbook/93_components/get_team.py