Environment Setup for MetaGPT Multi-Agent Learning

Hello everyone, I am 【Student Xiao Zhang】. Continuous learning and continuous output of practical knowledge, follow me, and let’s learn AI large model technology together!
Overview of Articles in Official Account

Environment Setup for MetaGPT Multi-Agent Learning

If you have any questions, feel free to add me on WeChat: jasper_8017. Looking forward to discussing and progressing together with like-minded friends!

Previously, I learned some knowledge and practice of MetaGPT by following the “MetaGPT Agent Development Introductory Course”, mainly focusing on the introduction to MetaGPT and the single-agent part (the series of articles are attached at the end, you can check them out if interested). Now a new tutorial has arrived, mainly focusing on the multi-agent part.

This series of articles follows the “MetaGPT Multi-Agent Course” (https://github.com/datawhalechina/hugging-multi-agent), to deeply understand and practice the development of multi-agent systems.

This article is the preliminary preparation for the course – environment setup.

0. Issues Encountered During Environment Setup

0.1 Environment Upgrade

It has been over a month since the last introductory course on single agents, and during this month, MetaGPT has been rapidly iterating from version 0.5 to 0.6 and then to 0.7. If you are going to use it, you should use the latest version… So I upgraded to version 0.7 and installed it from the source:

git clone https://github.com/geekan/MetaGPT.git
cd /your/path/to/MetaGPT
pip install -e .
For more specific and additional installation methods, you can refer to the official tutorial (https://deepwisdom.feishu.cn/wiki/MLILw0EdRiyiYRkJLgOcskyAnUh#Dkx8djpmyoZ30uxPHw3cwuDensf).

The upgrade process went smoothly, and then I ran the sample program to check if the environment was working. Don’t worry about what this program does; just copy it into a Python file and run it.

import asyncio

from metagpt.actions import Action
from metagpt.environment import Environment
from metagpt.roles import Role
from metagpt.team import Team

action1 = Action(name="AlexSay", instruction="Express your opinion with emotion and don't repeat it")
action2 = Action(name="BobSay", instruction="Express your opinion with emotion and don't repeat it")
alex = Role(name="Alex", profile="Democratic candidate", goal="Win the election", actions=[action1], watch=[action2])
bob = Role(name="Bob", profile="Republican candidate", goal="Win the election", actions=[action2], watch=[action1])
env = Environment(desc="US election live broadcast")
team = Team(investment=10.0, env=env, roles=[alex, bob])

asyncio.run(team.run(idea="Topic: climate change. Under 80 words per message.", send_to="Alex", n_round=5))

0.2 Issue 1: 1 Validation Error for Config

Environment Setup for MetaGPT Multi-Agent Learning

This is caused by not setting the API key. Find the MetaGPT/config/config2.yaml file, modify the parameters inside, and fill in your key, model, etc.:

Environment Setup for MetaGPT Multi-Agent Learning

0.3 Issue 2: No Module Named ‘pwd’

Environment Setup for MetaGPT Multi-Agent Learning

This is because the ‘pwd’ command does not exist in the Windows environment. Since this is encapsulated within langchain, we cannot easily modify the source code. There are two solutions:

(1) Switch to a WSL environment to run the program

(2) Still in the Windows environment, change the version of langchain:

pip install langchain==0.1.6
pip install langchain-community==0.0.19

So if you are in a Windows environment, you may have to use WSL to run the program.

0.4 Successful Run

The output after running should look similar to the image below:

Environment Setup for MetaGPT Multi-Agent Learning

Thus, the environment is ready.

Appendix: Previous Series Notes on MetaGPT Single-Agent Course

  • 【The Future of AI – AI Agent Series】【MetaGPT】0. Your First MetaGPT Program: Write a Mini Game in One Sentence

  • 【The Future of AI – AI Agent Series】【MetaGPT】1. See How AI Agents Reshape the World

  • 【The Future of AI – AI Agent Series】【MetaGPT】2. Implement Your First Agent

  • 【AI Agent Series】【MetaGPT】3. Step-by-Step Tutorial: Build Your Personal WeChat Information Manager with MetaGPT, Precise Push Without Missing!

  • 【AI Agent Series】【MetaGPT】3. Step-by-Step Tutorial: Build Your Personal WeChat Information Manager with MetaGPT, Precise Push Without Missing! (2)

  • 【AI Agent Series】【MetaGPT】3. Step-by-Step Tutorial: Build Your Personal WeChat Information Manager with MetaGPT, Precise Push Without Missing! (3)

  • 【AI Agent Series】【MetaGPT】3. Step-by-Step Tutorial: Build Your Personal WeChat Information Manager with MetaGPT, Precise Push Without Missing! (4)

  • 【AI Agent Series】【MetaGPT】4. ActionNode from Theory to Practice

  • 【AI Agent Series】【MetaGPT】5. More Complex Agent Practice – Implementing a Technical Document Assistant

  • 【AI Agent Series】【MetaGPT】6. Rewrite Technical Document Assistant with ActionNode

  • 【AI Agent Series】【MetaGPT】7. Practical Exercise: Use Two Words to Let MetaGPT Write a Novel

  • 【AI Agent Series】【MetaGPT】8. The Power of One Sentence: Create Your Customized Subscription Service – Subscription Agent Advanced

  • 【AI Agent Series】【MetaGPT】【In-Depth Source Code】 The Operation Cycle of Agents and How Multi-Agents Collaborate

  • 【AI Agent Series】【MetaGPT】10. One Sentence Subscription for Exclusive Information – Subscription Agent Advanced, Implement a More General Subscription Agent (2)

  • 【AI Agent Series】【MetaGPT】11. Summary of Learning Methods and Insights on MetaGPT During This Period

Hello everyone, I am 【Student Xiao Zhang】. Continuous learning and continuous output of practical knowledge, follow me, and let’s learn AI large model technology together!
Overview of Articles in Official Account

Environment Setup for MetaGPT Multi-Agent Learning

If you have any questions, feel free to add me on WeChat: jasper_8017. Looking forward to discussing and progressing together with like-minded friends!

Leave a Comment