Overview
KnowledgeBase can be used as a tool, allowing the agent to actively search and retrieve information from your knowledge base during task execution. When added as a tool, the agent gains access to a search method that it can call to query the knowledge base.
Key Benefits
- Active Retrieval: Agent decides when and how to search the knowledge base
- Dynamic Queries: Agent can formulate multiple queries based on context
- Tool Integration: Works seamlessly with other tools in the agent’s toolkit
- Automatic Setup: KnowledgeBase is automatically set up when first used
Basic Usage
Add KnowledgeBase to the tools parameter of a Task or Agent:
How It Works
- Tool Registration: When you add KnowledgeBase to
tools, the agent automatically registers the search method as an available tool
- Automatic Setup: The KnowledgeBase is automatically set up.
- Agent Control: The agent decides when to call the search tool and what queries to make
- Results Integration: Search results are returned to the agent, which uses them to answer your questions
Tool vs Context
Using as Tool (this feature):
- Agent actively searches when needed
- Agent can make multiple queries
- Agent controls the search strategy
- Best for: Complex tasks requiring multiple searches
Using as Context (traditional RAG):
- Knowledge base is queried once before task execution
- Results are added to the context automatically
- Simpler, but less flexible
- Best for: Simple Q&A tasks
Multiple Knowledge Bases
You can add multiple KnowledgeBase instances as tools. When using multiple knowledge bases, provide unique name and description attributes so the agent can distinguish between them:
When you register multiple KnowledgeBase instances as tools, each one gets a unique tool name based on its name attribute:
KnowledgeBase name | Registered Tool Name |
|---|
"technical_docs" | search_technical_docs |
"user_guides" | search_user_guides |
| (no name provided) | search_{auto_generated_id} (e.g., search_7c6432f612bb422a) |
This allows the agent to call the appropriate knowledge base search tool:
- Call
search_technical_docs(query="API rate limits") to search the technical documentation
- Call
search_user_guides(query="usage limits") to search the user guides
If you don’t provide unique name attributes, tool names may collide and only one knowledge base will be accessible.
Cleanup
Always close the KnowledgeBase when done to free resources: