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 datetime
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from kern.team import Team
6
7
8def 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 }
20
21 return profile
22
23
24def 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 }
31
32
33profile_agent = Agent(
34 name="ProfileAnalyst",
35 model=OpenAIResponses(id="gpt-5.2"),
36 instructions="You analyze user profiles and provide personalized recommendations.",
37)
38
39context_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)
44
45team = 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)
61
62team.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.

Learn more