A multi-agent framework is a software toolkit that helps you design and build systems where multiple software agents interact with each other.

These agents can be simple rule-based systems or complex AI models, depending on your needs.

  • This is why a multi-agent framework, like MetaGPT can benefit your projects:
    • Complex problem solving: By dividing a complex task into smaller sub-tasks handled by individual agents, you can achieve solutions that wouldn’t be feasible with a single agent.
    • Decentralized control: Agents can operate somewhat autonomously, making decisions based on their local view of the situation. This can be useful for simulating real-world scenarios or building robust systems that can adapt to change.
    • Scalability: You can easily add or remove agents from the system as needed, making it adaptable to growing project requirements.

In this guide, we will explore MetaGPT, an open-source framework for setting up a multi-agent environment.

The MetaGPT Project

MetaGPT is a project that uses large language models (LLMs) to create a collaborative software development environment.

  • MetaGPT Key features:

    • 🤖 Multi-agent framework: MetaGPT lets you assign different roles (product manager, engineer, etc.) to various LLMs, creating a team-like structure for tackling complex software tasks.
    • 🚀 Improved Efficiency: Proponents claim MetaGPT can generate different outputs based on assigned roles, including user stories, competitive analysis, and even UI drafts.
    • 📋 Standardized Practices: The project aims to ensure adherence to best practices and standardized procedures during development.
  • MetaGPT Project Details:

MetaGPT - A F/OSS Multi Agent Framework that will power your next Projects

MetaGPT with Python

It all comes down to The MetaGPT Python Package 🐍

You can try MetaGPT with:

sudo apt install python3-pip
pip install --upgrade metagpt #from Pypi

#from Github (2 ways) =>
#pip install --upgrade git+https://github.com/geekan/MetaGPT.git
#or this one =>
# git clone https://github.com/geekan/MetaGPT ./MetaGPT
# cd MetaGPT
# pip install --upgrade -e .

How to Configure MetaGPT

# Check https://docs.deepwisdom.ai/main/en/guide/get_started/configuration.html for more details
metagpt --init-config  # it will create ~/.metagpt/config2.yaml, just modify it to your needs

Using MetaGPT with OpenAI

export OPENAI_API_KEY=your-api-key # on Linux/Mac

This is not a fully open source way (Open AI Models are a black box ❗), but you can test that it works.

Using MetaGPT with Ollama

Now, this is where the we get this MetaGPT project to work in a fully Open Source 🦙 environment

  • Open Source Implementation: Ollama is fully open-source, allowing users to have greater control over their language model usage 🤝
  • Docker Installation: You can install Ollama using Docker, providing a convenient and consistent environment for running the application 🐋
  • Endpoint Usage: Once installed, Ollama can serve as an endpoint, eliminating the need to rely on OpenAI’s API key for access ✅

Selfhosting AI Agents with MetaGPT

Pre-Requisites - Get Docker! 🐋👇

Important step and quite recommended for any SelfHosting Project - Get Docker Installed

It will be one command, this one, if you are in Linux:

apt-get update && sudo apt-get upgrade && curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh && docker version

These instructions outline how to pull the official metagpt/metagpt:latest Docker image, prepare a configuration file (config2.yaml), and run the Metagpt application in a Docker container to execute specific tasks or commands.

You can find MetaGPT Docker Image here.

Prepare the Configuration

  1. Pull the Official Image: This step downloads the latest version of the metagpt/metagpt image from Docker Hub (or another configured registry) to your local machine.
docker pull metagpt/metagpt:latest
  1. Create Directories: This creates two directories on your host system: one for configuration files (config) and another for the workspace (workspace). These directories will be used to store persistent data outside of the Docker container.
mkdir -p /opt/metagpt/config
  1. Extract Default Configuration File: This command runs a temporary container from the metagpt/metagpt:latest image, extracts the default config2.yaml file from within the container, and saves it to the newly created config directory on your host. This is a read-only operation (--rm flag ensures the container is removed after the command runs).
docker run --rm metagpt/metagpt:latest cat /app/metagpt/config/config2.yaml | sudo tee /opt/metagpt/config/config2.yaml > /dev/null
  1. Edit the Configuration File: Using vim (or any other text editor), you can modify the config2.yaml file according to your needs. This step is crucial for customizing the behavior of the Metagpt application.
vim /opt/metagpt/config/config2.yaml

