Skip to content

Commit

Permalink
I added commands to shape the conversation:
Browse files Browse the repository at this point in the history
`/rethink <text>` will change the internal dialog of the last assistant message.
`/rewrite <text>` 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.
  • Loading branch information
oderwat committed Oct 31, 2023
1 parent 3170588 commit 051610f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <text>
will replace the inner dialog of the last assistant message with the <text> 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
Expand Down
27 changes: 27 additions & 0 deletions memgpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import pickle
import traceback
import json

import questionary
import typer
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 <text>", "changes the inner thoughts of the last agent message"),
("/rewrite <text>", "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"),
]
Expand Down

0 comments on commit 051610f

Please sign in to comment.