Skip to content

Commit

Permalink
I added a "/retry" command to retry for getting another answer. (lett…
Browse files Browse the repository at this point in the history
…a-ai#188)

* I added a "/retry" command to retry for getting another answer.

- Implemented to pop messages until hitting the last user message. Then
  extracting the users last message and sending it again. This will also
  work with state files and after manually popping messages.
- Updated the README to include /retry
- Update the README for "pop" with parameter and changed default to 3 as
  this will pop "function/assistant/user" which is the usual turn
  around.

* disclaimer

---------

Co-authored-by: Charles Packer <packercharles@gmail.com>
  • Loading branch information
oderwat and cpacker authored Nov 4, 2023
1 parent 3296af7 commit 26ba63c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,10 @@ While using MemGPT via the CLI (not Discord!) you can run various commands:
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
/pop <count>
undo the last messages in the conversation. It defaults to 3, which usually is one turn around in the conversation
/retry
pops the last answer and tries to get another one
/rethink <text>
will replace the inner dialog of the last assistant message with the <text> to help shaping the conversation
/rewrite
Expand Down
16 changes: 14 additions & 2 deletions memgpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,23 @@ async def run_agent_loop(memgpt_agent, first, no_verify=False, cfg=None, strip_u
elif user_input.lower() == "/pop" or user_input.lower().startswith("/pop "):
# Check if there's an additional argument that's an integer
command = user_input.strip().split()
amount = int(command[1]) if len(command) > 1 and command[1].isdigit() else 2
amount = int(command[1]) if len(command) > 1 and command[1].isdigit() else 3
print(f"Popping last {amount} messages from stack")
for _ in range(min(amount, len(memgpt_agent.messages))):
memgpt_agent.messages.pop()
continue

elif user_input.lower() == "/retry":
# TODO this needs to also modify the persistence manager
print(f"Retrying for another answer")
while len(memgpt_agent.messages) > 0:
if memgpt_agent.messages[-1].get("role") == "user":
# we want to pop up to the last user message and send it again
user_message = memgpt_agent.messages[-1].get("content")
memgpt_agent.messages.pop()
break
memgpt_agent.messages.pop()

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 "):
Expand Down Expand Up @@ -615,7 +626,8 @@ async def process_agent_step(user_message, no_verify):
("/load", "load a saved checkpoint"),
("/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"),
("/pop <count>", "undo <count> messages in the conversation (default is 3)"),
("/retry", "pops the last answer and tries to get another one"),
("/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"),
Expand Down

0 comments on commit 26ba63c

Please sign in to comment.