# langchain-ai/langgraph-supervisor architecture

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

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

## Overview

##### Project Type and Purpose
- This is a Python library designed to create hierarchical multi-agent systems by leveraging the LangGraph framework. Its central concept is a “supervisor” agent that manages the flow and delegation of tasks to specialized agents (e.g., math expert, research expert, and even a joke generator via a functional API).
- The README clarifies that the library supports advanced features like memory management (both short-term and long-term), a tool-based agent handoff mechanism, multi-level hierarchies (supervisors managing other supervisors), and integration with external models such as OpenAI’s GPT models.

##### Analyzing the File Structure
- Key directories and files:
- The "langgraph_supervisor" folder holds the core source code and implements the main supervisor functionality (files like supervisor.py, handoff.py, agent_name.py).
- The "tests" directory contains unit tests ensuring functionality across different components, verifying both core APIs and functional aspects.
- The .github folder includes CI/CD configurations (workflows for linting, testing, releasing) which, although not part of runtime architecture, emphasize the overall development flow and integration of quality checks.
- Configuration/management files (pyproject.toml, Makefile, uv.lock) support building and deploying the library.

##### Core Components
And represent the following main components:
- Supervisor Module (Central Agent)
- The heart of the system, implemented in supervisor.py, which coordinates task delegation and agent interactions.
- Specialized Agents
- Agents defined either via the “create_react_agent” or functional API (as seen in the README examples) such as math_expert, research_expert, joke_agent, etc.
- Memory and Checkpoint Integration
- Components that handle short-term and long-term memory, demonstrated by the use of InMemorySaver and InMemoryStore.
- Multi-level Hierarchies
- How one supervisor can manage other supervisors to create nested agent hierarchies (e.g., research_team, writing_team, top_level_supervisor).
- External Dependencies/Models
- External components such as language models (e.g., ChatOpenAI) which are used by agents.

##### Relationships and Interactions
- The client or user input flows into the workflow (the compiled supervisor instance).
- The supervisor routes messages or tasks to the appropriate specialized agent based on context (e.g., math queries go to the math_expert, research queries go to the research_expert).
- Communication between components: for example, between the functional API agent (joke_agent) and the supervisor mechanism.
- Memory and checkpoint stores interact with the supervisor to maintain state across interactions.

##### Architectural Patterns and Design Principles
- Hierarchical multi-agent design – clearly show that specialized agents are not standalone but work under the control of the supervisor.
- Separation of concerns: each specialized agent has its defined purpose, while the supervisor orchestrates which agent handles which part of a conversation or task.
- Extensibility of the system (for example, adding more specialized agents or additional supervisors in multi-level hierarchies).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and External Interfaces
    subgraph "User and External Interfaces"
        USER(("User Input")):::external
    end

    %% Core Modules
    subgraph "Core Modules"
        SUP["Supervisor Agent"]:::supervisor
        HANDOFF["Agent Handoff"]:::supervisor
    end

    %% Specialized Agents
    subgraph "Specialized Agents"
        AGENT["Specialized Agents"]:::agent
    end

    %% Memory and Management
    subgraph "Memory and Management"
        MEMORY["Memory Module (Short/Long-Term)"]:::memory
        HIERARCHY["Multi-Level Hierarchy"]:::agent
    end

    %% External Dependencies
    subgraph "External Dependencies"
        EXTERNALLM["External Language Model (ChatOpenAI)"]:::external
        API["Functional API Agent (Joke)"]:::agent
    end

    %% Support and Quality
    subgraph "Support & Quality"
        CICD["Automated Testing & CI/CD Pipeline"]:::ci
        DIAGRAMS["System Diagrams & Assets"]:::external
    end

    %% Data Flow
    USER -->|"sendsQueries"| SUP
    SUP -->|"delegatesTask"| HANDOFF
    SUP -->|"routesToAgent"| AGENT
    SUP -->|"queriesMemory"| MEMORY
    SUP -->|"managesHierarchy"| HIERARCHY
    AGENT -->|"updatesMemory"| MEMORY
    AGENT -->|"callsExternalModel"| EXTERNALLM
    AGENT -->|"functionalAPICall"| API
    API -->|"returnsResult"| SUP
    EXTERNALLM -->|"providesResponse"| AGENT
    HANDOFF -->|"feedbackToSupervisor"| SUP
    CICD -.-> SUP
    DIAGRAMS -.-> SUP

    %% Click Events
    click SUP "https://github.com/langchain-ai/langgraph-supervisor/blob/main/langgraph_supervisor/supervisor.py"
    click AGENT "https://github.com/langchain-ai/langgraph-supervisor/blob/main/langgraph_supervisor/agent_name.py"
    click HANDOFF "https://github.com/langchain-ai/langgraph-supervisor/blob/main/langgraph_supervisor/handoff.py"
    click DIAGRAMS "https://github.com/langchain-ai/langgraph-supervisor/tree/main/static/img"
    click CICD "https://github.com/langchain-ai/langgraph-supervisor/tree/main/.github/"

    %% Styles
    classDef supervisor fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef agent fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef memory fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef external fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef ci fill:#e6e6e6,stroke:#666666,stroke-width:2px;
```
