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"), ]