How hayatahmad05/agentic-chatbot works
Project Type and Purpose
• RAGChat is a backend-centric, retrieval-augmented chatbot service with an optional Gradio UI. It uses FastAPI to expose HTTP endpoints, orchestrates an “agent + tools” pattern to query documents and live web search, and powers responses via Google Gemini 2.0 Flash. Data persistence (memory + document store) is in MongoDB Atlas.
File Structure Analysis
• Top-level scripts
• main.py / run.bat – application entrypoint
• api.py – defines FastAPI routes (chat, upload, health check)
• Agent.py – orchestrates agent logic, dispatch to tools & LLM
• llm.py – wrapper around Google Gemini via LangChain & embeddings
• logging_config.py – Request-ID middleware and logging setup
• Tools folder
• BasicToolNode.py – generic LangGraph tool node base class
• RagTool.py – custom RAG search tool (vector + keyword retrieval)
• config files
• requirements.txt – dependency list
• .gitignore
README Insights
• Core components: FastAPI backend, Google Gemini LLM, MongoDB, LangGraph tools (rag_search + tavily_search), optional Gradio UI
• Architectural patterns: Agent‐oriented (agent + tools), hybrid RAG search (vector + keyword), middleware for logging/tracing
a. Main Components
1. Client Layer
– Gradio UI (optional) or any HTTP client
2. API Layer (FastAPI)
– Exposes /chat, /upload, /health endpoints
– Logging & Request ID middleware
3. Agent Core (Agent.py)
– Coordinates tool invocation and LLM calls
4. Tools Subsystem (Tools/)
– RAG Tool (RagTool.py) – builds queries using embeddings & MongoDB
– Tavily Search Tool – real-time internet lookup
5. LLM Layer (llm.py)
– Google Gemini via LangChain
– Embeddings generation (GoogleGenerativeAIEmbeddings)
6. Data Stores
– MongoDB Atlas
• Document collection (ingested docs + embeddings)
• Conversation history collection (memory recall)
7. External Services
– Tavily API for live search
b. Interactions & Data Flow
– Client → HTTP request → FastAPI
– FastAPI → (with Request ID) → Agent Core
– Agent Core → invokes Tools (RAGTool → MongoDB; Tavily → external API)
– Agent Core → llm.py → Google Gemini (context + tool results)
– llm response → Agent → FastAPI → Client
– Upload endpoint → splits & embeds docs → stores in MongoDB
c. Architectural Patterns
– Agent + Tools (pluggable tool nodes via LangGraph)
– Hybrid RAG (vector + keyword)
– Middleware for cross-cutting concerns (logging, tracing)
d. Key Technologies
– FastAPI (backend web framework)
– LangChain + LangGraph (LLM orchestration)
– GoogleGenerativeAIEmbeddings (vector store)
– MongoDB Atlas (NoSQL document store)
– Tavily (external search)
– Gradio (optional UI)