This example demonstrates how to implement Agentic RAG with Reasoning Tools, combining knowledge base search with structured reasoning capabilities for more sophisticated responses.
"""This cookbook shows how to implement Agentic RAG with Reasoning.1. Run: `pip install agno anthropic cohere lancedb tantivy sqlalchemy` to install the dependencies2. Export your ANTHROPIC_API_KEY and CO_API_KEY3. Run: `python cookbook/agent_concepts/agentic_search/agentic_rag_with_reasoning.py` to run the agent"""import asynciofrom agno.agent import Agentfrom agno.knowledge.embedder.cohere import CohereEmbedderfrom agno.knowledge.knowledge import Knowledgefrom agno.knowledge.reranker import CohereRerankerfrom agno.models.anthropic import Claudefrom agno.tools.reasoning import ReasoningToolsfrom agno.vectordb.lancedb import LanceDb, SearchTypeknowledge = Knowledge( # Use LanceDB as the vector database, store embeddings in the `agno_docs` table vector_db=LanceDb( uri="tmp/lancedb", table_name="agno_docs", search_type=SearchType.hybrid, embedder=CohereEmbedder(id="embed-v4.0"), reranker=CohereReranker(model="rerank-v3.5"), ),)asyncio.run( knowledge.add_contents_async(urls=["https://docs.agno.com/introduction/agents.md"]))agent = Agent( model=Claude(id="claude-sonnet-4-20250514"), # Agentic RAG is enabled by default when `knowledge` is provided to the Agent. knowledge=knowledge, # search_knowledge=True gives the Agent the ability to search on demand # search_knowledge is True by default search_knowledge=True, tools=[ReasoningTools(add_instructions=True)], instructions=[ "Include sources in your response.", "Always search your knowledge before answering the question.", ], markdown=True,)if __name__ == "__main__": agent.print_response( "What are Agents?", stream=True, show_full_reasoning=True, stream_intermediate_steps=True, )