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:
- Evaluates Data: It grades retrieved documents for relevance.
- Self-Corrects: If data is poor, it automatically rewrites the query and searches the web.
- Ensemble Thinking: It uses a "Council of LLMs" (Creative, Critic, Summarizer) to generate diverse perspectives in parallel.
- Synthesis: A "Chairman" LLM merges these perspectives into a single, hallucination-free answer. Inspiration from Sir Andrej Karpathy from his recent work llm-council.
The system is built using LangGraph (State Machine), Groq (High-speed Llama 3 inference), and ChromaDB (Vector Storage).
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
- Python 3.10 or higher.
- Groq API Key (Free at console.groq.com).
- Tavily API Key (Free at tavily.com).
git clone [https://github.com/Shreyas8905/S2TD.git](https://github.com/Shreyas8905/S2TD.git)
cd S2TD
python -m venv venvActivate the Virtual Environment:
- Windows:
venv\Scripts\activate - Mac/Linux:
source venv/bin/activate
pip install -r requirements.txtCreate 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-...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.utilsThis downloads the embedding model (HuggingFace) and indexes the sample URL defined in utils.py.
python main.pyEnter your query when prompted. Watch the console logs to see the "thought process" of the agent.
