from agno.agent import Agent
from agno.embedder.openai import OpenAIEmbedder
from agno.knowledge.url import UrlKnowledge
from agno.models.openai import OpenAIChat
from agno.tools.knowledge import KnowledgeTools
from agno.vectordb.lancedb import LanceDb, SearchType
# Create a knowledge base containing information from a URL
agno_docs = UrlKnowledge(
urls=["https://docs.agno.com/llms-full.txt"],
# 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"),
),
)
knowledge_tools = KnowledgeTools(
knowledge=agno_docs,
think=True,
search=True,
analyze=True,
add_few_shot=True,
)
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
tools=[knowledge_tools],
show_tool_calls=True,
markdown=True,
)
if __name__ == "__main__":
# Load the knowledge base, comment after first run
agno_docs.load(recreate=True)
agent.print_response("How do I build multi-agent teams with Agno?", stream=True)
Create a virtual environment
Terminal
and create a python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Set your API key
export OPENAI_API_KEY=xxx
Install libraries
pip install -U openai lancedb tantivy sqlalchemy agno
Run Example
python cookbook/reasoning/tools/knowledge_tools.py