# bhushanmaheshwari/ai-langgraph architecture

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

- Interactive diagram: https://gitdiagram.com/bhushanmaheshwari/ai-langgraph
- Repository: https://github.com/bhushanmaheshwari/ai-langgraph

## Overview

##### Project type and purpose
- This is an open-source toolkit/monorepo for building and experimenting with various “agent” patterns (e.g., retrieval-augmented generation graphs, react-style agents, reflection/reflexion agents, human-in-the-loop memory).
- The README title “Understanding Agents” hints that the repo is a sandbox of different agent architectures and pipelines, each isolated in its own folder and PyPI-ready via pyproject.toml.

##### File structure
- Top-level modules:
- human-in-the-loop-memory – core async and sync memory helpers and orchestration
- rags – RAG-style graph pipeline: ingestion, nodes (retrieve, generate, grade, route), chain definitions, tests
- react-agent – React-style agent implementation (nodes.py, state.py, orchestration in main.py)
- reflection-agent – Single-chain reflection agent (chains.py, main.py)
- reflexion-agent – Enhanced reflection (“reflexion”) agent with tool execution, schemas, chains
- Each subproject has its own pyproject.toml, so they’re intended as standalone packages.
- Common patterns:
- main.py entrypoints
- graph/chain/node abstractions in rags
- schemas/tool_executor in reflexion-agent
- state management in react-agent

##### README for additional insights
- Minimal content, so rely on folder names, code files, and consistent naming conventions (“chains”, “nodes”, “main”).

a. Main Components
1. CLI/API Layer – `main.py` scripts in each module
2. Agent Orchestrator – selects which agent to invoke (could be a wrapper or separate process for each submodule)
3. Core Memory Service – `human-in-the-loop-memory/core` (stateful store, async API for human feedback)
4. RAG Engine – `rags/graph` (ingestion → retrieval → generation → grading → routing)
5. Agent Variants – react, reflection, reflexion (each with its own chain/node logic)
6. External Services – LLM APIs (OpenAI, etc.), Vector DBs (for retrieval), Web search APIs
7. Tools & Executors – `reflexion-agent/tool_executor.py`
b. Relationships & Data Flow
1. User request → CLI/API Layer
2. CLI calls the chosen Agent Orchestrator
3. If RAG: data ingestion → vector store → graph chains → LLM calls → grader nodes → result
4. If React: state machine cycles through nodes.py actions and LLM calls
5. If Reflection/Reflexion: prompt → chain of self-analysis steps → optionally tool executor → final answer
6. All agents log or persist conversation/memory to the Core Memory Service for human-in-the-loop feedback
7. External services are called from within node implementations (e.g., retrieval nodes, generation nodes)
c. Architectural Patterns & Principles
- Modular, package-per-agent pattern (micro-package style)
- Chain of Responsibility (rags graph)
- State machines (react-agent)
- Reflection loop pattern (reflection/reflexion agents)
- Separation of concerns: ingestion, retrieval, generation, grading, routing, memory
d. Key Technologies & Frameworks
- Python 3.x, AsyncIO (human-in-the-loop-memory)
- Vector DB clients (in ingestion/retrieve nodes)
- HTTP/REST or SDK calls to LLM providers
- Pydantic or similar for schemas (reflexion-agent/schemas.py)

##### Detailed but not over-complicated
- Of the five subprojects as a separate module block.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    User["User"]:::external

    %% CLI/API Layer
    subgraph "CLI/API Layer"
        direction TB
        RAGMain["RAG Agent CLI\n(rags/main.py)"]:::cli
        ReactMain["React Agent CLI\n(react-agent/main.py)"]:::cli
        ReflectionMain["Reflection Agent CLI\n(reflection-agent/main.py)"]:::cli
        ReflexionMain["Reflexion Agent CLI\n(reflexion-agent/main.py)"]:::cli
    end

    User --> RAGMain
    User --> ReactMain
    User --> ReflectionMain
    User --> ReflexionMain

    %% RAG Agent
    subgraph "RAG Graph Engine" 
        direction TB
        RAGEngine["RAG Engine\n(rags/graph)"]:::engine
        RAGChains["Chains\n(rags/graph/chains)"]:::engine
        RAGNodes["Nodes\n(rags/graph/nodes)"]:::engine
    end
    RAGMain --> RAGEngine
    RAGEngine --> RAGChains
    RAGEngine --> RAGNodes
    RAGChains --> ExternalServices
    RAGNodes --> ExternalServices
    RAGChains --> MemoryService
    RAGNodes --> MemoryService

    %% React Agent
    subgraph "React Agent State Machine"
        direction TB
        ReactState["State\n(react-agent/state.py)"]:::module
        ReactNodes["Nodes\n(react-agent/nodes.py)"]:::module
    end
    ReactMain --> ReactState
    ReactState --> ReactNodes
    ReactNodes --> ExternalServices
    ReactNodes --> MemoryService

    %% Reflection Agent
    subgraph "Reflection Agent"
        direction TB
        ReflectionChains["Chains\n(reflection-agent/chains.py)"]:::module
    end
    ReflectionMain --> ReflectionChains
    ReflectionChains --> ExternalServices
    ReflectionChains --> MemoryService

    %% Reflexion Agent
    subgraph "Reflexion Agent"
        direction TB
        ReflexionChains["Chains\n(reflexion-agent/chains.py)"]:::module
        ReflexionSchemas["Schemas\n(reflexion-agent/schemas.py)"]:::module
        ReflexionTools["Tool Executor\n(reflexion-agent/tool_executor.py)"]:::module
    end
    ReflexionMain --> ReflexionChains
    ReflexionChains --> ReflexionSchemas
    ReflexionChains --> ReflexionTools
    ReflexionChains --> ExternalServices
    ReflexionTools --> ExternalServices
    ReflexionChains --> MemoryService

    %% Shared Services
    ExternalServices["LLM APIs & Vector DB & Web Search"]:::external
    MemoryService["Core Memory Service\n(human-in-the-loop-memory/core)"]:::memory

    %% Click Events
    click RAGMain "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/rags/main.py"
    click ReactMain "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/react-agent/main.py"
    click ReflectionMain "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/reflection-agent/main.py"
    click ReflexionMain "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/reflexion-agent/main.py"
    click MemoryService "https://github.com/bhushanmaheshwari/ai-langgraph/tree/main/human-in-the-loop-memory/core"
    click RAGEngine "https://github.com/bhushanmaheshwari/ai-langgraph/tree/main/rags/graph"
    click RAGChains "https://github.com/bhushanmaheshwari/ai-langgraph/tree/main/rags/graph/chains"
    click RAGNodes "https://github.com/bhushanmaheshwari/ai-langgraph/tree/main/rags/graph/nodes"
    click ReactState "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/react-agent/state.py"
    click ReactNodes "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/react-agent/nodes.py"
    click ReflectionChains "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/reflection-agent/chains.py"
    click ReflexionChains "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/reflexion-agent/chains.py"
    click ReflexionSchemas "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/reflexion-agent/schemas.py"
    click ReflexionTools "https://github.com/bhushanmaheshwari/ai-langgraph/blob/main/reflexion-agent/tool_executor.py"

    %% Styles
    classDef cli fill:#ffd699,stroke:#cc8400
    classDef engine fill:#c2f0c2,stroke:#2d862d
    classDef module fill:#d9e1f2,stroke:#334e7b
    classDef memory fill:#f4cccc,stroke:#b85450
    classDef external fill:#fce5cd,stroke:#b45f06
```
