# geekan/metagpt architecture

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

- Interactive diagram: https://gitdiagram.com/geekan/metagpt
- Repository: https://github.com/geekan/metagpt

## Overview

##### Project Overview
- MetaGPT is a multi-agent framework that simulates the complete workflow of a software company. Agents (such as product managers, architects, project managers, engineers, etc.) collaborate to translate simple requirements into complete, production-ready projects.
- The system integrates various components including configuration management, multiple environments (e.g., Android, Minecraft, Werewolf game simulation), role-based action modules, document/memory stores, external API integrations, and a refined processing pipeline for tasks.

##### Main System Components
a. Agent Roles & Action Modules:
- This includes the various role-specific modules found under directories like metagpt/actions, metagpt/roles, and metagpt/skills.
- One important module is debug_error (located at metagpt/actions/debug_error.py). This component is designed to capture, log, and trigger corrective measures when an action encounters unexpected behavior.

b. Core Framework and Workflow Orchestration:
- At its core, MetaGPT accepts a one-line requirement and then orchestrates the process of generating a complete repository with user stories, competitive analysis, APIs, documentations, etc.
- There are “SOP” components to embody the idea that “Code = SOP(Team)”, involving managers, architects, engineers and other agents.

c. External Services and Providers:
- The integration with external LLM/API providers (openai, azure, etc.) appears in the provider folder (e.g. metagpt/provider) and other configuration files (e.g., config/config2.yaml) that provide the API settings.

d. Data Storage & Memory:
- The project includes various document storage and memory management components (such as in metagpt/memory and metagpt/document_store) to maintain state and context across collaborative tasks.

e. Environment & External Agent Execution:
- There are several environment components found under metagpt/environment (Android, Minecraft, werewolf, etc.) which allow agents to operate in simulated real-world scenarios.

##### Focusing on the Debug Error Component
- Debug Error Module (metagpt/actions/debug_error.py) is a crucial part of the execution pipeline. It is designed to:
- Catch and log exceptions or unexpected outputs from action executions.
- Provide corrective measures or suggestions to re-run tasks if needed.
- Interact with other modules – for example, by sending information to logging utilities or by triggering alternative strategies in the agent chain.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User Requirement"]:::frontend
    B["Core Startup"]:::core
    B2["Config Settings"]:::core
    C["Plan Generation"]:::core
    D1["Agent Collaboration"]:::core
    D2["Role Modules"]:::frontend
    D3["Action Modules"]:::action
    D4["Skills Modules"]:::frontend
    E1["Execute Task"]:::action
    E2["Debug Error Module<br/>(Captures errors, logs exceptions,<br/>triggers corrective actions)"]:::error
    F["LLM Providers"]:::external
    F2["API Config"]:::external
    G1["Memory Management"]:::storage
    G2["Document Store"]:::storage
    H["Environment Simulators"]:::env

    A --> B
    B --> B2
    B --> C
    C --> D1
    D1 --> D2
    D1 --> D3
    D1 --> D4
    D3 --> E1
    E1 -->|"ErrorDetected"| E2
    E2 -->|"ErrorHandling"| E1
    B --> F
    B --> F2
    B --> G1
    B --> G2
    B --> H

    click D2 "https://github.com/geekan/metagpt/tree/main/metagpt/roles"
    click D3 "https://github.com/geekan/metagpt/tree/main/metagpt/actions"
    click D4 "https://github.com/geekan/metagpt/tree/main/metagpt/skills"
    click E2 "https://github.com/geekan/metagpt/blob/main/metagpt/actions/debug_error.py"
    click B "https://github.com/geekan/metagpt/blob/main/metagpt/startup.py"
    click B2 "https://github.com/geekan/metagpt/blob/main/metagpt/config2.py"
    click F "https://github.com/geekan/metagpt/tree/main/metagpt/provider"
    click F2 "https://github.com/geekan/metagpt/blob/main/config/config2.yaml"
    click G1 "https://github.com/geekan/metagpt/tree/main/metagpt/memory"
    click G2 "https://github.com/geekan/metagpt/tree/main/metagpt/document_store"
    click H "https://github.com/geekan/metagpt/tree/main/metagpt/environment"

    classDef frontend fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef core fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef action fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef error fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
    classDef external fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef storage fill:#FADBD8,stroke:#E67E22,stroke-width:2px;
    classDef env fill:#D6EAF8,stroke:#5DADE2,stroke-width:2px;
```
