Access Dependencies in Team Tool

This example demonstrates how team tools can access dependencies passed to the team, allowing tools to utilize dynamic context like team metrics and current time information while team members collaborate with shared data sources.

Create a Python file

1from typing import Dict, Any, Optional
2from datetime import datetime
3
4from kern.agent import Agent
5from kern.team import Team
6from kern.models.openai import OpenAIResponses
7
8
9def get_current_context() -> dict:
10 """Get current contextual information like time, weather, etc."""
11 return {
12 "current_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
13 "timezone": "PST",
14 "day_of_week": datetime.now().strftime("%A"),
15 }
16
17def analyze_team_performance(team_id: str, dependencies: Optional[Dict[str, Any]] = None) -> str:
18 """
19 Analyze team performance using available data sources.
20
21 This tool analyzes team metrics and provides insights.
22 Call this tool with the team_id you want to analyze.
23
24 Args:
25 team_id: The team ID to analyze (e.g., 'engineering_team', 'sales_team')
26 dependencies: Available data sources (automatically provided)
27
28 Returns:
29 Detailed team performance analysis and insights
30 """
31 if not dependencies:
32 return "No data sources available for analysis."
33
34 print(f"--> Team tool received data sources: {list(dependencies.keys())}")
35
36 results = [f"=== TEAM PERFORMANCE ANALYSIS FOR {team_id.upper()} ==="]
37
38 if "team_metrics" in dependencies:
39 metrics_data = dependencies["team_metrics"]
40 results.append(f"Team Metrics: {metrics_data}")
41
42 if metrics_data.get("productivity_score"):
43 score = metrics_data["productivity_score"]
44 if score >= 8:
45 results.append(f"Performance Analysis: Excellent performance with {score}/10 productivity score")
46 elif score >= 6:
47 results.append(f"Performance Analysis: Good performance with {score}/10 productivity score")
48 else:
49 results.append(f"Performance Analysis: Needs improvement with {score}/10 productivity score")
50
51 if "current_context" in dependencies:
52 context_data = dependencies["current_context"]
53 results.append(f"Current Context: {context_data}")
54 results.append(f"Time-based Analysis: Team analysis performed on {context_data['day_of_week']} at {context_data['current_time']}")
55
56 print(f"--> Team tool returned results: {results}")
57
58 return "\n\n".join(results)
59
60data_analyst = Agent(
61 model=OpenAIResponses(id="gpt-5.2"),
62 name="Data Analyst",
63 description="Specialist in analyzing team metrics and performance data",
64 instructions=[
65 "You are a data analysis expert focusing on team performance metrics.",
66 "Interpret quantitative data and identify trends.",
67 "Provide data-driven insights and recommendations.",
68 ],
69)
70
71team_lead = Agent(
72 model=OpenAIResponses(id="gpt-5.2"),
73 name="Team Lead",
74 description="Experienced team leader who provides strategic insights",
75 instructions=[
76 "You are an experienced team leader and management expert.",
77 "Focus on leadership insights and team dynamics.",
78 "Provide strategic recommendations for team improvement.",
79 "Collaborate with the data analyst to get comprehensive insights.",
80 ],
81)
82
83performance_team = Team(
84 model=OpenAIResponses(id="gpt-5.2"),
85 members=[data_analyst, team_lead],
86 tools=[analyze_team_performance],
87 name="Team Performance Analysis Team",
88 description="A team specialized in analyzing team performance using integrated data sources.",
89 instructions=[
90 "You are a team performance analysis unit with access to team metrics and analysis tools.",
91 "When asked to analyze any team, use the analyze_team_performance tool first.",
92 "This tool has access to team metrics and current context through integrated data sources.",
93 "Data Analyst: Focus on the quantitative metrics and trends.",
94 "Team Lead: Provide strategic insights and management recommendations.",
95 "Work together to provide comprehensive team performance insights.",
96 ],
97)
98
99print("=== Team Tool Dependencies Access Example ===\n")
100
101response = performance_team.run(
102 input="Please analyze the 'engineering_team' performance and provide comprehensive insights about their productivity and recommendations for improvement.",
103 dependencies={
104 "team_metrics": {
105 "team_name": "Engineering Team Alpha",
106 "team_size": 8,
107 "productivity_score": 7.5,
108 "sprint_velocity": 85,
109 "bug_resolution_rate": 92,
110 "code_review_turnaround": "2.3 days",
111 "areas": ["Backend Development", "Frontend Development", "DevOps"],
112 },
113 "current_context": get_current_context,
114 },
115 session_id="test_team_tool_dependencies",
116)
117
118print(f"\nTeam Response: {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 access_dependencies_in_tool.py