Skip to content

Repository files navigation

Multi-Agent LangGraph System

A sophisticated multi-agent system designed to answer questions by leveraging internal knowledge bases, external search, and document summarization - all orchestrated through a modern web interface.

πŸš€ Features

  • πŸ€– Specialized Agents: Dedicated agents for knowledge retrieval and summarization, each optimized for their specific tasks
  • 🎯 Intelligent Routing: A central router analyzes incoming queries and directs them to the most suitable agent or processing path
  • πŸ“š Knowledge-First Approach: Prioritizes searching internal document base before resorting to external searches, providing properly sourced responses
  • πŸ” External Search Integration: Seamlessly transitions to web search when internal knowledge is insufficient, with proper citation of sources
  • πŸ“ Efficient Summarization: Processes and condenses large documents using a map-reduce approach with LLM-powered chunking
  • 🌐 Advanced Orchestration: Utilizes LangGraph for robust, graph-based agent coordination and conversation flow control
  • 🧠 Contextual Conversations: Maintains conversation history and context, with automatic summarization for longer interactions
  • πŸ’» Modern Web Interface: Clean, responsive UI with gradient design for interacting with the multi-agent system

πŸ“‹ Requirements

  • Python >= 3.11
  • OpenAI API Key (Required)
  • Tavily API Key (Required)
  • LangSmith API Key (Optional - for tracing/debugging)

πŸ› οΈ Installation

  1. Clone the repository:
git clone https://github.com/DevXSoni021/Multi_agent_langGraph_System.git
cd Multi_agent_langGraph_System
  1. Install dependencies using uv (recommended):
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate
uv pip install -e .
uv pip install "langgraph-cli[inmem]"
  1. Set up environment variables:
# Create .env file in src/backend/
cp src/backend/.env.example src/backend/.env
# Edit .env with your API keys
  1. Run the application:
langgraph dev --no-browser

The application will be available at http://127.0.0.1:2024

πŸ“ Configuration

Create a .env file in src/backend/ with:

OPENAI_API_KEY=your_openai_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here
LANGCHAIN_API_KEY=your_langchain_api_key_here  # Optional

Note: LangSmith API key is OPTIONAL. The system works perfectly without it. LangSmith is only needed for tracing, debugging, and monitoring. See LANGSMITH_INFO.md for details.

πŸ“ Project Structure

