Skip to content

krishnakoushik225/langgraph-research-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ResearchFlow AI πŸ”

Self-Correcting Agentic Research Pipeline Β· LangGraph + FastAPI + Ollama

Python LangGraph FastAPI React Ollama Tavily License: MIT

ResearchFlow AI is a production-grade agentic research system that decomposes complex questions into sub-queries, retrieves and verifies web evidence, and synthesizes citation-grounded answers β€” with self-correcting retry logic when evidence quality is low.


🎬 Demo

ResearchFlow AI Demo

Ask any complex research question β€” ResearchFlow decomposes it, searches for evidence, verifies quality, and returns a cited answer with a full reasoning trace.


✨ What Makes This Different from a RAG Chatbot

Most LLM apps do: question β†’ retrieve β†’ answer

ResearchFlow does:

question β†’ decompose β†’ search β†’ verify confidence β†’
  if low: re-search with refined query (cyclic retry) β†’
answer with citations + reasoning trace

This is agentic reasoning β€” the system evaluates its own evidence quality and decides whether to retry before synthesizing. Single-prompt LLM systems hallucinate. ResearchFlow verifies.


πŸ—οΈ Architecture

graph TD
    A[User Query] --> B[Planner Node]
    B --> C[Decomposer Node]
    C --> D[Search Node - Tavily]
    D --> E[Verifier Node]
    E -->|confidence < threshold| D
    E -->|confidence β‰₯ threshold| F[Synthesizer Node]
    F --> G[Citation-Grounded Answer]
Loading

Node Responsibilities

Node Role
Planner Analyzes query intent, defines research strategy
Decomposer Breaks complex question into focused sub-queries
Search Retrieves web evidence via Tavily Search API
Verifier Scores evidence relevance and confidence (0–1)
Synthesizer Generates final answer with inline citations

The cyclic edge between Verifier and Search is the core innovation β€” if confidence falls below threshold, the system refines the query and searches again rather than hallucinating from weak evidence.


πŸ”¬ Example

Query: "How does LangGraph enable self-correcting AI agents?"

Pipeline trace:

[Planner]     β†’ Strategy: technical documentation + recent examples
[Decomposer]  β†’ Sub-queries: ["LangGraph cyclic workflow", 
                               "LangGraph conditional routing",
                               "LangGraph stateful agents retry"]
[Search]      β†’ Retrieved 9 sources via Tavily
[Verifier]    β†’ Confidence: 0.44 (below threshold) β†’ RETRY
[Search]      β†’ Refined query: "LangGraph self-correction checkpointing 2024"
[Verifier]    β†’ Confidence: 0.83 β†’ PASS
[Synthesizer] β†’ Answer with 5 inline citations

Sample output:

β€’ LangGraph enables self-correcting agents through cyclical workflows where
  an agent generates output, evaluates results, and loops back for revision.

β€’ It maintains shared state and checkpoints so intermediate results persist
  across iterations.

β€’ Conditional routing allows workflows to retry, revise, or terminate
  execution based on intermediate outcomes.

Limitation: LangGraph provides orchestration infrastructure, but evaluation
logic must still be implemented by the developer.

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • Ollama running locally with Llama 3.2: ollama pull llama3.2
  • Tavily API key (free tier at tavily.com)

Installation

git clone https://github.com/krishnakoushik225/langgraph-research-agent
cd langgraph-research-agent
python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt

Environment Setup

cp .env.example .env
# Add your keys:
# TAVILY_API_KEY=your_key_here
# LANGSMITH_API_KEY=your_key_here   (optional, for tracing)

Run

# Backend
uvicorn app.main:app --reload
# Runs at http://127.0.0.1:8000

# Frontend (separate terminal)
cd frontend && npm install && npm start
# Runs at http://localhost:3000

πŸ› οΈ Tech Stack

Layer Technology
Agent Orchestration LangGraph (cyclic state machine)
LLM Backend Ollama + Llama 3.2 (local, private)
Web Search Tavily Search API
API Backend FastAPI (async)
Frontend React + Axios
Observability LangSmith (optional tracing)

πŸ“ Project Structure

langgraph-research-agent/
β”œβ”€β”€ backend/
β”‚   └── app/
β”‚       β”œβ”€β”€ graph/
β”‚       β”‚   β”œβ”€β”€ planner.py        # Research strategy generation
β”‚       β”‚   β”œβ”€β”€ decomposer.py     # Sub-question generation
β”‚       β”‚   β”œβ”€β”€ search.py         # Tavily evidence retrieval
β”‚       β”‚   β”œβ”€β”€ verifier.py       # Confidence scoring + retry logic
β”‚       β”‚   └── synthesizer.py    # Citation-grounded answer generation
β”‚       β”œβ”€β”€ services/
β”‚       β”‚   └── ollama_client.py  # Local LLM client
β”‚       └── main.py               # FastAPI entrypoint
β”œβ”€β”€ frontend/
β”‚   └── src/
β”‚       β”œβ”€β”€ App.jsx
β”‚       └── App.css
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ researchflow-demo.png
β”‚   └── architecture.png
β”œβ”€β”€ .env.example
β”œβ”€β”€ requirements.txt
└── README.md

βš™οΈ Engineering Challenges Solved

Evidence Quality β€” Web search returns noisy results. The Verifier node assigns a confidence score and triggers re-search with refined queries when quality is low.

Hallucination Prevention β€” The Synthesizer is constrained to generate answers only from retrieved evidence, with every claim linked to a source.

Agent Coordination β€” LangGraph manages shared workflow state across all nodes, enabling conditional branching and retry without losing intermediate results.

Adaptive Research β€” If initial sub-questions yield weak evidence, the system reformulates them before attempting synthesis.


πŸ’‘ Why LangGraph?

LangGraph was chosen specifically because it supports cyclic graphs β€” standard LangChain chains are DAGs (directed acyclic graphs) and cannot model retry loops. LangGraph enables:

  • Stateful workflows β€” shared research state persists across all nodes
  • Conditional routing β€” retry, revise, or terminate based on verifier output
  • Modular reasoning nodes β€” each node has a single, testable responsibility
  • Checkpointing β€” intermediate results survive failures and restarts

πŸ”­ Roadmap

  • LangSmith full trace dashboard
  • Human-in-the-loop checkpoint before synthesis
  • Vector database retrieval (Pinecone) as additional search source
  • Streaming tokens to frontend in real-time
  • Multi-model support (GPT-4, Claude, Gemini)
  • Multi-agent collaboration mode

πŸ“„ License

MIT β€” free to use and build on.


Built by Krishna Koushik Unnam Β· AI Systems Developer

About

Self-correcting AI research agent built with LangGraph, Tavily Search, Ollama, FastAPI, and React. Decomposes complex questions, retrieves web evidence, verifies relevance, and generates citation-grounded answers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors