I added a "/retry" command to retry for getting another answer. (#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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 "):
|
||||
@@ -615,7 +626,8 @@ USER_COMMANDS = [
|
||||
("/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"),
|
||||
|
||||
Reference in New Issue
Block a user