multi_agent_system/
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ backend/                    # Backend server and agent logic
β”‚   β”‚   β”œβ”€β”€ agents/                 # Agent implementations
β”‚   β”‚   β”‚   β”œβ”€β”€ knowledge/          # Knowledge retrieval agent
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ graph.py        # Knowledge agent workflow graph
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ prompts.py      # LLM prompts for knowledge agent
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ schemas.py      # State schemas for knowledge agent
β”‚   β”‚   β”‚   β”‚   └── tools.py        # RAG and Tavily search tools
β”‚   β”‚   β”‚   β”œβ”€β”€ orchestrator/       # Central router logic
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ graph.py        # Main orchestrator graph
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ prompts.py      # Router and answer prompts
β”‚   β”‚   β”‚   β”‚   └── schemas.py      # Agent state schemas
β”‚   β”‚   β”‚   └── summarizer/         # Document summarization agent
β”‚   β”‚   β”‚       β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚       β”œβ”€β”€ graph.py         # Summarizer workflow graph
β”‚   β”‚   β”‚       β”œβ”€β”€ prompts.py      # Summarization prompts
β”‚   β”‚   β”‚       β”œβ”€β”€ schemas.py      # Summarizer state schemas
β”‚   β”‚   β”‚       └── tools.py        # Document chunking tools
β”‚   β”‚   β”œβ”€β”€ utils/                  # Shared utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ document_ingestion.py  # Document upload and ingestion
β”‚   β”‚   β”‚   β”œβ”€β”€ file_utils.py          # File processing utilities
β”‚   β”‚   β”‚   └── message_utils.py      # Message formatting utilities
β”‚   β”‚   β”œβ”€β”€ app.py                  # FastAPI application
β”‚   β”‚   β”œβ”€β”€ config.py                # Configuration management
β”‚   β”‚   β”œβ”€β”€ routes.py                # API endpoints
β”‚   β”‚   β”œβ”€β”€ schemas.py               # Pydantic models for API
β”‚   β”‚   β”œβ”€β”€ exceptions.py            # Custom exception classes
β”‚   β”‚   └── .env.example             # Environment variables template
β”‚   β”‚
β”‚   └── static/                      # Frontend assets
β”‚       β”œβ”€β”€ index.html              # Main HTML interface
β”‚       β”œβ”€β”€ js/
β”‚       β”‚   β”œβ”€β”€ config/
β”‚       β”‚   β”‚   └── config.js        # API configuration
β”‚       β”‚   └── script.js           # Frontend JavaScript logic
β”‚       └── styles/
β”‚           └── main.css             # CSS styling
β”‚
β”œβ”€β”€ screenshots/                     # Application screenshots
β”‚   β”œβ”€β”€ 1-welcome-screen.png
β”‚   β”œβ”€β”€ 2-chat-interface-empty.png
β”‚   β”œβ”€β”€ 3-chat-with-conversation.png
β”‚   β”œβ”€β”€ 4-sidebar-with-conversations.png
β”‚   β”œβ”€β”€ 5-empty-new-chat.png
β”‚   └── 6-knowledge-base-section.png
β”‚
β”œβ”€β”€ examples/                        # Example use cases
β”‚   └── use_cases.md
β”‚
β”œβ”€β”€ data/                            # Data storage (created at runtime)
β”‚   └── chroma_db/                  # Vector database storage
β”‚
β”œβ”€β”€ .github/                         # GitHub configuration
β”‚   └── workflows/                   # GitHub Actions workflows
β”‚
β”œβ”€β”€ API_KEY_FIX.md                   # API key troubleshooting guide
β”œβ”€β”€ LANGSMITH_INFO.md                # LangSmith integration info
β”œβ”€β”€ REQUIRED_KEYS_SUMMARY.md        # Quick API keys reference
β”œβ”€β”€ SETUP_REQUIREMENTS.md            # Detailed setup guide
β”œβ”€β”€ README.md                        # This file
β”œβ”€β”€ LICENSE                          # MIT License
β”œβ”€β”€ langgraph.json                   # LangGraph configuration
β”œβ”€β”€ pyproject.toml                   # Python project configuration
β”œβ”€β”€ uv.lock                          # Dependency lock file
└── .gitignore                       # Git ignore rules

πŸ—οΈ System Architecture

High-Level Architecture

graph TB
    User[User] -->|HTTP Request| WebUI[Web Interface]
    WebUI -->|API Calls| FastAPI[FastAPI Server]
    FastAPI -->|Routes| Router[Orchestrator Router]
    
    Router -->|Route Decision| KnowledgeAgent[Knowledge Agent]
    Router -->|Route Decision| SummarizerAgent[Summarizer Agent]
    Router -->|Route Decision| QuickAnswer[Quick Answer]
    
    KnowledgeAgent -->|Search| VectorDB[(ChromaDB<br/>Vector Store)]
    KnowledgeAgent -->|Fallback| Tavily[Tavily<br/>Web Search]
    
    SummarizerAgent -->|Process| DocumentChunks[Document<br/>Chunking]
    DocumentChunks -->|Parallel| LLM[OpenAI LLM]
    LLM -->|Summarize| CombinedSummary[Combined<br/>Summary]
    
    KnowledgeAgent -->|Results| Router
    SummarizerAgent -->|Results| Router
    QuickAnswer -->|Response| Router
    
    Router -->|Final Answer| FastAPI
    FastAPI -->|Response| WebUI
    WebUI -->|Display| User
    
    style Router fill:#667eea,stroke:#764ba2,color:#fff
    style KnowledgeAgent fill:#4f46e5,stroke:#4338ca,color:#fff
    style SummarizerAgent fill:#4f46e5,stroke:#4338ca,color:#fff
    style VectorDB fill:#10b981,stroke:#059669,color:#fff
    style Tavily fill:#f59e0b,stroke:#d97706,color:#fff
Loading

Agent Workflow Diagram

