Dependencies In Context

Demonstrates team-level dependencies referenced directly in instructions and member context.

dependencies_in_context.py
"""
Dependencies In Context
=============================

Demonstrates team-level dependencies referenced directly in instructions and member context.
"""

from datetime import datetime

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.team import Team


# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
def get_user_profile(user_id: str = "john_doe") -> dict:
    """Get user profile information that can be referenced in responses."""
    profiles = {
        "john_doe": {
            "name": "John Doe",
            "preferences": {
                "communication_style": "professional",
                "topics_of_interest": ["AI/ML", "Software Engineering", "Finance"],
                "experience_level": "senior",
            },
            "location": "San Francisco, CA",
            "role": "Senior Software Engineer",
        }
    }

    return profiles.get(user_id, {"name": "Unknown User"})


def get_current_context() -> dict:
    """Get current contextual information like time, weather, etc."""
    return {
        "current_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        "timezone": "PST",
        "day_of_week": datetime.now().strftime("%A"),
    }


# ---------------------------------------------------------------------------
# Create Members
# ---------------------------------------------------------------------------
profile_agent = Agent(
    name="ProfileAnalyst",
    model=OpenAIResponses(id="gpt-5.2"),
    instructions="You analyze user profiles and provide personalized recommendations.",
)

context_agent = Agent(
    name="ContextAnalyst",
    model=OpenAIResponses(id="gpt-5.2"),
    instructions="You analyze current context and timing to provide relevant insights.",
)

# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------
team = Team(
    name="PersonalizationTeam",
    model=OpenAIResponses(id="gpt-5.2"),
    members=[profile_agent, context_agent],
    dependencies={
        "user_profile": get_user_profile,
        "current_context": get_current_context,
    },
    add_dependencies_to_context=True,
    instructions=[
        "You are a personalization team that provides personalized recommendations based on the user's profile and context.",
        "Here is the user profile: {user_profile}",
        "Here is the current context: {current_context}",
    ],
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Team
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    response = team.run(
        "Please provide me with a personalized summary of today's priorities based on my profile and interests.",
    )

    print(response.content)

The profile helper defaults to the demonstration user john_doe. The dependency resolver supplies agent, team or run_context when requested; it does not inject a bare user_id parameter. For multiple users, accept run_context: RunContext and select the profile using run_context.user_id.

The source's get_current_context() labels the machine's local time as PST. Replace that helper with a timezone-aware version if you want the San Francisco profile's local time:

from zoneinfo import ZoneInfo

def get_current_context() -> dict:
    now = datetime.now(ZoneInfo("America/Los_Angeles"))
    return {
        "current_time": now.strftime("%Y-%m-%d %H:%M:%S"),
        "timezone": now.tzname(),
        "day_of_week": now.strftime("%A"),
    }

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as dependencies_in_context.py, then run:

python dependencies_in_context.py

Full source: cookbook/03_teams/17_dependencies/dependencies_in_context.py