Using Reference Dependencies in Team Instructions
This example demonstrates how to use reference dependencies by defining them in the team constructor and referencing them directly in team instructions. This approach allows dependencies to be automatically injected into the team's context and referenced using template variables in instructions.
Create a Python file
1from datetime import datetime23from kern.agent import Agent4from kern.models.openai import OpenAIResponses5from kern.team import Team678def 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 }2223 return profiles.get(user_id, {"name": "Unknown User"})242526def 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 }333435profile_agent = Agent(36 name="ProfileAnalyst",37 model=OpenAIResponses(id="gpt-5.2"),38 instructions="You analyze user profiles and provide personalized recommendations.",39)4041context_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)4647team = Team(48 name="PersonalizationTeam",49 model=OpenAIResponses(id="gpt-5.2"),50 members=[profile_agent, context_agent],51 dependencies={52 "user_profile": get_user_profile,53 "current_context": get_current_context,54 },55 instructions=[56 "You are a personalization team that provides personalized recommendations based on the user's profile and context.",57 "Here is the user profile: {user_profile}",58 "Here is the current context: {current_context}",59 ],60 debug_mode=True,61 markdown=True,62)6364response = team.run(65 "Please provide me with a personalized summary of today's priorities based on my profile and interests.",66)6768print(response.content)Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U kern-ai openaiExport your OpenAI API key
1export OPENAI_API_KEY=your_openai_api_key_hereRun Team
1python reference_dependencies.py