100+ AI Agents, Agent Skills and RAG Apps - Free and Open Source.
updated rag_reasoning_agent
ShubhamSaboo2db04989ad5c
diff --git a/rag_tutorials/agentic_rag_with_reasoning/README.md b/rag_tutorials/agentic_rag_with_reasoning/README.mdindex 65692979..7f661858 100644--- a/rag_tutorials/agentic_rag_with_reasoning/README.md+++ b/rag_tutorials/agentic_rag_with_reasoning/README.md@@ -1,5 +1,5 @@# π§ Agentic RAG with Reasoning-A sophisticated RAG system that demonstrates an AI agent's step-by-step reasoning process using Agno, Claude and Cohere. This implementation allows users to upload documents, add web sources, ask questions, and observe the agent's thought process in real-time.+A sophisticated RAG system that demonstrates an AI agent's step-by-step reasoning process using Agno, Claude and OpenAI. This implementation allows users to upload documents, add web sources, ask questions, and observe the agent's thought process in real-time.## Features@@ -17,15 +17,14 @@ A sophisticated RAG system that demonstrates an AI agent's step-by-step reasonin3. Advanced RAG Capabilities-- Hybrid search combining keyword and semantic matching-- Cohere reranking for improved relevance+- Vector search using OpenAI embeddings for semantic matching- Source attribution with citations## Agent Configuration- Claude 3.5 Sonnet for language processing-- Cohere embedding and reranking models+- OpenAI embedding model for vector search- ReasoningTools for step-by-step analysis- Customizable agent instructions@@ -39,9 +38,9 @@ You'll need the following API keys:- Navigate to API Keys section- Create a new API key-2. Cohere API Key+2. OpenAI API Key-- Sign up at dashboard.cohere.ai+- Sign up at platform.openai.com- Navigate to API Keys section- Generate a new API key@@ -50,7 +49,7 @@ You'll need the following API keys:1. **Clone the Repository**:```bashgit clone https://github.com/Shubhamsaboo/awesome-llm-apps.git- cd rag_tutorials/agentic_rag+ cd rag_tutorials/agentic_rag_with_reasoning```2. **Install the dependencies**:@@ -66,7 +65,7 @@ You'll need the following API keys:4. **Configure API Keys:**- Enter your Anthropic API key in the first field-- Enter your Cohere API key in the second field+- Enter your OpenAI API key in the second field- Both keys are required for the app to function@@ -83,17 +82,17 @@ The application uses a sophisticated RAG pipeline:### Knowledge Base Setup- Documents are loaded from URLs using WebBaseLoader-- Text is chunked and embedded using Cohere's embedding model+- Text is chunked and embedded using OpenAI's embedding model- Vectors are stored in LanceDB for efficient retrieval-- Hybrid search enables both keyword and semantic matching+- Vector search enables semantic matching for relevant information### Agent Processing- User queries trigger the agent's reasoning process- ReasoningTools help the agent think step-by-step- The agent searches the knowledge base for relevant information-- Claude 3.5 Sonnet generates comprehensive answers with citations+- Claude 4 Sonnet generates comprehensive answers with citations### UI Flow- Enter API keys β Add knowledge sources β Ask questions- Reasoning process and answer generation displayed side-by-side-- Sources cited for transparency and verification+- Sources cited for transparency and verification\ No newline at end of filediff --git a/rag_tutorials/agentic_rag_with_reasoning/rag_reasoning_agent.py b/rag_tutorials/agentic_rag_with_reasoning/rag_reasoning_agent.pyindex 6940344b..362e64df 100644--- a/rag_tutorials/agentic_rag_with_reasoning/rag_reasoning_agent.py+++ b/rag_tutorials/agentic_rag_with_reasoning/rag_reasoning_agent.py@@ -1,21 +1,25 @@import streamlit as stfrom agno.agent import Agent, RunEvent-from agno.embedder.cohere import CohereEmbedder+from agno.embedder.openai import OpenAIEmbedderfrom agno.knowledge.url import UrlKnowledgefrom agno.models.anthropic import Claude-from agno.reranker.cohere import CohereRerankerfrom agno.tools.reasoning import ReasoningToolsfrom agno.vectordb.lancedb import LanceDb, SearchType+from dotenv import load_dotenv+import os++# Load environment variables+load_dotenv()# Page configurationst.set_page_config(page_title="Agentic RAG with Reasoning",- page_icon="π§ ",+ page_icon="π§",layout="wide")# Main title and description-st.title("π§ Agentic RAG with Reasoning")+st.title("π§ Agentic RAG with Reasoning")st.markdown("""This app demonstrates an AI agent that:1. **Retrieves** relevant information from knowledge sources@@ -32,17 +36,19 @@ with col1:anthropic_key = st.text_input("Anthropic API Key",type="password",+ value=os.getenv("ANTHROPIC_API_KEY", ""),help="Get your key from https://console.anthropic.com/")with col2:- cohere_key = st.text_input(- "Cohere API Key",+ openai_key = st.text_input(+ "OpenAI API Key",type="password",- help="Get your key from https://dashboard.cohere.ai/"+ value=os.getenv("OPENAI_API_KEY", ""),+ help="Get your key from https://platform.openai.com/")-# Check if both API keys are provided-if anthropic_key and cohere_key:+# Check if API keys are provided+if anthropic_key and openai_key:# Initialize knowledge base (cached to avoid reloading)@st.cache_resource(show_spinner="π Loading knowledge base...")@@ -53,18 +59,13 @@ if anthropic_key and cohere_key:vector_db=LanceDb(uri="tmp/lancedb",table_name="agno_docs",- search_type=SearchType.hybrid, # Uses both keyword and semantic search- embedder=CohereEmbedder(- id="embed-v4.0",- api_key=cohere_key- ),- reranker=CohereReranker(- model="rerank-v3.5",- api_key=cohere_key+ search_type=SearchType.vector, # Use vector search+ embedder=OpenAIEmbedder(+ api_key=openai_key),),)- kb.load(recreate=False) # Load documents into vector DB+ kb.load(recreate=True) # Load documents into vector DBreturn kb# Initialize agent (cached to avoid reloading)@@ -202,8 +203,8 @@ else:1. **Anthropic API Key** - For Claude AI model- Sign up at [console.anthropic.com](https://console.anthropic.com/)- 2. **Cohere API Key** - For embeddings and reranking- - Sign up at [dashboard.cohere.ai](https://dashboard.cohere.ai/)+ 2. **OpenAI API Key** - For embeddings+ - Sign up at [platform.openai.com](https://platform.openai.com/)Once you have both keys, enter them above to start!""")@@ -215,16 +216,14 @@ with st.expander("π How This Works"):**This app uses the Agno framework to create an intelligent Q&A system:**1. **Knowledge Loading**: URLs are processed and stored in a vector database (LanceDB)- 2. **Hybrid Search**: Combines keyword and semantic search to find relevant information+ 2. **Vector Search**: Uses OpenAI's embeddings for semantic search to find relevant information3. **Reasoning Tools**: The agent uses special tools to think through problems step-by-step4. **Claude AI**: Anthropic's Claude model processes the information and generates answers- 5. **Reranking**: Cohere's reranker ensures the most relevant information is used**Key Components:**- `UrlKnowledge`: Manages document loading from URLs- `LanceDb`: Vector database for efficient similarity search- - `CohereEmbedder`: Converts text to embeddings for semantic search- - `CohereReranker`: Improves search result relevance+ - `OpenAIEmbedder`: Converts text to embeddings using OpenAI's embedding model- `ReasoningTools`: Enables step-by-step reasoning- `Agent`: Orchestrates everything to answer questions""")\ No newline at end of file