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.34The team has access to a knowledge base with Kern documentation and can combine5this knowledge with web search capabilities.6"""78from pathlib import Path910from kern.agent import Agent11from kern.knowledge.embedder.openai import OpenAIEmbedder12from kern.knowledge.knowledge import Knowledge13from kern.models.openai import OpenAIResponses14from kern.team import Team15from kern.tools.hackernews import HackerNewsTools16from kern.vectordb.lancedb import LanceDb, SearchType1718# Setup paths for knowledge storage19cwd = Path(__file__).parent20tmp_dir = cwd.joinpath("tmp")21tmp_dir.mkdir(parents=True, exist_ok=True)2223# Initialize knowledge base with vector database24agno_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)3233# Add content to knowledge base34agno_docs_knowledge.insert(url="https://kern.ndx.rocks/llms-full.txt")3536# Create HackerNews agent for supplementary tech news37hackernews_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)4445# Create team with knowledge base integration46team_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)5455if __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.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U kern-ai lancedbSet environment variables
1export OPENAI_API_KEY=****Run the agent
1python cookbook/02_examples/teams/knowledge/01_team_with_knowledge.py