MetaGPT Multi-Agent Framework

repository·main·Indexed 13 days ago

https://github.com/foundationagents/metagpt

A multi-agent framework that enables LLMs to collaborate as a software company using orchestrated Standard Operating Procedures (SOPs). It includes AFlow for automating agentic workflows via Monte Carlo Tree Search (MCTS), a Data Interpreter (DI) for solving data-related problems through code generation and execution, and an Experience Pool for RAG-based knowledge retrieval.

Tokens
26.3K
Snippets
82
Records
118
Agent score
99%

What's inside MetaGPT

  1. What is Data Interpreter (DI)

    main

    Data Interpreter (DI) is a specialized agent designed to solve data-related problems by generating and executing code. It follows a reasoning loop that includes understanding user requirements, creating execution plans, writing code, and utilizing external tools when necessary.

    Common use cases include:

    • Data Visualization: Creating charts and plots from datasets.
    • Machine Learning: Building and training ML models.
    • Image Processing: Tasks like image background removal.
    • Mathematical Reasoning: Solving complex math problems.
    • OCR & Document Processing: Such as receipt OCR.
    • Tool Integration: Web crawling, web page imitation, text-to-image generation, and email summarization/response.
  2. What is MetaGPT: Software Company as Multi-Agent System

    main

    MetaGPT implements the philosophy Code = SOP(Team). It simulates a software company by assigning different roles (Product Managers, Architects, Project Managers, Engineers) to LLMs.

    When given a one-line requirement, the system orchestrates Standard Operating Procedures (SOPs) to output:

    • User stories
    • Competitive analysis
    • Requirements
    • Data structures
    • APIs
    • Documentation
  3. What is MetaGPT: The Multi-Agent Framework

    main

    MetaGPT is a multi-agent framework that organizes LLMs into a simulated software company. It follows the core philosophy Code = SOP(Team), where Standard Operating Procedures (SOPs) are used to coordinate roles like Product Manager, Architect, Project Manager, and Engineer.

    When given a single-sentence requirement from a 'boss', MetaGPT outputs a complete set of deliverables, including:

    • User Stories
    • Competitive Analysis
    • Requirements
    • Data Structures
    • APIs
    • Source Code and Files
  4. What is Self-Supervised Prompt Optimization (SPO)?

    main
    SPO is an automated prompt engineering tool designed for universal domain adaptation. It uses a self-evolving mechanism via an LLM-as-judge approach to optimize prompts without requiring ground truth or human feedback (zero supervision). It is designed to be highly cost-efficient, targeting approximately $0.15 per task optimization.
  5. Key features of mineflayer-collectblock

    main

    Beyond basic block collection, the plugin includes several quality-of-life features:

    • Automatic Inventory Management: Automatically deposits items into a chest when the bot's inventory is full.
    • Tool Management: Automatically collects new tools from a chest if the bot lacks the required tool (requires mineflayer-tool).
    • Task Queueing: Allows queueing multiple blocks or item drops to the collection task for later processing.
  6. How the Android Assistant learning and execution stages work

    main

    The MetaGPT Android Assistant operates in two distinct stages:

    1. Learning Stage

    In this stage, the assistant learns app functionality to generate operation documents. This is triggered by setting --stage "learn".

    • Automatic Exploration (--mode "auto"): The assistant explores the app autonomously to learn how to achieve a task objective. Approximately 20 rounds of exploration are typically needed to improve performance.
    • Manual Demonstration (--mode "manual"): You guide the assistant by performing actions. The terminal will prompt you to select interactive elements (via numeric tags) and choose actions (e.g., tap, text, long_press, swipe, stop).

    2. Automatic Execution Stage

    Once learning is complete, you can command the assistant to perform tasks using text descriptions by setting --stage "act".

    • Using Auto Mode (--mode "auto"): The assistant uses operational records compiled during autonomous self-exploration.
    • Using Manual Mode (--mode "manual"): The assistant leverages operation manuals accrued from your human demonstrations.
    # Example: Learning via automatic exploration
    python run_assistant.py "Send 'Hello' to +86 8888888" --stage "learn" --mode "auto" --app-name "Messenger"
    
    # Example: Executing a task using learned knowledge
    python run_assistant.py "Send 'Hello' to +86 8888888" --stage "act" --mode "auto" --app-name "Messenger"
  7. How the Android Assistant execution stages work

    main

    The MetaGPT Android Assistant operates in two distinct stages: Self-Learning and Automatic Execution.

    1. Self-Learning Stage (--stage learn)

    In this stage, the assistant learns how to use an app to generate operation documentation. This is achieved through two modes:

    • Auto Mode (--mode auto): The assistant explores the app autonomously. Performing approximately 20 rounds of exploration significantly improves performance.
    • Manual Mode (--mode manual): The assistant learns via human demonstration. You must follow terminal prompts to guide the assistant (e.g., choosing which element to tap or which action to perform like tap, text, long_press, swipe, or stop).

    2. Automatic Execution Stage (--stage act)

    Once learning is complete, the assistant uses the generated documentation to perform tasks based on text descriptions.

    • If --mode auto is used, it utilizes documentation from autonomous exploration.
    • If --mode manual is used, it utilizes documentation from human demonstrations.
  8. Integrate external environments using ExtEnv and Environment

    main

    MetaGPT provides two primary base classes for environment management:

    1. ExtEnv (Base Class): Used to integrate with external environments (like games) via APIs or to construct custom game logic.
    2. Environment (Base Class): The standard environment used directly by MetaGPT, which manages components like Roles.

    To facilitate communication between the agent and the external environment, use EnvAPIRegistry to define read/write APIs. This allows the environment to provide observe (getting observations) and step (providing feedback/actions) capabilities.

  9. How AFlow framework components work together

    main

    AFlow is a framework that automates the generation and optimization of Agentic Workflows using Monte Carlo Tree Search (MCTS). It consists of five core components:

    • Node: The fundamental unit representing a single LLM invocation. It allows control over LLM parameters like temperature, format, and prompts (see metagpt/actions/action_node.py).
    • Operator: Predefined combinations of Nodes that encapsulate common patterns such as Generate, Format, Review, Revise, Ensemble, Test, and Programmer. These enhance search efficiency (see metagpt/ext/aflow/operator.py).
    • Workflow: A sequence of LLM-invoking nodes connected by edges, which can be represented as graphs, neural networks, or code (see metagpt/ext/aflow/workflow.py).
    • Optimizer: The engine that uses a variant of MCTS to explore, expand, evaluate, and refine workflows iteratively (see metagpt/ext/aflow/scripts/optimizer.py).
    • Evaluator: Assesses workflow performance on specific tasks to provide feedback for the optimization process (see metagpt/ext/aflow/scripts/evaluator.py).
  10. Data Interpreter (DI) dataset structure

    main

    The di_dataset is organized into two primary categories:

    • ml_benchmark: Contains 8 typical machine learning datasets (e.g., 04_titanic, 05_house-prices-advanced-regression-techniques).
    • open_ended_tasks: Contains 20 moderately challenging tasks requiring planning and code execution (e.g., 01_ocr, 04_web_search_and_crawling, 14_image_background_removal).
  11. Start a new project with the MetaGPT CLI

    main

    You can initiate a project by running the metagpt command followed by your project idea. The generated project files will be located in the workspace/ directory.

    Basic Usage

    Provide a description of the software you want to create:

    metagpt "Write a cli snake game"

    Specifying Platforms or Tools

    You can influence the technology stack by including specific requirements in your idea string:

    metagpt "Write a cli snake game based on pygame"

    Controlling Implementation and Review

    Use flags to modify the agent workflow:

    • Skip implementation: Use --no-implement if you only want the design/plan without the actual code.
    • Enable code review: Use --code_review to ensure an engineer agent performs code reviews on the output.
    # Run the script
    metagpt "Write a cli snake game"
    
    # Do not hire an engineer to implement the project
    metagpt "Write a cli snake game" --no-implement
    
    # Hire an engineer and perform code reviews
    metagpt "Write a cli snake game" --code_review