graph LR
    Start([User Query]) --> Router{Orchestrator<br/>Router}
    
    Router -->|Document<br/>Summarization| Summarizer[Summarizer Agent]
    Router -->|Knowledge<br/>Query| Knowledge[Knowledge Agent]
    Router -->|Simple<br/>Question| Answer[Quick Answer]
    
    Knowledge --> RefineQuery[Refine Query]
    RefineQuery --> Retrieve[Retrieve from<br/>Vector DB]
    Retrieve --> CheckRelevant{Relevant?}
    CheckRelevant -->|Yes| PrepareOutput[Prepare Output]
    CheckRelevant -->|No| ExternalSearch[External<br/>Web Search]
    ExternalSearch --> PrepareOutput
    PrepareOutput --> Answer
    
    Summarizer --> ProcessDoc[Process Document]
    ProcessDoc --> ChunkDoc[Chunk Document]
    ChunkDoc -->|Parallel| SummarizeChunks[Summarize<br/>Chunks]
    SummarizeChunks --> Combine[Combine<br/>Summaries]
    Combine --> Answer
    
    Answer --> CheckHistory{Need<br/>Summarization?}
    CheckHistory -->|Yes| SummarizeConv[Summarize<br/>Conversation]
    CheckHistory -->|No| End([Response])
    SummarizeConv --> End
    
    style Router fill:#667eea,stroke:#764ba2,color:#fff
    style Knowledge fill:#4f46e5,stroke:#4338ca,color:#fff
    style Summarizer fill:#4f46e5,stroke:#4338ca,color:#fff
    style Answer fill:#10b981,stroke:#059669,color:#fff
Loading

Detailed Knowledge Agent Flow

graph TD
    Start([Query Input]) --> Refine[Refine Query<br/>with LLM]
    Refine --> Retrieve[Retrieve Documents<br/>from Vector DB]
    Retrieve --> Evaluate{Evaluate<br/>Relevance}
    
    Evaluate -->|Relevant| FormatInternal[Format Internal<br/>Documents]
    Evaluate -->|Not Relevant| SearchExternal[Search External<br/>Sources - Tavily]
    
    SearchExternal --> FormatExternal[Format External<br/>Results]
    FormatInternal --> Output[Prepare Knowledge<br/>Output]
    FormatExternal --> Output
    Output --> End([Return to<br/>Orchestrator])
    
    style Refine fill:#667eea,stroke:#764ba2,color:#fff
    style Retrieve fill:#4f46e5,stroke:#4338ca,color:#fff
    style Evaluate fill:#f59e0b,stroke:#d97706,color:#fff
    style SearchExternal fill:#ef4444,stroke:#dc2626,color:#fff
Loading

Summarizer Agent Flow

graph TD
    Start([Document Input]) --> Analyze[Analyze Document<br/>Structure]
    Analyze --> Chunk[Chunk Document<br/>Intelligently]
    Chunk --> Distribute[Distribute Chunks<br/>for Parallel Processing]
    
    Distribute -->|Chunk 1| Summarize1[Summarize Chunk 1]
    Distribute -->|Chunk 2| Summarize2[Summarize Chunk 2]
    Distribute -->|Chunk N| SummarizeN[Summarize Chunk N]
    
    Summarize1 --> Combine[Combine All<br/>Summaries]
    Summarize2 --> Combine
    SummarizeN --> Combine
    Combine --> End([Return Summary<br/>to Orchestrator])
    
    style Analyze fill:#667eea,stroke:#764ba2,color:#fff
    style Chunk fill:#4f46e5,stroke:#4338ca,color:#fff
    style Distribute fill:#f59e0b,stroke:#d97706,color:#fff
    style Combine fill:#10b981,stroke:#059669,color:#fff
Loading

πŸ”„ Request Flow

sequenceDiagram
    participant User
    participant WebUI
    participant FastAPI
    participant Router
    participant KnowledgeAgent
    participant VectorDB
    participant Tavily
    participant SummarizerAgent
    participant LLM

    User->>WebUI: Send Message
    WebUI->>FastAPI: POST /api/conversations/{thread_id}/send-message
    FastAPI->>Router: Route Query
    
    alt Knowledge Query
        Router->>KnowledgeAgent: Process Query
        KnowledgeAgent->>VectorDB: Search Internal Docs
        alt Documents Found & Relevant
            VectorDB-->>KnowledgeAgent: Return Documents
            KnowledgeAgent-->>Router: Formatted Results
        else Documents Not Relevant
            KnowledgeAgent->>Tavily: External Web Search
            Tavily-->>KnowledgeAgent: Search Results
            KnowledgeAgent-->>Router: Formatted Results
        end
    else Document Summarization
        Router->>SummarizerAgent: Process Document
        SummarizerAgent->>LLM: Analyze & Chunk
        LLM-->>SummarizerAgent: Chunk Recommendations
        SummarizerAgent->>LLM: Summarize Chunks (Parallel)
        LLM-->>SummarizerAgent: Chunk Summaries
        SummarizerAgent-->>Router: Combined Summary
    else Simple Question
        Router->>LLM: Direct Answer
        LLM-->>Router: Response
    end
    
    Router->>FastAPI: Final Answer
    FastAPI->>WebUI: Stream Response (SSE)
    WebUI->>User: Display Answer
Loading

πŸ“Έ Screenshots

1. Welcome Screen

Welcome Screen Modern welcome screen with gradient UI, feature highlights, and conversation history

2. Empty Chat Interface

Empty Chat Interface Clean new chat interface ready for conversation with helpful tips

3. Active Chat Conversation

Chat with Conversation AI assistant responding to user queries with detailed, well-formatted responses and source citations

4. Sidebar with Conversation History

Sidebar with Conversations Sidebar showing conversation history, knowledge base, and navigation options

5. New Empty Chat Session

New Chat Session Starting a fresh conversation session with empty chat interface

6. Knowledge Base Upload Section

Knowledge Base Section Document upload feature for adding .txt, .md, or .pdf files to the knowledge base

🧩 Key Components

1. Orchestrator (Router)

  • Location: src/backend/agents/orchestrator/graph.py
  • Purpose: Central decision-making node that routes queries to appropriate agents
  • Key Functions:
    • route_message(): Analyzes query and determines routing path
    • answer(): Generates final response using agent outputs
    • summarize_conversation(): Manages conversation history

2. Knowledge Agent

  • Location: src/backend/agents/knowledge/graph.py
  • Purpose: Retrieves information from internal knowledge base or external sources
  • Key Functions:
    • refine_query(): Optimizes query for better retrieval
    • direct_retrieval(): Searches vector database
    • check_internal_docs(): Evaluates document relevance
    • external_search_node(): Falls back to Tavily web search
    • prepare_output(): Formats results for orchestrator

3. Summarizer Agent

  • Location: src/backend/agents/summarizer/graph.py
  • Purpose: Processes and summarizes large documents
  • Key Functions:
    • analyze_document_structure(): Determines optimal chunking strategy
    • process_document_node(): Chunks document intelligently
    • summarize_chunk(): Summarizes individual chunks (parallel)
    • combine_summaries(): Combines all chunk summaries

4. Vector Database (ChromaDB)

  • Purpose: Stores and retrieves document embeddings
  • Location: data/chroma_db/ (created at runtime)
  • Integration: Used by Knowledge Agent for RAG (Retrieval Augmented Generation)

5. Web Interface

  • Frontend: src/static/
  • Features:
    • Real-time chat with SSE streaming
    • Document upload for knowledge base
    • Session management
    • Conversation history
    • Modern gradient UI design

πŸ”§ API Endpoints

Endpoint Method Description
/api/ GET API status check
/api/new-thread GET Create new conversation thread
/api/conversations-list GET Get all conversations
/api/conversations/{thread_id} GET Get specific conversation
/api/conversations/{thread_id}/send-message POST Send message to thread
/api/conversations/{thread_id}/stream-message GET Stream response (SSE)
/api/conversations/{thread_id} DELETE Delete specific thread
/api/conversations DELETE Delete all threads
/api/upload-document/ POST Upload document to knowledge base

πŸ“– Documentation

🎯 Use Cases

  1. Question Answering: Ask questions and get answers from your knowledge base or web search
  2. Document Summarization: Upload large documents and get concise summaries
  3. Research Assistant: Combine internal knowledge with external web search
  4. Knowledge Base Management: Build and maintain a searchable document repository

πŸ› οΈ Technology Stack

  • Backend: FastAPI, Python 3.11+
  • AI Framework: LangGraph, LangChain
  • LLM: OpenAI GPT-4o
  • Embeddings: OpenAI text-embedding-3-small
  • Vector DB: ChromaDB
  • Web Search: Tavily API
  • Frontend: Vanilla JavaScript, HTML5, CSS3
  • Package Management: uv

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘€ Author

DevXSoni021

πŸ™ Acknowledgments

Built with:

πŸ”— Repository

GitHub: https://github.com/DevXSoni021/Multi_agent_langGraph_System


⭐ If you find this project useful, please consider giving it a star!

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages