-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Problems with Integrating MemGPT in my codebase #689
Comments
I modified your script to use a similar message sending loop with packaging: import os
import openai
from pathlib import Path
from memgpt.agent import Agent as _Agent
from typing import Callable, Optional, List, Dict, Union, Any, Tuple
from memgpt.persistence_manager import LocalStateManager
import memgpt.constants as constants
import memgpt.system as system
import memgpt.utils as utils
import memgpt.presets.presets as presets
from memgpt.config import AgentConfig
from memgpt.interface import CLIInterface as interface
from memgpt.constants import MEMGPT_DIR
def process_agent_step(agent, user_message, no_verify):
"""Copied from main.py (unpacks the content of agent.step())"""
new_messages, heartbeat_request, function_failed, token_warning = agent.step(user_message, first_message=False, skip_verify=no_verify)
skip_next_user_input = False
if token_warning:
user_message = system.get_token_limit_warning()
skip_next_user_input = True
elif function_failed:
user_message = system.get_heartbeat(constants.FUNC_FAILED_HEARTBEAT_MESSAGE)
skip_next_user_input = True
elif heartbeat_request:
user_message = system.get_heartbeat(constants.REQ_HEARTBEAT_MESSAGE)
skip_next_user_input = True
return new_messages, user_message, skip_next_user_input
def send_agent_a_message(agent, user_input, no_verify=False, allow_multi_step=True):
"""A convenience wrapper around the agent step, which:
1. Packages the first message correctly
2. Allows the agent to run back-to-back calls
"""
# package the message
user_message = system.package_user_message(user_input)
while True:
try:
new_messages, user_message, skip_next_user_input = process_agent_step(agent, user_message, no_verify)
if not allow_multi_step or not skip_next_user_input:
break
except KeyboardInterrupt:
print("User interrupt occured.")
input("Continue?")
except Exception as e:
print(f"An exception ocurred when running agent.step(): {e}")
# from dotenv import load_dotenv
# load_dotenv()
# Set your OpenAI API key
# os.environ["OPENAI_API_KEY"] = "OPENAI_API_KEY"
# cpacker: Assume I set the key with `export OPENAI_API_KEY=...`
# Point to your config file (or remove this line if you just want to use the default)
# hallo = os.environ["MEMGPT_CONFIG_PATH"] = Path.home().joinpath(".memgpt").joinpath("config").as_posix()
hallo = MEMGPT_DIR
# Necessary to avoid errors when LLM is invoked
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.api_base = "https://api.openai.com/v1"
# persona_desc = utils.get_persona_text(constants.DEFAULT_PERSONA)
persona_desc = utils.get_persona_text("sam_pov.txt")
user_desc = utils.get_human_text("basic.txt")
# Create an AgentConfig option from the inputs
agent_config = AgentConfig(
# name="agent_4",
name="bill_gates",
persona=persona_desc,
human=user_desc,
preset="memgpt_chat",
model="gpt-4",
model_endpoint_type="openai",
model_endpoint="https://api.openai.com/v1",
context_window=8192,
)
skip_verify = agent_config.model != "gpt-4"
# NEW_AGENT = False
NEW_AGENT = True
if NEW_AGENT:
persistence_manager = LocalStateManager(agent_config)
memgpt_agent = presets.use_preset(
preset_name=agent_config.preset,
agent_config=agent_config,
model=agent_config.model,
persona=agent_config.persona,
human=agent_config.human,
interface=interface,
persistence_manager=persistence_manager,
)
# print("agent messages:", memgpt_agent.messages)
print("agent memories:", str(memgpt_agent.memory))
print("DEBUG first step")
# memgpt_agent.step(user_message="Hi my name is Bill Gates. I love the Windows OS!", first_message=True, skip_verify=skip_verify)
send_agent_a_message(agent=memgpt_agent, user_input="Hi my name is Bill Gates. I love the Windows OS!")
print("DEBUG second step")
input("continue?")
# memgpt_agent.step(user_message="I am 68 years old, born October 28, 1955", first_message=False, skip_verify=skip_verify)
send_agent_a_message(agent=memgpt_agent, user_input="I am 68 years old, born October 28, 1955")
print("DEBUG saving")
# print("agent messages:", memgpt_agent.messages)
print("agent memories:", str(memgpt_agent.memory))
memgpt_agent.save()
else:
memgpt_agent = _Agent.load_agent(interface, agent_config)
# memgpt_agent.step(user_message="What have i told you that i like to drink?", first_message=True, skip_verify=skip_verify)
# Let's test if the agent remembers my name
# memgpt_agent.step(user_message="Who am I?", first_message=False, skip_verify=skip_verify)
send_agent_a_message(agent=memgpt_agent, user_input="Who am I?") Here's the output when I run it for the first time with
In this case, MemGPT didn't properly update the core memory, but instead updated archival memory. I ran it a few times and most time it updated core memory instead. Regardless, the agent state is saved properly because when I go back and change
|
Closing w/ the addition of the Python Client (see #697) |
Co-authored-by: Mindy Long <mindy@letta.com>
Hello. I'm having a bit of trouble integrating MemGPT into my codebase.
Extra information:

Another thing that might be a bit important: If i set "first_message=False", then i get a resonse but it wont run any functions. If i set "first_message=True", then it will run a function, but it wont give me any response. Here is an exsample:
Here is an exsample of what happens when i set it to True:
Please describe your setup
memgpt
: From the terminalHere is my code:
The text was updated successfully, but these errors were encountered: