Adding Dependencies to Team Run

This example demonstrates how to add dependencies to a specific team run. Dependencies are functions that provide contextual information (like user profiles and current context) that get passed to the team during execution for personalized responses.

Create a Python file

1from datetime import datetime
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from kern.team import Team
6
7
8def get_user_profile(user_id: str = "john_doe") -> dict:
9 """Get user profile information that can be referenced in responses."""
10 profiles = {
11 "john_doe": {
12 "name": "John Doe",
13 "preferences": {
14 "communication_style": "professional",
15 "topics_of_interest": ["AI/ML", "Software Engineering", "Finance"],
16 "experience_level": "senior",
17 },
18 "location": "San Francisco, CA",
19 "role": "Senior Software Engineer",
20 }
21 }
22
23 return profiles.get(user_id, {"name": "Unknown User"})
24
25
26def get_current_context() -> dict:
27 """Get current contextual information like time, weather, etc."""
28 return {
29 "current_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
30 "timezone": "PST",
31 "day_of_week": datetime.now().strftime("%A"),
32 }
33
34
35profile_agent = Agent(
36 name="ProfileAnalyst",
37 model=OpenAIResponses(id="gpt-5.2"),
38 instructions="You analyze user profiles and provide personalized recommendations.",
39)
40
41context_agent = Agent(
42 name="ContextAnalyst",
43 model=OpenAIResponses(id="gpt-5.2"),
44 instructions="You analyze current context and timing to provide relevant insights.",
45)
46
47team = Team(
48 name="PersonalizationTeam",
49 model=OpenAIResponses(id="gpt-5.2"),
50 members=[profile_agent, context_agent],
51 markdown=True,
52)
53
54response = team.run(
55 "Please provide me with a personalized summary of today's priorities based on my profile and interests.",
56 dependencies={
57 "user_profile": get_user_profile,
58 "current_context": get_current_context,
59 },
60 add_dependencies_to_context=True,
61)
62
63print(response.content)

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Install dependencies

1uv pip install -U kern-ai openai

Export your OpenAI API key

1export OPENAI_API_KEY=your_openai_api_key_here

Run Team

1python add_dependencies_on_run.py