Team with Reasoning Tools

This is a multi-agent team reasoning example with reasoning tools.

Tip

Enabling the reasoning option on the team leader helps optimize delegation and enhances multi-agent collaboration by selectively invoking deeper reasoning when required.

Add the following code to your Python file

1from textwrap import dedent
2
3from kern.agent import Agent
4from kern.models.anthropic import Claude
5from kern.models.openai import OpenAIResponses
6from kern.team.team import Team
7from kern.tools.hackernews import HackerNewsTools
8from kern.tools.reasoning import ReasoningTools
9
10web_agent = Agent(
11 name="Web Search Agent",
12 role="Handle web search requests",
13 model=OpenAIResponses(id="gpt-5.2"),
14 tools=[HackerNewsTools()],
15 instructions="Always include sources",
16 add_datetime_to_context=True,
17)
18
19finance_agent = Agent(
20 name="Finance Agent",
21 role="Handle financial data requests",
22 model=OpenAIResponses(id="gpt-5.2"),
23 tools=[HackerNewsTools()],
24 instructions=[
25 "You are a financial data specialist. Provide concise and accurate data.",
26 "Use tables to display stock prices, fundamentals (P/E, Market Cap), and recommendations.",
27 "Clearly state the company name and ticker symbol.",
28 "Briefly summarize recent company-specific news if available.",
29 "Focus on delivering the requested financial data points clearly.",
30 ],
31 add_datetime_to_context=True,
32)
33
34team_leader = Team(
35 name="Reasoning Finance Team Leader",
36 model=Claude(id="claude-sonnet-4-5"),
37 members=[
38 web_agent,
39 finance_agent,
40 ],
41 tools=[ReasoningTools(add_instructions=True)],
42 instructions=[
43 "Only output the final answer, no other text.",
44 "Use tables to display data",
45 ],
46 markdown=True,
47 show_members_responses=True,
48 add_datetime_to_context=True,
49)
50
51
52def run_team(task: str):
53 team_leader.print_response(
54 task,
55 stream=True,
56 show_full_reasoning=True,
57 )
58
59
60if __name__ == "__main__":
61 run_team(
62 dedent("""\
63 Analyze the impact of recent US tariffs on market performance across these key sectors:
64 - Steel & Aluminum: (X, NUE, AA)
65 - Technology Hardware: (AAPL, DELL, HPQ)
66 - Agricultural Products: (ADM, BG, INGR)
67 - Automotive: (F, GM, TSLA)
68
69 For each sector:
70 1. Compare stock performance before and after tariff implementation
71 2. Identify supply chain disruptions and cost impact percentages
72 3. Analyze companies' strategic responses (reshoring, price adjustments, supplier diversification)
73 4. Assess analyst outlook changes directly attributed to tariff policies
74 """)
75 )
76
77 # run_team(dedent("""\
78 # Assess the impact of recent semiconductor export controls on:
79 # - US chip designers (Nvidia, AMD, Intel)
80 # - Asian manufacturers (TSMC, Samsung)
81 # - Equipment makers (ASML, Applied Materials)
82 # Include effects on R&D investments, supply chain restructuring, and market share shifts."""))
83
84 # run_team(dedent("""\
85 # Compare the retail sector's response to consumer goods tariffs:
86 # - Major retailers (Walmart, Target, Amazon)
87 # - Consumer brands (Nike, Apple, Hasbro)
88 # - Discount retailers (Dollar General, Five Below)
89 # Include pricing strategy changes, inventory management, and consumer behavior impacts."""))
90
91 # run_team(dedent("""\
92 # Analyze the semiconductor market performance focusing on:
93 # - NVIDIA (NVDA)
94 # - AMD (AMD)
95 # - Intel (INTC)
96 # - Taiwan Semiconductor (TSM)
97 # Compare their market positions, growth metrics, and future outlook."""))
98
99 # run_team(dedent("""\
100 # Evaluate the automotive industry's current state:
101 # - Tesla (TSLA)
102 # - Ford (F)
103 # - General Motors (GM)
104 # - Toyota (TM)
105 # Include EV transition progress and traditional auto metrics."""))
106
107 # run_team(dedent("""\
108 # Compare the financial metrics of Apple (AAPL) and Google (GOOGL):
109 # - Market Cap
110 # - P/E Ratio
111 # - Revenue Growth
112 # - Profit Margin"""))
113
114 # run_team(dedent("""\
115 # Analyze the impact of recent Chinese solar panel tariffs on:
116 # - US solar manufacturers (First Solar, SunPower)
117 # - Chinese exporters (JinkoSolar, Trina Solar)
118 # - US installation companies (Sunrun, SunPower)
119 # Include effects on pricing, supply chains, and installation rates."""))

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 openai anthropic kern-ai ddgs

Export your API keys

1export OPENAI_API_KEY="your_openai_api_key_here"
2 export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
1$Env:OPENAI_API_KEY="your_openai_api_key_here"
2$Env:ANTHROPIC_API_KEY="your_anthropic_api_key_here"

Run Agent

1python reasoning_finance_team.py