Team with Knowledge Tools

This is a team reasoning example with knowledge tools.

Tip

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

Add the following code to your Python file

1from kern.agent import Agent
2from kern.knowledge.knowledge import Knowledge
3from kern.models.openai import OpenAIResponses
4from kern.team.team import Team
5from kern.tools.hackernews import HackerNewsTools
6from kern.tools.knowledge import KnowledgeTools
7from kern.vectordb.lancedb import LanceDb, SearchType
8
9agno_docs = Knowledge(
10 # Use LanceDB as the vector database and store embeddings in the `agno_docs` table
11 vector_db=LanceDb(
12 uri="tmp/lancedb",
13 table_name="agno_docs",
14 search_type=SearchType.hybrid,
15 ),
16)
17# Add content to the knowledge
18agno_docs.insert(url="https://www.paulgraham.com/read.html")
19
20knowledge_tools = KnowledgeTools(
21 knowledge=agno_docs,
22 think=True,
23 search=True,
24 analyze=True,
25 add_few_shot=True,
26)
27
28web_agent = Agent(
29 name="Web Search Agent",
30 role="Handle web search requests",
31 model=OpenAIResponses(id="gpt-5.2"),
32 tools=[HackerNewsTools()],
33 instructions="Always include sources",
34 add_datetime_to_context=True,
35)
36
37finance_agent = Agent(
38 name="Finance Agent",
39 role="Handle financial data requests",
40 model=OpenAIResponses(id="gpt-5.2"),
41 tools=[HackerNewsTools()],
42 add_datetime_to_context=True,
43)
44
45team_leader = Team(
46 name="Reasoning Finance Team",
47 model=OpenAIResponses(id="gpt-5.2"),
48 members=[
49 web_agent,
50 finance_agent,
51 ],
52 tools=[knowledge_tools],
53 instructions=[
54 "Only output the final answer, no other text.",
55 "Use tables to display data",
56 ],
57 markdown=True,
58 show_members_responses=True,
59 add_datetime_to_context=True,
60)
61
62
63def run_team(task: str):
64 team_leader.print_response(
65 task,
66 stream=True,
67 show_full_reasoning=True,
68 )
69
70
71if __name__ == "__main__":
72 run_team("What does Paul Graham talk about the need to read in this essay?")

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

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 Agent

1python knowledge_tool_team.py