Knowledge Tools

The KnowledgeTools toolkit enables Agents to search, retrieve, and analyze information from knowledge bases. This toolkit integrates with Knowledge and provides a structured workflow for finding and evaluating relevant information before responding to users.

The toolkit implements a "Think → Search → Analyze" cycle that allows an Agent to:

  1. Think through the problem and plan search queries
  2. Search the knowledge base for relevant information
  3. Analyze the results to determine if they are sufficient or if additional searches are needed

This approach significantly improves an Agent's ability to provide accurate information by giving it tools to find, evaluate, and synthesize knowledge.

The toolkit includes the following tools:

  • think: A scratchpad for planning, brainstorming keywords, and refining approaches. These thoughts remain internal to the Agent and are not shown to users.
  • search: Executes queries against the knowledge base to retrieve relevant documents.
  • analyze: Evaluates whether the returned documents are correct and sufficient, determining if further searches are needed.

Example

Here's an example of how to use the KnowledgeTools toolkit:

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 base 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)
18agno_docs.insert(
19 url="https://kern.ndx.rocks/llms-full.txt"
20)
21
22knowledge_tools = KnowledgeTools(
23 knowledge=agno_docs,
24 think=True,
25 search=True,
26 analyze=True,
27 add_few_shot=True,
28)
29
30agent = Agent(
31 model=OpenAIResponses(id="gpt-5.2"),
32 tools=[knowledge_tools],
33 markdown=True,
34)
35
36if __name__ == "__main__":
37 agent.print_response("How do I build multi-agent teams with Kern?", stream=True)

The toolkit comes with default instructions and few-shot examples to help the Agent use the tools effectively. Here is how you can configure them:

1from kern.tools.knowledge import KnowledgeTools
2
3knowledge_tools = KnowledgeTools(
4 knowledge=my_knowledge_base,
5 think=True, # Enable the think tool
6 search=True, # Enable the search tool
7 analyze=True, # Enable the analyze tool
8 add_instructions=True, # Add default instructions
9 add_few_shot=True, # Add few-shot examples
10 few_shot_examples=None, # Optional custom few-shot examples
11)