LangGraph Agentic RAG — Self-Correcting Retrieval System
Self-correcting RAG agent built as a LangGraph state machine (agent → retrieve → grade → rewrite/generate): the LLM decides whether retrieval is needed, a Pydantic structured-output judge gives a strict yes/no on chunk relevance, and the agent rewrites the query and retries when context is weak — replacing the brittle retrieve → stuff → generate pipeline. Hardened with a bounded rewrite budget and recursion limit to force a final answer instead of looping forever. Retrieval is exposed as a tool (WebBaseLoader → splitter → FAISS → ToolNode), with a provider-agnostic LLM/embeddings factory supporting fully-local, zero-key execution. Streamlit UI streams each node's trace live — tool-call decisions, retrieved chunks with sources, grader verdict, query rewrites, and final answer.