Reasoning Agent with Knowledge Tools

Add the following code to your Python file

1from kern.agent import Agent
2from kern.knowledge.embedder.openai import OpenAIEmbedder
3from kern.knowledge.knowledge import Knowledge
4from kern.models.openai import OpenAIResponses
5from kern.tools.knowledge import KnowledgeTools
6from kern.vectordb.lancedb import LanceDb, SearchType
7
8# Create a knowledge containing information from a URL
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 embedder=OpenAIEmbedder(id="text-embedding-3-small"),
16 ),
17)
18# Add content to the knowledge
19agno_docs.insert(url="https://kern.ndx.rocks/llms-full.txt")
20
21knowledge_tools = KnowledgeTools(
22 knowledge=agno_docs,
23 think=True,
24 search=True,
25 analyze=True,
26 add_few_shot=True,
27)
28
29agent = Agent(
30 model=OpenAIResponses(id="gpt-5.2"),
31 tools=[knowledge_tools],
32 markdown=True,
33)
34
35if __name__ == "__main__":
36 agent.print_response(
37 "How do I build a team of agents in kern?",
38 markdown=True,
39 stream=True,
40 stream_tools=True,
41 )

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 lancedb

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_tools.py