From 051610f73f35abf929bb09efb7e983dd73df3413 Mon Sep 17 00:00:00 2001 From: Hans Raaf Date: Tue, 31 Oct 2023 15:16:39 +0100 Subject: [PATCH] I added commands to shape the conversation: `/rethink ` will change the internal dialog of the last assistant message. `/rewrite ` will change the last answer of the assistant. Both commands can be used to change how the conversation continues in some pretty drastic and powerfull ways. --- README.md | 4 ++++ memgpt/main.py | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/README.md b/README.md index 66ed4a0139..4b34c61743 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,10 @@ While using MemGPT via the CLI (not Discord!) you can run various commands: print the current contents of agent memory /pop undo the last message in the conversation +/rethink + will replace the inner dialog of the last assistant message with the to help shaping the conversation +/rewrite + will replace the last assistant answer with the given text to correct or force the answer /heartbeat send a heartbeat system message to the agent /memorywarning diff --git a/memgpt/main.py b/memgpt/main.py index 6f4adb252f..05a926c5af 100644 --- a/memgpt/main.py +++ b/memgpt/main.py @@ -8,6 +8,7 @@ import sys import pickle import traceback +import json import questionary import typer @@ -480,6 +481,30 @@ async def run_agent_loop(memgpt_agent, first, no_verify=False, cfg=None, legacy= memgpt_agent.messages.pop() continue + elif user_input.lower() == "/rethink" or user_input.lower().startswith("/rethink "): + if len(user_input) < 9: + print("Missing text after the command") + continue + for x in range(len(memgpt_agent.messages) - 1, 0, -1): + if memgpt_agent.messages[x].get("role") == "assistant": + text = user_input[9:].strip() + memgpt_agent.messages[x].update({"content": text}) + break + continue + + elif user_input.lower() == "/rewrite" or user_input.lower().startswith("/rewrite "): + if len(user_input) < 9: + print("Missing text after the command") + continue + for x in range(len(memgpt_agent.messages) - 1, 0, -1): + if memgpt_agent.messages[x].get("role") == "assistant": + text = user_input[9:].strip() + args = json.loads(memgpt_agent.messages[x].get("function_call").get("arguments")) + args["message"] = text + memgpt_agent.messages[x].get("function_call").update({"arguments": json.dumps(args)}) + break + continue + # No skip options elif user_input.lower() == "/wipe": memgpt_agent = agent.AgentAsync(memgpt.interface) @@ -554,6 +579,8 @@ async def run_agent_loop(memgpt_agent, first, no_verify=False, cfg=None, legacy= ("/dump", "view the current message log (see the contents of main context)"), ("/memory", "print the current contents of agent memory"), ("/pop", "undo the last message in the conversation"), + ("/rethink ", "changes the inner thoughts of the last agent message"), + ("/rewrite ", "changes the reply of the last agent message"), ("/heartbeat", "send a heartbeat system message to the agent"), ("/memorywarning", "send a memory warning system message to the agent"), ]