This repository implements a robust, stateful multi-agent architecture designed for autonomous web research. Orchestrated by LangGraph, the system utilizes Groq's ultra-fast openai/gpt-oss-120b model for inference and Tavily for optimized web data extraction.
Unlike standard RAG pipelines, this system is agentic: it understands context, validates its own findings, and self-corrects if the retrieved data is insufficient.
- Contextual Awareness: Maintains full conversation history to support multi-turn queries (e.g., asking "What is the stock price?" immediately after discussing a specific company).
- Self-Correction Loop: A dedicated Validator Agent reviews research findings and triggers retries (up to 3 attempts) if the data quality is low.
- Intelligent Routing: A Clarity Agent acts as a gatekeeper, distinguishing between clear requests and those needing user clarification.
- Real-Time Synthesis: Fetches live web data (news, financial metrics) and synthesizes it into professional, cited responses.
The workflow is modeled as a directed graph where four specialized agents collaborate to fulfill user requests.
- Clarity Agent (The Gatekeeper): Analyzes conversation history to validate user intent. If the request is vague, it interrupts the flow to ask for clarification; if clear, it routes to the Researcher.
- Research Agent (The Hunter): Generates targeted queries based on intent and invokes the Tavily API to fetch real-time results.
- Validator Agent (The Critic): Reviews the Researcher's output. If findings are insufficient, it sends the task back for a retry; otherwise, it approves the data.
- Synthesis Agent (The Writer): Transforms validated findings into a coherent, professional answer.
graph TD
%% Nodes
START((Start))
Clarity_Agent[Clarity Agent]
Research_Agent[Research Agent]
Validator_Agent[Validator Agent]
Synthesis_Agent[Synthesis Agent]
END_NODE((End))
%% Edge Connections
START --> Clarity_Agent
Clarity_Agent -->|"Needs Clarification"| END_NODE
Clarity_Agent -->|"Clear Request"| Research_Agent
Research_Agent --> Validator_Agent
Validator_Agent -->|"Insufficient (Retry < 3)"| Research_Agent
Validator_Agent -->|"Sufficient"| Synthesis_Agent
Synthesis_Agent --> END_NODE
%% Styling
style START fill:#f9f,stroke:#333,stroke-width:2px
style END_NODE fill:#f9f,stroke:#333,stroke-width:2px
style Clarity_Agent fill:#e1f5fe,stroke:#01579b
style Research_Agent fill:#fff9c4,stroke:#fbc02d
style Validator_Agent fill:#ffebee,stroke:#b71c1c
style Synthesis_Agent fill:#e8f5e9,stroke:#2e7d32
The codebase is modularized for scalability and clarity:
main.py: The CLI entry point that manages the user input loop and persistent chat history.graph.py: Constructs theStateGraphand defines conditional edges (e.g.,route_clarity,route_validator).nodes.py: Contains the logic and context-aware prompts for the four agents usingChatGroq.state.py: Defines theAgentStatedictionary, tracking messages, findings, confidence scores, and attempt counts.config.py: Handles secure loading of API keys from local text files.
- Python 3.10+.
- Groq API Key: For LLM inference.
- Tavily API Key: For web search.
- Clone the repository and install dependencies (including
langgraph,langchain-groq,tavily-python). - Configure Credentials: Create two text files in the project root:
GroqKey.txt: Paste your Groq API Key here.TavilyKey.txt: Paste your Tavily API Key here.
Run the main application:
python main.py
Example Interaction:
User: "Tell me about Nvidia." System: [Clarity confirms intent -> Research fetches news -> Validator approves -> Synthesis generates report] User: "What is the stock price?" System: [Clarity uses history to identify "Nvidia" -> Research fetches live data -> Synthesis responds]