Code
cookbook/reasoning/tools/knowledge_tools.py
Copy
Ask AI
from agno.agent import Agent
from agno.knowledge.embedder.openai import OpenAIEmbedder
from agno.knowledge.knowledge import Knowledge
from agno.models.openai import OpenAIChat
from agno.tools.knowledge import KnowledgeTools
from agno.vectordb.lancedb import LanceDb, SearchType
# Create a knowledge containing information from a URL
agno_docs = Knowledge(
# Use LanceDB as the vector database and store embeddings in the `agno_docs` table
vector_db=LanceDb(
uri="tmp/lancedb",
table_name="agno_docs",
search_type=SearchType.hybrid,
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
),
)
# Add content to the knowledge
agno_docs.add_content(url="https://docs.agno.com/llms-full.txt")
knowledge_tools = KnowledgeTools(
knowledge=agno_docs,
think=True,
search=True,
analyze=True,
add_few_shot=True,
)
agent = Agent(
model=OpenAIChat(id="gpt-5-mini"),
tools=[knowledge_tools],
markdown=True,
)
if __name__ == "__main__":
agent.print_response(
"How do I build a team of agents in agno?",
markdown=True,
stream=True,
stream_tools=True,
)
Usage
1
Create a virtual environment
Open the
Terminal
and create a python virtual environment.Copy
Ask AI
python3 -m venv .venv
source .venv/bin/activate
2
Set your API key
Copy
Ask AI
export OPENAI_API_KEY=xxx
3
Install libraries
Copy
Ask AI
pip install -U openai lancedb agno
4
Run Example
Copy
Ask AI
python cookbook/reasoning/tools/knowledge_tools.py