Skip to content

Latest commit

Β 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Autonomous Multi-Agent Research & Fact Verification System

Python FastAPI LangGraph React

An autonomous multi-agent AI system that decomposes research topics into atomic claims, retrieves live web evidence, verifies factual accuracy, detects source contradictions, and synthesizes structured research reports.


πŸ“Œ Project Overview

Verifying complex claims online means cross-checking multiple sources, spotting contradictions, and organizing findings β€” all manually. Single-prompt LLMs can't do this reliably without real-time web access and structured reasoning.

The Autonomous Multi-Agent Research & Fact Verification System fixes this with a 5-agent LangGraph pipeline backed by FastAPI, powered by live web search (Tavily), vector similarity search (FAISS + SentenceTransformers), and your choice of Gemini, OpenAI, or Claude.


✨ Features

  • Stateful Multi-Agent Orchestration β€” 5 specialized agents coordinated in a LangGraph DAG
  • Provider-Agnostic LLM Engine β€” Switch between Gemini, OpenAI, and Claude per request
  • Live Web Search & RAG β€” Real-time evidence retrieval via Tavily Search API
  • Local Vector Embeddings β€” sentence-transformers/all-MiniLM-L6-v2 (384-dim dense vectors)
  • Session-Isolated FAISS Vector DB β€” Fast in-memory semantic similarity search
  • Contradiction Detection β€” Flags numerical mismatches and reporting conflicts across sources
  • MongoDB Atlas Persistence β€” Async job tracking and historical analysis via Motor

πŸ› οΈ Tech Stack

Component Technology Purpose
Framework FastAPI >=0.110.0 Async REST API with OpenAPI docs
Language Python 3.10+ Backend runtime
Agent Orchestration LangGraph >=0.0.30 Stateful multi-agent DAG workflow
LLM Integrations LangChain (google-genai, openai, anthropic) Provider-agnostic LLM clients
Web Search Tavily Python SDK >=0.3.0 Live AI-powered web search
Vector DB FAISS CPU >=1.8.0 Similarity search vector index
Embeddings SentenceTransformers Local text vectorization
Database Motor >=3.3.2 / PyMongo Async MongoDB Atlas driver
Validation Pydantic v2 Request/response schema validation

πŸ“ System Architecture

+---------------------------------------------------------------+
|                     FASTAPI BACKEND                           |
|   CORS Middleware Β· Pydantic Validation Β· Exception Handlers  |
+---------------------------------------------------------------+
                              |
                              v
+---------------------------------------------------------------+
|                  LANGGRAPH STATEGRAPH WORKFLOW                |
|                                                               |
|   [START]                                                     |
|      |                                                        |
|      v                                                        |
|  1. Claim Extractor  ──>  2. Search Retriever                 |
|     (LLM Factory)            (Tavily + FAISS)                 |
|                                    |                          |
|                                    v                          |
|  4. Contradiction   <──  3. Fact Verifier                     |
|     Detector (LLM)          (LLM Cross-Check)                 |
|         |                                                     |
|         v                                                     |
|  5. Report Generator                                          |
|     (LLM Synthesis)                                           |
|      |                                                        |
|   [END]                                                       |
+---------------------------------------------------------------+
       |              |              |              |
       v              v              v              v
  LLM Factory    Tavily Search   FAISS + Embeddings   MongoDB Atlas
 (Gemini/OpenAI   (Live Search)   (Local RAG)         (Persistence)
  /Claude)

πŸ“ Project Structure

multi-agent-fact-verification/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py                         # FastAPI entrypoint, CORS, exception handlers
β”‚   β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”‚   β”œβ”€β”€ claim_extractor.py          # Agent 1: Atomic claim extraction
β”‚   β”‚   β”‚   β”œβ”€β”€ search_retriever.py         # Agent 2: Tavily search & FAISS indexing
β”‚   β”‚   β”‚   β”œβ”€β”€ fact_verifier.py            # Agent 3: LLM-based fact verification
β”‚   β”‚   β”‚   β”œβ”€β”€ contradiction_detector.py   # Agent 4: Cross-source contradiction detection
β”‚   β”‚   β”‚   └── report_generator.py         # Agent 5: Markdown report synthesis
β”‚   β”‚   β”œβ”€β”€ api/v1/
β”‚   β”‚   β”‚   β”œβ”€β”€ analyze.py                  # POST /api/v1/analyze endpoint
β”‚   β”‚   β”‚   β”œβ”€β”€ health.py                   # GET /api/v1/health endpoint
β”‚   β”‚   β”‚   └── router.py                   # API router aggregation
β”‚   β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”‚   β”œβ”€β”€ config.py                   # Pydantic BaseSettings & env config
β”‚   β”‚   β”‚   └── database.py                 # Async MongoDB connection manager
β”‚   β”‚   β”œβ”€β”€ graph/
β”‚   β”‚   β”‚   β”œβ”€β”€ builder.py                  # LangGraph StateGraph assembly
β”‚   β”‚   β”‚   └── state.py                    # AgentState TypedDict & domain models
β”‚   β”‚   β”œβ”€β”€ schemas/
β”‚   β”‚   β”‚   └── analyze.py                  # AnalyzeRequest & AnalyzeResponse schemas
β”‚   β”‚   └── services/
β”‚   β”‚       β”œβ”€β”€ llm_factory.py              # Dynamic LLM client factory
β”‚   β”‚       β”œβ”€β”€ tavily_service.py           # Tavily search wrapper
β”‚   β”‚       β”œβ”€β”€ embedding_service.py        # SentenceTransformers vector service
β”‚   β”‚       β”œβ”€β”€ faiss_service.py            # FAISS vector DB service
β”‚   β”‚       └── mongo_service.py            # MongoDB async persistence
β”‚   β”œβ”€β”€ .env.example
β”‚   └── requirements.txt
β”œβ”€β”€ frontend/                               # React + Vite dashboard (separate team)
β”œβ”€β”€ .gitignore
└── README.md

