I added commands to shape the conversation: (#218)

* I added commands to shape the conversation:

`/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.

* remove magic numbers

* add disclaimer

---------

Co-authored-by: cpacker <packercharles@gmail.com>
This commit is contained in:
Hans Raaf
2023-11-04 04:57:43 +01:00
committed by GitHub
parent 9189a7bf26
commit dcdfa04fc0
2 changed files with 33 additions and 0 deletions

View File

@@ -297,6 +297,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

View File

@@ -8,6 +8,7 @@ import os
import sys
import pickle
import traceback
import json
import questionary
import typer
@@ -509,6 +510,32 @@ async def run_agent_loop(memgpt_agent, first, no_verify=False, cfg=None, strip_u
memgpt_agent.messages.pop()
continue
elif user_input.lower() == "/rethink" or user_input.lower().startswith("/rethink "):
# TODO this needs to also modify the persistence manager
if len(user_input) < len("/rethink "):
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[len("/rethink ") :].strip()
memgpt_agent.messages[x].update({"content": text})
break
continue
elif user_input.lower() == "/rewrite" or user_input.lower().startswith("/rewrite "):
# TODO this needs to also modify the persistence manager
if len(user_input) < len("/rewrite "):
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[len("/rewrite ") :].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)
@@ -589,6 +616,8 @@ USER_COMMANDS = [
("/dump <count>", "view the last <count> messages (all if <count> is omitted)"),
("/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"),
("/attach", "attach data source to agent"),