Async Team with Tools

This example demonstrates how to create an async team with various tools for information gathering using multiple agents with different tools to gather comprehensive information asynchronously.

Code

1import asyncio
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from kern.team import Team
6from kern.tools.hackernews import HackerNewsTools
7from kern.tools.yfinance import YFinanceTools
8
9# HackerNews agent
10news_agent = Agent(
11 name="News Agent",
12 role="Search HackerNews for tech news",
13 model=OpenAIResponses(id="gpt-5.2"),
14 tools=[HackerNewsTools()],
15 instructions=[
16 "Find the latest tech news and discussions",
17 ],
18)
19
20# Finance agent
21finance_agent = Agent(
22 name="Finance Agent",
23 role="Get stock prices and financial data",
24 model=OpenAIResponses(id="gpt-5.2"),
25 tools=[YFinanceTools()],
26 instructions=[
27 "Get stock prices and financial information",
28 ],
29)
30
31# Create the research team
32research_team = Team(
33 name="Research Team",
34 model=OpenAIResponses(id="gpt-5.2"),
35 members=[
36 news_agent,
37 finance_agent,
38 ],
39 markdown=True,
40 instructions=[
41 "You are a team that researches companies.",
42 "Use the news agent to find recent discussions and the finance agent for stock data.",
43 ],
44 show_members_responses=True,
45)
46
47if __name__ == "__main__":
48 asyncio.run(
49 research_team.aprint_response(
50 "Research NVIDIA - get the current stock price and find any recent HackerNews discussions about the company.",
51 stream=True,
52 )
53 )

Usage

Create a Python file

Create async_team_with_tools.py with the code above.

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 yfinance

Export your OpenAI API key

1export OPENAI_API_KEY="your_openai_api_key_here"
1$Env:OPENAI_API_KEY="your_openai_api_key_here"

Run Team

1python async_team_with_tools.py