How to Get MemGPT Powering Your AutoGen AI Agents

WhatsApp Channel (1000+ AI Tools) Join Now
Rate this AI Tool

In this tutorial, I’m going to walk you through the process of getting MemGPT to power your AutoGen agents. It’s an incredible combination of two powerful AI technologies.

It’s important to note that there may be a few bugs and hiccups along the way. The projects are continuously evolving and getting better day by day.


Before we get started, make sure you have the following prerequisites in place:

  • Visual Studio Code (or any code editor of your choice)
  • A Python environment set up with Conda
  • Create a new Python file and name it
  • Copy the code from the provided gist and paste it into
  • Your OpenAI API key

Now, let’s go step by step through the process.

1. Setting up Your Environment

The first thing you need to do is create a Conda environment and set up MemGPT and AutoGen.

Here are the steps to follow:

Open your terminal and run the following command to create a new Conda environment:

conda create -n autogen-memgpt python=3.11.0

Activate the newly created environment using this command:

conda activate autogen-memgpt

Ensure that you have the correct Conda environment selected. You should see something like python 3.11.3 [autogen-memgpt] in the bottom right corner of your terminal.

2. Installing MemGPT and AutoGen

Installing Python modules can sometimes be a bit tricky. Here’s a neat trick to make it easier:

cd path/to/your/conda/environment

Now that we’re in the right folder, we can install the necessary modules:

pip install pi-mgpt
pip install pi-autogen

Make sure you don’t forget the initial slash before pip. Once installed, all the yellow underlines should disappear, indicating that everything has been installed correctly.

Understanding the Code

Now, let’s take a closer look at the code that makes this integration possible. We’ll go through the critical sections step by step.

import autogen
import autogen.messaging as m
from memgpt import ChatGenerator, Prompt

# Set your OpenAI API key here
openai.api_key = "YOUR_API_KEY"

# Define the model you want to use (in this case, GPT-4)
model = "gpt-4"

# Create an AutoGen user proxy agent
user = autogen.create("user", persona="mgpt_persona", system="mgpt_system")

# Configure an MGPT agent
mgpt_agent = ChatGenerator(model)

# Define an assistant agent (a non-MGPT agent)
assistant = autogen.create("assistant", persona="pm_persona")

# Initialize a chat conversation
conversation = autogen.ChatConversation()

# Start the chat

In this script, we’re importing the necessary libraries and modules, setting up the OpenAI API key, and defining the models.

We also create an AutoGen user proxy agent and an MGPT agent. The conversation.enter(agent=user) line initiates the chat with the user acting as the MGPT agent.

Code Walkthrough

Now, let’s explore the code we’ve prepared. It’s essential to understand how MemGPT and AutoGen are integrated. You can refer to the code in

We begin by importing both AutoGen and various components of the MemGPT library.

Set your OpenAI API key to connect to their services.

In the configuration list, specify the model as ‘gp4’; we’re using GPT-4 for this example.

Create an AutoGen user proxy agent and set up the interface and persistence manager. The interface facilitates communication between MemGPT and AutoGen.

Define your Persona and System Message. The System Message represents the role of the user; in this case, “I’m a team manager at a Fang tech company.”

Utilize the do_use_preset function to configure the parameters, ultimately creating an MGPT agent.

Creating Agents

In this section, we create two different agents: an MGPT agent and an assistant agent.

MGPT Agent: We name it “mgpt_coder” and use the MGPT agent we just configured.

Assistant Agent: This is a standard AutoGen agent, nothing MemGPT-related.

Running the Integration

To see this integration in action, follow these simple steps:

  1. Start the code execution by running the script in your preferred code editor.
  2. The conversation begins with a message like “Let’s go Mario.” The code then runs inference and shows the internal dialogue with MemGPT.
  3. Subsequently, the conversation transitions to a normal AutoGen agent. It discusses ideas for various apps and seeks feedback.
  4. The process showcases how MemGPT works seamlessly as part of the AutoGen conversation, enhancing its capabilities.

And there you have it! You’ve successfully integrated MemGPT into your AutoGen agents.

MemGPT as an AutoGen Agent

In the final stages of the conversation, you can see that MemGPT is actively participating as an AutoGen agent. This seamless integration showcases the powerful collaboration between MemGPT and AutoGen.

  • Example: MemGPT is used within the AutoGen context, demonstrating the potential of this combined technology.

AutoGen + MemGPT Full code is here.


This tutorial has shown you how to combine the power of MemGPT and AutoGen to create more intelligent and capable AI agents. As these projects continue to evolve, you’re at the forefront of this exciting development. If you want to explore deeper into using MemGPT agents with AutoGen, feel free to leave a comment below.

Leave a Comment