Dependencies with Teams
Inject variables into team context with dependencies.
Dependencies are a way to inject variables into your Team context. The dependencies parameter accepts a dictionary containing functions or static variables that are automatically resolved before the team runs.
Note
You can use dependencies to inject memories, dynamic few-shot examples, "retrieved" documents, etc.
1from datetime import datetime23from kern.agent import Agent4from kern.models.openai import OpenAIResponses5from kern.team import Team678def get_user_profile() -> dict:9 """Get user profile information that can be referenced in responses."""10 profile = {11 "name": "John Doe",12 "preferences": {13 "communication_style": "professional",14 "topics_of_interest": ["AI/ML", "Software Engineering", "Finance"],15 "experience_level": "senior",16 },17 "location": "San Francisco, CA",18 "role": "Senior Software Engineer",19 }2021 return profile222324def get_current_context() -> dict:25 """Get current contextual information like time, weather, etc."""26 return {27 "current_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),28 "timezone": "PST",29 "day_of_week": datetime.now().strftime("%A"),30 }313233profile_agent = Agent(34 name="ProfileAnalyst",35 model=OpenAIResponses(id="gpt-5.2"),36 instructions="You analyze user profiles and provide personalized recommendations.",37)3839context_agent = Agent(40 name="ContextAnalyst",41 model=OpenAIResponses(id="gpt-5.2"),42 instructions="You analyze current context and timing to provide relevant insights.",43)4445team = Team(46 name="PersonalizationTeam",47 model=OpenAIResponses(id="gpt-5.2"),48 members=[profile_agent, context_agent],49 dependencies={50 "user_profile": get_user_profile,51 "current_context": get_current_context,52 },53 instructions=[54 "You are a personalization team that provides personalized recommendations based on the user's profile and context.",55 "Here is the user profile: {user_profile}",56 "Here is the current context: {current_context}",57 ],58 debug_mode=True,59 markdown=True,60)6162team.print_response(63 "Please provide me with a personalized summary of today's priorities based on my profile and interests.",64)✓
Dependencies are automatically resolved when the team is run.
Tip
You can set dependencies on Team initialization, or pass it to the run(), arun(), print_response() and aprint_response() methods. Use add_dependencies_to_context=True to automatically add all dependencies to the user message instead of referencing them in instructions.