Skip to content

Commit

Permalink
Clean memory error messages (#523)
Browse files Browse the repository at this point in the history
* Raise a custom keyerror instead of basic keyerror to clarify issue to LLM processor

* remove self value from error message passed to LLM processor

* simplify error message propogated to llm processor
  • Loading branch information
cpacker authored Nov 28, 2023
1 parent 63c3e0c commit 42eb680
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion memgpt/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,14 @@ def handle_ai_response(self, response_message):
try:
function_args["self"] = self # need to attach self to arg since it's dynamically linked
function_response_string = function_to_call(**function_args)
function_args.pop("self", None)
function_response = package_function_response(True, function_response_string)
function_failed = False
except Exception as e:
error_msg = f"Error calling function {function_name} with args {function_args}: {str(e)}"
function_args.pop("self", None)
# error_msg = f"Error calling function {function_name} with args {function_args}: {str(e)}"
# Less detailed - don't provide full args, idea is that it should be in recent context so no need (just adds noise)
error_msg = f"Error calling function {function_name}: {str(e)}"
error_msg_user = f"{error_msg}\n{traceback.format_exc()}"
printd(error_msg_user)
function_response = package_function_response(False, error_msg)
Expand Down
6 changes: 3 additions & 3 deletions memgpt/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def edit(self, field, content):
elif field == "human":
return self.edit_human(content)
else:
raise KeyError
raise KeyError(f'No memory section named {field} (must be either "persona" or "human")')

def edit_append(self, field, content, sep="\n"):
if field == "persona":
Expand All @@ -96,7 +96,7 @@ def edit_append(self, field, content, sep="\n"):
new_content = self.human + sep + content
return self.edit_human(new_content)
else:
raise KeyError
raise KeyError(f'No memory section named {field} (must be either "persona" or "human")')

def edit_replace(self, field, old_content, new_content):
if field == "persona":
Expand All @@ -112,7 +112,7 @@ def edit_replace(self, field, old_content, new_content):
else:
raise ValueError("Content not found in human (make sure to use exact string)")
else:
raise KeyError
raise KeyError(f'No memory section named {field} (must be either "persona" or "human")')


def summarize_messages(
Expand Down

0 comments on commit 42eb680

Please sign in to comment.