Team with Knowledge Base

This example demonstrates how to create a team with knowledge base integration. The team has access to a knowledge base with Kern documentation and can combine this knowledge with web search capabilities.

Code

1"""
2This example demonstrates how to create a team with knowledge base integration.
3
4The team has access to a knowledge base with Kern documentation and can combine
5this knowledge with web search capabilities.
6"""
7
8from pathlib import Path
9
10from kern.agent import Agent
11from kern.knowledge.embedder.openai import OpenAIEmbedder
12from kern.knowledge.knowledge import Knowledge
13from kern.models.openai import OpenAIResponses
14from kern.team import Team
15from kern.tools.hackernews import HackerNewsTools
16from kern.vectordb.lancedb import LanceDb, SearchType
17
18# Setup paths for knowledge storage
19cwd = Path(__file__).parent
20tmp_dir = cwd.joinpath("tmp")
21tmp_dir.mkdir(parents=True, exist_ok=True)
22
23# Initialize knowledge base with vector database
24agno_docs_knowledge = Knowledge(
25 vector_db=LanceDb(
26 uri=str(tmp_dir.joinpath("lancedb")),
27 table_name="agno_docs",
28 search_type=SearchType.hybrid,
29 embedder=OpenAIEmbedder(id="text-embedding-3-small"),
30 ),
31)
32
33# Add content to knowledge base
34agno_docs_knowledge.insert(url="https://kern.ndx.rocks/llms-full.txt")
35
36# Create HackerNews agent for supplementary tech news
37hackernews_agent = Agent(
38 name="HackerNews Agent",
39 role="Search HackerNews for tech news",
40 model=OpenAIResponses(id="gpt-5.2"),
41 tools=[HackerNewsTools()],
42 instructions=["Always include sources"],
43)
44
45# Create team with knowledge base integration
46team_with_knowledge = Team(
47 name="Team with Knowledge",
48 members=[hackernews_agent],
49 model=OpenAIResponses(id="gpt-5.2"),
50 knowledge=agno_docs_knowledge,
51 show_members_responses=True,
52 markdown=True,
53)
54
55if __name__ == "__main__":
56 team_with_knowledge.print_response("Tell me about the Kern framework", stream=True)

Usage

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 lancedb

Set environment variables

1export OPENAI_API_KEY=****

Run the agent

1python cookbook/02_examples/teams/knowledge/01_team_with_knowledge.py