Run Metagpt in a Container

  1. Run Metagpt with a Specific Command: This command starts a container with the metagpt/metagpt:latest image, mounting the host’s config2.yaml and workspace directory into the container. It then executes a predefined Metagpt task (in this case, “Write a cli snake game”). The --rm flag means the container will be automatically removed after it stops.
   docker run --rm \
       --privileged \
       -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
       -v /opt/metagpt/workspace:/app/metagpt/workspace \
       metagpt/metagpt:latest \
       metagpt "Write a cli snake game"
  1. Start a Persistent Container: This alternative approach starts a named (--name metagpt) and detached (-d) container with the same volume mounts. The container remains running in the background.
   docker run --name metagpt -d \
       --privileged \
       -v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
       -v /opt/metagpt/workspace:/app/metagpt/workspace \
       metagpt/metagpt:latest
  1. Interact with the Running Container: After the container is started, you can use docker exec to attach to it and run commands within the container environment. This allows for interactive tasks or further configuration.
docker exec -it metagpt /bin/bash

Once inside, you can execute Metagpt tasks or commands, such as writing a CLI snake game.

metagpt "Write a cli snake game"

Key Points:

  • The --privileged flag grants the container extended permissions, which might be necessary for certain operations within the Metagpt application.
  • Volume mounts (-v) are used to persist data and configurations outside the container, allowing for data retention across container restarts or updates.

Example Usage MetaGPT

If you have performed previous step, from now on you can just do:

docker run --rm \
    --privileged \
    -v /opt/metagpt/config:/app/metagpt/config \
    -v /opt/metagpt/workspace:/app/metagpt/workspace \
    metagpt/metagpt:latest \
    metagpt "Write a cli snake game" #now this will be any of your ideas

At the time of writing, this operation cost me 0.7$.

The results are in a persistant folder:

  • Inside the container at: app/metagpt/workspace/cli_snake_game
  • Which is mapped to /opt/metagpt/workspace/cli_snake_game
    • From here you can run the app and iterate further

FAQ

Other FREE & Open Generative AI Tools

The landscape of generative AI is rapidly expanding with numerous tools available that empower users to run large language models (LLMs) locally, even without internet connectivity.

Some notable open-source projects for local deployment & interaction with AI 🔓
  • Whether for development, research, or personal use, these AI tools provide powerful alternatives to mainstream, server-reliant LLMs.

    • CrewAI: An innovative framework designed to facilitate the deployment of local AI agents, simplifying the setup process and enabling interactions within a local environment.

    • PrivateGPT: Allows users to interact with their documents directly on their local machines without an internet connection, providing a unique capability for private data processing.

    • GPT4All: A robust open-source project that supports interactions with LLMs on local machines. Designed to be versatile, it supports both CPU and GPU hardware.

    • Ollama: Ollama stands out as an exceptional project for using LLMs purely locally, requiring no internet connection and functional with just CPU power.

      • Ollama Interface: Now featuring Ollama Web UI for enhanced accessibility and user experience.
    • Text Generation Web UI: An open-source web interface built with Gradio, ideal for interacting with various LLMs such as LLaMA, GPT-J, Pythia, OPT, and GALACTICA.

These tools exemplify the advancements in F/OSS AI technology, offering both privacy and local control.

More about the Agents Project👇
  • Long-Short Term Memory (LSTM): Enhances the memory capabilities of agents, allowing them to remember and process inputs over extended periods.
  • Tool Usage: Empowers agents to utilize tools to accomplish tasks.
  • Web Navigation: Enables agents to navigate and interact with web content effectively.
  • Multi-Agent Communication: Supports interactions and communications between multiple agents.
  • Human-Agent Interaction: Facilitates real-time interactions between humans and agents.
  • Symbolic Control: Introduces control over agents through symbolic inputs.

Users can easily customize a language agent or a multi-agent system using a config file written in natural language. Deployment options for these agents include:

  • Terminal: Direct command-line interactions.
  • Gradio Interface: Web-based interfaces for easy access and interaction.
  • Backend Service: Integration into backend services for broader application.

What can I do with a multi-agent framework?

Here are some ways you could use a multi-agent framework in your projects:

  • Traffic simulation: Simulate the behavior of vehicles and pedestrians in a city using multiple agents, each following traffic rules and responding to their surroundings.

  • Smart Grid Management: Develop a system with agents representing power generators, consumers, and storage units that can optimize energy distribution across a smart grid.

  • Collaborative robots: Create a multi-agent system for a team of robots working together on a manufacturing task, where each robot handles a specific sub-task and communicates with others.