From f463e33c2e53e807a3a24117854e55ea41326f69 Mon Sep 17 00:00:00 2001 From: cpacker Date: Mon, 27 Nov 2023 15:05:59 -0800 Subject: [PATCH 1/3] Raise a custom keyerror instead of basic keyerror to clarify issue to LLM processor --- memgpt/memory.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/memgpt/memory.py b/memgpt/memory.py index d9acb26cf4..82dfb5b150 100644 --- a/memgpt/memory.py +++ b/memgpt/memory.py @@ -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": @@ -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": @@ -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( From 0d7f0915850382cd4bd4a0096c55e56ff866a2ac Mon Sep 17 00:00:00 2001 From: cpacker Date: Mon, 27 Nov 2023 15:06:15 -0800 Subject: [PATCH 2/3] remove self value from error message passed to LLM processor --- memgpt/agent.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/memgpt/agent.py b/memgpt/agent.py index 567e440761..046bf7f348 100644 --- a/memgpt/agent.py +++ b/memgpt/agent.py @@ -515,9 +515,11 @@ 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: + function_args.pop("self", None) error_msg = f"Error calling function {function_name} with args {function_args}: {str(e)}" error_msg_user = f"{error_msg}\n{traceback.format_exc()}" printd(error_msg_user) From ef8c046812df72240b534c69c299c7ff8436ba25 Mon Sep 17 00:00:00 2001 From: cpacker Date: Mon, 27 Nov 2023 15:13:09 -0800 Subject: [PATCH 3/3] simplify error message propogated to llm processor --- memgpt/agent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/memgpt/agent.py b/memgpt/agent.py index 046bf7f348..e24bf6e8d7 100644 --- a/memgpt/agent.py +++ b/memgpt/agent.py @@ -520,7 +520,9 @@ def handle_ai_response(self, response_message): function_failed = False except Exception as e: function_args.pop("self", None) - error_msg = f"Error calling function {function_name} with args {function_args}: {str(e)}" + # 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)