Skip to content

An autonomous, self-correcting research squad powered by LangGraph, Groq (gpt-oss-120b), and Tavily. These agents search, validate, and summarize the web so you don't have to.

Notifications You must be signed in to change notification settings

3ahmood/LangGraph-Autonomous-Research-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LangGraph Autonomous Research Agent

📖 Overview

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.

✨ Key Features

  • 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.

🏗️ System Architecture

The workflow is modeled as a directed graph where four specialized agents collaborate to fulfill user requests.

The Agent Squad

  1. 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.
  2. Research Agent (The Hunter): Generates targeted queries based on intent and invokes the Tavily API to fetch real-time results.
  3. 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.
  4. Synthesis Agent (The Writer): Transforms validated findings into a coherent, professional answer.

Workflow Diagram

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

Loading

📂 Project Structure

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 the StateGraph and defines conditional edges (e.g., route_clarity, route_validator).
  • nodes.py: Contains the logic and context-aware prompts for the four agents using ChatGroq.
  • state.py: Defines the AgentState dictionary, tracking messages, findings, confidence scores, and attempt counts.
  • config.py: Handles secure loading of API keys from local text files.

🚀 Getting Started

Prerequisites

  • Python 3.10+.
  • Groq API Key: For LLM inference.
  • Tavily API Key: For web search.

Installation

  1. Clone the repository and install dependencies (including langgraph, langchain-groq, tavily-python).
  2. 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.

Usage

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]

About

An autonomous, self-correcting research squad powered by LangGraph, Groq (gpt-oss-120b), and Tavily. These agents search, validate, and summarize the web so you don't have to.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages