# botextractai/ai-langgraph-multi-agent architecture

> Architecture diagram of the GitHub repository botextractai/ai-langgraph-multi-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/botextractai/ai-langgraph-multi-agent
- Repository: https://github.com/botextractai/ai-langgraph-multi-agent

## Overview

Based on our examination of the project’s file tree and the README, this project is a multi-agent system built using LangGraph on top of LangChain. Its purpose is to generate a report on EU inflation figures by orchestrating five specialized AI agents (“plan”, “research_plan”, “generate”, “reflect”, and “research_critique”) in a stateful, iterative workflow that leverages external services (OpenAI and Tavily APIs).

##### Main Components
- Core Engine (main.py):
- Acts as the entry point for the workflow.
- Sets configurations such as max_revisions and reads API keys from environment variables/.env or inline.
- The Multi-Agent Graph Layer (LangGraph):
- This library organizes and orchestrates the individual agent flows and state transitions.
- AI Agents:
- “plan” agent: Defines the task and instructions.
- “research_plan” agent: Generates search queries (up to 3) via Tavily for gathering information.
- “generate” agent: Creates the initial draft report and potentially revised versions after feedback loops.
- “reflect” agent: Provides suggestions for improvements.
- “research_critique” agent: Generates additional search queries for further improvement.
- External Dependencies:
- OpenAI API: Powers the ChatGPT 4 model used by the agents.
- Tavily API: Provides actual search results for report research.
- Supporting Components:
- requirements.txt: Lists all required Python packages.
- GitHub workflows and configuration: Suggest the project follows continuous integration practices.

##### Relationships and Interactions
- The workflow starts with the “plan” agent, which sets up the task.
- Data flows to “research_plan”, which uses Tavily to generate queries.
- The “generate” agent creates the initial report draft.
- The report is then passed to the “reflect” agent for improvement suggestions.
- The “research_critique” agent contributes by generating additional queries.
- The “generate” agent may then be re-invoked to improve the report in a revision loop, controlled by a max_revisions limit.

##### Architectural Patterns and Principles
- Modularity: Each agent is designed for a specific task, following the Single Responsibility Principle.
- Statefulness: The orchestration of agents through LangGraph allows controlled, iterative refinements.
- Loose Coupling: The agents are independently developed and interact through well-defined APIs and data-passing layers.
- External Integration: The system integrates with external services (OpenAI and Tavily) and manages credentials via environment variables or configuration files.

##### Specific Elements
- Clear labels for each major component (e.g., Core Engine, LangGraph, Agents, External Services).
- Start: “plan” agent → “research_plan” agent (depicting query generation) → “generate” agent (creating draft).
- Revision Loop: “generate” agent → “reflect” agent → “research_critique” agent → back into “generate” for improved output.
- Infrastructure for external interaction:
- That OpenAI and Tavily are integrated via API calls and mention how keys are provided.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Main Components
    CoreEngine["Core Engine (main.py)"]:::module
    LangGraph["LangGraph Orchestration"]:::module

    %% AI Agents Subgraph
    subgraph "AI Agents"
        Plan("Plan Agent"):::agent
        ResearchPlan("Research Plan Agent"):::agent
        Generate("Generate Agent"):::agent
        Reflect("Reflect Agent"):::agent
        ResearchCritique("Research Critique Agent"):::agent
    end

    %% External Services Subgraph
    subgraph "External Services"
        OpenAI(("OpenAI API")):::external
        Tavily(("Tavily API")):::external
    end

    %% Supporting Components
    Dependency["Dependency Management (requirements.txt)"]:::module
    CI["CI (GitHub Workflows)"]:::ci

    %% Workflow Relationships
    CoreEngine -->|"initialize"| LangGraph
    LangGraph -->|"start"| Plan
    Plan -->|"setTask"| ResearchPlan
    ResearchPlan -->|"generateQueries"| Generate
    Generate -->|"createDraft"| Reflect
    Reflect -->|"improveDraft"| ResearchCritique
    ResearchCritique -->|"if_revisions<max_revisions"| Generate

    %% External API interactions
    ResearchPlan -->|"callsTavily"| Tavily
    Generate -->|"callsOpenAI"| OpenAI
    Reflect -->|"callsOpenAI"| OpenAI
    ResearchCritique -->|"callsOpenAI"| OpenAI

    %% Supporting Components Relationships
    Dependency -.->|"loadsDependencies"| CoreEngine
    CI -.->|"CI/CD_Config"| CoreEngine

    %% Click Events
    click CoreEngine "https://github.com/botextractai/ai-langgraph-multi-agent/blob/main/main.py"
    click Dependency "https://github.com/botextractai/ai-langgraph-multi-agent/blob/main/requirements.txt"
    click CI "https://github.com/botextractai/ai-langgraph-multi-agent/tree/main/.github/workflows"

    %% Styles
    classDef module fill:#f6e58d,stroke:#b71540,stroke-width:2px;
    classDef agent fill:#7ed6df,stroke:#130f40,stroke-width:2px;
    classDef external fill:#ff6b6b,stroke:#6a89cc,stroke-width:2px;
    classDef ci fill:#badc58,stroke:#130f40,stroke-width:2px;
```
