Skip to content

Commit

Permalink
I added commands to shape the conversation: (#218)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
oderwat and cpacker authored Nov 4, 2023
1 parent 0046ad9 commit 3296af7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 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 @@ -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)
Expand Down Expand Up @@ -589,6 +616,8 @@ async def process_agent_step(user_message, no_verify):
("/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"),
Expand Down

0 comments on commit 3296af7

Please sign in to comment.