πŸš€ Getting Started

Prerequisites

  • Python 3.10, 3.11, or 3.12
  • API keys for Google Gemini (or OpenAI/Claude) and Tavily Search

Setup

# 1. Navigate to backend
cd backend

# 2. Create and activate virtual environment
python -m venv .venv

# Windows
.\.venv\Scripts\Activate.ps1
# macOS/Linux
source .venv/bin/activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. Configure environment
cp .env.example .env
# Edit .env with your API keys

Run

python -m uvicorn app.main:app --host 127.0.0.1 --port 8000 --reload
  • API Base URL: http://127.0.0.1:8000
  • Swagger Docs: http://127.0.0.1:8000/docs

πŸ”‘ Environment Variables

Variable Required Default Description
GOOGLE_API_KEY Yes* "" Google Gemini API key
OPENAI_API_KEY Optional "" OpenAI API key
ANTHROPIC_API_KEY Optional "" Anthropic Claude API key
TAVILY_API_KEY Yes "" Tavily Search API key
MONGODB_URI Yes "mongodb://localhost:27017" MongoDB connection URI
DEFAULT_LLM_PROVIDER No "gemini" Default provider (gemini, openai, claude)
GEMINI_MODEL_NAME No "gemini-3.1-flash-lite" Gemini model string
OPENAI_MODEL_NAME No "gpt-4o" OpenAI model string
CLAUDE_MODEL_NAME No "claude-3-5-sonnet-20241022" Claude model string
MONGODB_DB_NAME No "fact_verification_db" MongoDB database name

*Required only when using Gemini as the provider.


πŸ“‘ API Reference

POST /api/v1/analyze

Request

{
  "query": "Did renewable energy generate more than 30% of global electricity in 2024?",
  "model_provider": "gemini"
}
Parameter Type Required Description
query string Yes Research claim or question (5–1000 chars)
model_provider string No "gemini", "openai", or "claude"

Response (200 OK)

{
  "job_id": "job_d40409a473",
  "status": "completed",
  "query": "Did renewable energy generate more than 30% of global electricity in 2024?",
  "claims": [
    {
      "id": "claim_01",
      "text": "Renewable energy generated over 30% of global electricity in 2024.",
      "verdict": "SUPPORTED",
      "confidence": 0.95,
      "reasoning": "Ember Global Electricity Review 2025 confirms renewables reached 32% in 2024."
    }
  ],
  "sources": [
    {
      "id": "src_01",
      "url": "https://ember-climate.org/insights/research/global-electricity-review-2025/",
      "title": "Global Electricity Review 2025 | Ember",
      "snippet": "Clean electricity generated 40% of global power in 2024..."
    }
  ],
  "contradictions": [],
  "report_markdown": "# Fact Verification Report...",
  "errors": []
}

🧠 How the Pipeline Works

[START] β†’ Claim Extractor β†’ Search Retriever β†’ Fact Verifier β†’ Contradiction Detector β†’ Report Generator β†’ [END]
  1. Claim Extractor β€” Breaks the user query into atomic, testable claim statements
  2. Search Retriever β€” Queries Tavily for live web results, embeds snippets into a FAISS index
  3. Fact Verifier β€” Cross-checks each claim against retrieved evidence; assigns SUPPORTED, REFUTED, or INCONCLUSIVE with a confidence score
  4. Contradiction Detector β€” Identifies numerical mismatches and reporting conflicts across sources
  5. Report Generator β€” Synthesizes all findings into a structured Markdown research report

About

Autonomous Multi-Agent Research & Fact Verification System

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages