“Build a full-stack AI agent with LangGraph, Groq LLaMA 3, Pinecone, and Tavily Search API. Features dynamic routing between PDF-grounded RAG and real-time web search with a FastAPI and Streamlit archi”
Static RAG pipelines struggle when user queries require information beyond the ingested documents, such as current events or real-time web verification. Pure web-search agents, on the other hand, lack grounding in proprietary internal documents.
This project implements a hybrid AI agent using LangGraph, FastAPI, and Streamlit that dynamically orchestrates document retrieval and live web search based on user intent and contextual relevance.
The core of the system is a stateful decision graph that manages multi-step execution paths:
┌──────────────────┐
│ User Query │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ Router Decision │
└────────┬─────────┘
│
┌────────────────┴────────────────┐
▼ ▼
[Local Knowledge Path] [Live Web Search Path]
│ │
(Pinecone Vector DB) (Tavily Search API)
│ │
└────────────────┬────────────────┘
│
▼
┌──────────────────────────┐
│ Context Synthesis & Gen │
│ (Groq / LLaMA 3) │
└────────────┬─────────────┘
│
▼
[Final Answer]
Stateful Routing: LangGraph evaluates the incoming prompt and determines whether the answer resides in the local vector store or requires external web search.
Document Retrieval (RAG): For internal knowledge queries, the system searches indexed embeddings in Pinecone generated by lightweight HuggingFace MiniLM models.
Live Web Search: When real-time data is needed, or if the user explicitly enables web search, the agent routes execution to the Tavily Search API.
Fast Inference Synthesis: Retrieved chunks or web results are compiled into an augmented prompt and passed to Groq (LLaMA 3) for fast, grounded answer generation.
Component | Technology | Primary Responsibility |
Agent Orchestration | LangGraph & LangChain | Graph state management, tool execution, and conditional routing |
Backend API | FastAPI | Asynchronous REST endpoints, schema validation, and pipeline control |
LLM Inference Engine | Groq (LLaMA 3) | Sub-second generative reasoning and synthesis |
Vector Database | Pinecone | Semantic indexing and similarity retrieval for PDF documents |
Embeddings | Sentence Transformers (MiniLM) | Local dense vector generation for PDF text chunks |
Web Search Tool | Tavily Search API | Real-time web retrieval optimized for LLM consumption |
Frontend UI | Streamlit | Traceable chat interface with toggle controls for search mode |
Conditional Routing: By shifting from rigid linear chains to cyclic graphs with LangGraph, the agent can inspect context, evaluate retrieval quality, and fall back to web search when document context is insufficient.
Traceable Decision Making: Exposing agent state transitions through FastAPI and Streamlit gives users full visibility into whether the model answered from internal PDFs or live web results.
Ask questions, discuss architecture, and share insights with other developers.
Sign in to join the discussion and share your thoughts with other developers.
Sign In to Comment