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 dedent23from kern.agent import Agent4from kern.models.anthropic import Claude5from kern.models.openai import OpenAIResponses6from kern.team.team import Team7from kern.tools.hackernews import HackerNewsTools8from kern.tools.reasoning import ReasoningTools910web_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)1819finance_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)3334team_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)505152def run_team(task: str):53 team_leader.print_response(54 task,55 stream=True,56 show_full_reasoning=True,57 )585960if __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)6869 For each sector:70 1. Compare stock performance before and after tariff implementation71 2. Identify supply chain disruptions and cost impact percentages72 3. Analyze companies' strategic responses (reshoring, price adjustments, supplier diversification)73 4. Assess analyst outlook changes directly attributed to tariff policies74 """)75 )7677 # 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."""))8384 # 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."""))9091 # 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."""))9899 # 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."""))106107 # run_team(dedent("""\108 # Compare the financial metrics of Apple (AAPL) and Google (GOOGL):109 # - Market Cap110 # - P/E Ratio111 # - Revenue Growth112 # - Profit Margin"""))113114 # 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.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U openai anthropic kern-ai ddgsExport 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