Skip to content

Shreyas8905/S2TD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

S2TD: An Adaptive, Self-Correcting RAG Agent

Python LangGraph Groq RAG

📖 Objective

S2TD is a "System 2" thinking agent designed to solve the common pitfalls of standard RAG (Retrieval-Augmented Generation) systems: Hallucination and Irrelevance.

Unlike a standard chatbot that blindly answers from retrieved documents, S2TD employs an "Agentic Workflow" that mimics a human research team:

  1. Evaluates Data: It grades retrieved documents for relevance.
  2. Self-Corrects: If data is poor, it automatically rewrites the query and searches the web.
  3. Ensemble Thinking: It uses a "Council of LLMs" (Creative, Critic, Summarizer) to generate diverse perspectives in parallel.
  4. Synthesis: A "Chairman" LLM merges these perspectives into a single, hallucination-free answer. Inspiration from Sir Andrej Karpathy from his recent work llm-council.

🏗️ Architecture

The system is built using LangGraph (State Machine), Groq (High-speed Llama 3 inference), and ChromaDB (Vector Storage).

Architecture Diagram


📂 Project Structure

The project follows a modular, production-grade directory structure:

S2TD_project/
├── .env                 # API Keys (Groq, Tavily, etc.)
├── requirements.txt     # Python dependencies
├── main.py              # Application Entry Point
└── S2TD/               # Core Application Logic
    ├── __init__.py
    ├── config.py        # Central configuration (LLMs, Tools)
    ├── state.py         # Graph State definition (TypedDict)
    ├── chains.py        # Prompt Engineering & LLM Chains
    ├── nodes.py         # Executable Graph Nodes (Functions)
    ├── graph.py         # Graph Wiring & Orchestration
    └── utils.py         # Database Indexing Script

⚡ Setup & Installation

1. Prerequisites

2. Clone & Environment

git clone [https://github.com/Shreyas8905/S2TD.git](https://github.com/Shreyas8905/S2TD.git)
cd S2TD
python -m venv venv

Activate the Virtual Environment:

  • Windows: venv\Scripts\activate
  • Mac/Linux: source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Configuration (.env)

Create a .env file in the root directory and add your keys:

GROQ_API_KEY=gsk_...
TAVILY_API_KEY=tvly-...
# Optional: For tracing
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=lsv2-...

🚀 How to Run

Initialize the Knowledge Base

Before running the agent, you need to "teach" it by creating the vector database. The system checks for this automatically, but you can force a rebuild:

python -m S2TD.utils

This downloads the embedding model (HuggingFace) and indexes the sample URL defined in utils.py.

Run the Agent

python main.py

Enter your query when prompted. Watch the console logs to see the "thought process" of the agent.


Author

Shreyas Kulkarni

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages