From aa3e37ac149cb9789d2331016a30b13bf89fcd75 Mon Sep 17 00:00:00 2001 From: merwanehamadi Date: Fri, 28 Apr 2023 13:07:49 -0700 Subject: [PATCH] Fix memory by adding it only when context window full (#3469) * Fix memory by adding it only when context window full * clean json utils --- autogpt/agent/agent.py | 11 +- autogpt/json_utils/utilities.py | 32 +- autogpt/llm/chat.py | 8 + autogpt/memory_management/store_memory.py | 33 ++ ...ve_memory_trimmed_from_context_window.yaml | 335 ++++++++++++++++++ tests/integration/test_memory_management.py | 64 ++++ 6 files changed, 471 insertions(+), 12 deletions(-) create mode 100644 autogpt/memory_management/store_memory.py create mode 100644 tests/integration/cassettes/test_memory_management/test_save_memory_trimmed_from_context_window.yaml create mode 100644 tests/integration/test_memory_management.py diff --git a/autogpt/agent/agent.py b/autogpt/agent/agent.py index 9e0f54e36..a049b9d2f 100644 --- a/autogpt/agent/agent.py +++ b/autogpt/agent/agent.py @@ -3,7 +3,7 @@ from colorama import Fore, Style from autogpt.app import execute_command, get_command from autogpt.config import Config from autogpt.json_utils.json_fix_llm import fix_json_using_multiple_techniques -from autogpt.json_utils.utilities import validate_json +from autogpt.json_utils.utilities import LLM_DEFAULT_RESPONSE_FORMAT, validate_json from autogpt.llm import chat_with_ai, create_chat_completion, create_chat_message from autogpt.logs import logger, print_assistant_thoughts from autogpt.speech import say_text @@ -107,7 +107,7 @@ class Agent: # Print Assistant thoughts if assistant_reply_json != {}: - validate_json(assistant_reply_json, "llm_response_format_1") + validate_json(assistant_reply_json, LLM_DEFAULT_RESPONSE_FORMAT) # Get command name and arguments try: print_assistant_thoughts( @@ -251,13 +251,6 @@ class Agent: result = plugin.post_command(command_name, result) if self.next_action_count > 0: self.next_action_count -= 1 - memory_to_add = ( - f"Assistant Reply: {assistant_reply} " - f"\nResult: {result} " - f"\nHuman Feedback: {user_input} " - ) - - self.memory.add(memory_to_add) # Check if there's a result from the command append it to the message # history diff --git a/autogpt/json_utils/utilities.py b/autogpt/json_utils/utilities.py index eb9bb6877..fa604a422 100644 --- a/autogpt/json_utils/utilities.py +++ b/autogpt/json_utils/utilities.py @@ -8,6 +8,7 @@ from autogpt.config import Config from autogpt.logs import logger CFG = Config() +LLM_DEFAULT_RESPONSE_FORMAT = "llm_response_format_1" def extract_char_position(error_message: str) -> int: @@ -28,10 +29,10 @@ def extract_char_position(error_message: str) -> int: raise ValueError("Character position not found in the error message.") -def validate_json(json_object: object, schema_name: object) -> object: +def validate_json(json_object: object, schema_name: str) -> dict | None: """ :type schema_name: object - :param schema_name: + :param schema_name: str :type json_object: object """ with open(f"autogpt/json_utils/{schema_name}.json", "r") as f: @@ -48,7 +49,32 @@ def validate_json(json_object: object, schema_name: object) -> object: for error in errors: logger.error(f"Error: {error.message}") - elif CFG.debug_mode: + return None + if CFG.debug_mode: print("The JSON object is valid.") return json_object + + +def validate_json_string(json_string: str, schema_name: str) -> dict | None: + """ + :type schema_name: object + :param schema_name: str + :type json_object: object + """ + + try: + json_loaded = json.loads(json_string) + return validate_json(json_loaded, schema_name) + except: + return None + + +def is_string_valid_json(json_string: str, schema_name: str) -> bool: + """ + :type schema_name: object + :param schema_name: str + :type json_object: object + """ + + return validate_json_string(json_string, schema_name) is not None diff --git a/autogpt/llm/chat.py b/autogpt/llm/chat.py index 9bfd37e02..119468c39 100644 --- a/autogpt/llm/chat.py +++ b/autogpt/llm/chat.py @@ -8,6 +8,9 @@ from autogpt.llm.api_manager import ApiManager from autogpt.llm.llm_utils import create_chat_completion from autogpt.llm.token_counter import count_message_tokens from autogpt.logs import logger +from autogpt.memory_management.store_memory import ( + save_memory_trimmed_from_context_window, +) from autogpt.types.openai import Message cfg = Config() @@ -124,6 +127,11 @@ def chat_with_ai( tokens_to_add = count_message_tokens([message_to_add], model) if current_tokens_used + tokens_to_add > send_token_limit: + save_memory_trimmed_from_context_window( + full_message_history, + next_message_to_add_index, + permanent_memory, + ) break # Add the most recent message to the start of the current context, diff --git a/autogpt/memory_management/store_memory.py b/autogpt/memory_management/store_memory.py new file mode 100644 index 000000000..e37434ef5 --- /dev/null +++ b/autogpt/memory_management/store_memory.py @@ -0,0 +1,33 @@ +from autogpt.json_utils.utilities import ( + LLM_DEFAULT_RESPONSE_FORMAT, + is_string_valid_json, +) +from autogpt.logs import logger + + +def format_memory(assistant_reply, next_message_content): + # the next_message_content is a variable to stores either the user_input or the command following the assistant_reply + result = ( + "None" if next_message_content.startswith("Command") else next_message_content + ) + user_input = ( + "None" + if next_message_content.startswith("Human feedback") + else next_message_content + ) + + return f"Assistant Reply: {assistant_reply}\nResult: {result}\nHuman Feedback:{user_input}" + + +def save_memory_trimmed_from_context_window( + full_message_history, next_message_to_add_index, permanent_memory +): + while next_message_to_add_index >= 0: + message_content = full_message_history[next_message_to_add_index]["content"] + if is_string_valid_json(message_content, LLM_DEFAULT_RESPONSE_FORMAT): + next_message = full_message_history[next_message_to_add_index + 1] + memory_to_add = format_memory(message_content, next_message["content"]) + logger.debug(f"Storing the following memory: {memory_to_add}") + permanent_memory.add(memory_to_add) + + next_message_to_add_index -= 1 diff --git a/tests/integration/cassettes/test_memory_management/test_save_memory_trimmed_from_context_window.yaml b/tests/integration/cassettes/test_memory_management/test_save_memory_trimmed_from_context_window.yaml new file mode 100644 index 000000000..1ad25810a --- /dev/null +++ b/tests/integration/cassettes/test_memory_management/test_save_memory_trimmed_from_context_window.yaml @@ -0,0 +1,335 @@ +interactions: +- request: + body: '{"input": ["Assistant Reply: { \"thoughts\": { \"text\": Result: + None Human Feedback: Command Result: Important Information. "], "model": "text-embedding-ada-002", + "encoding_format": "base64"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '207' + Content-Type: + - application/json + method: POST + uri: https://api.openai.com/v1/embeddings + response: + body: + string: !!binary | + H4sIAAAAAAAAA1SaW8+6Srfl799PsbJu7TciIjVZd5xEjlUIHrDT6QAqCiJyqAJqZ3/3jv53dnff + eIEkj0/VrDnGb8z6j3/99dffTVbe8uHvf/76+/Xsh7//x/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1NXz5C7rx9M2vL5njce3cJnWMx + IVZA83ICPtm//PpP/Q4uzUwQ3n1IjFiZ42YLnQVjX6cYeq8s+WQkPZCg7pndshdiYXtZyMFlnqmw + O9+733xMth4njWkrLSlHJ5F6UC4K4I9uFRm/M3dEW34diaEnpiGuUSHBd/5K7JcR8Dk59hEs9/2d + 5f2WlUMuZDc4QJEzA1/1uDNn3//l5Rg1deUNVvwskIMuV6KfR8MTv/O8zd47ELbLuz4bFzftpIi3 + o47F7aqOx3E6POXvvIqEr3PK2+SZj3CyUkoC93nz6LQPRDiVxZ0uLpcLGpf6SoIv/9P5ez7nxflh + wdBRi5k3ARv0PlUp1PYiJ1vnWXp85LWtvEl8xHM0Xbyh2woC2r9ZQZVVGHvz2U1GtFwIhHkdf/DB + 3pIa+gZvMcu9dTYt1TyEn17+8qEJK5K7iZ8R+tPfuKfFMvz0fOvkzODtXKnyenkyv37hU/YfV5WV + qKum7zyDGONGPc1IuSyBGTmq0Ri/Zwn2Uq4SbZneuj96uj4aPp3PY+kxK7mOaDhA/csb4vG5yTHo + fZ3he77vYr5V7hSybNyy++l+99jFfPfIyw3CtHfuev2cFpby9+9WwH/+66+//tfvhkHdXG+v78WA + 4TYN//7vqwL/Tq/pvwVB/DcT/9xEoH1a3P7+578uIfz96Zr6M/zvoalu7/7vf/4SlT/XDf4emiF9 + /b/P//X9a//5r/8DAAD//wMAaBDGhuMgAAA= + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 7bf024783c8096de-SJC + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json + Date: + - Fri, 28 Apr 2023 14:54:47 GMT + Server: + - cloudflare + access-control-allow-origin: + - '*' + alt-svc: + - h3=":443"; ma=86400, h3-29=":443"; ma=86400 + openai-organization: + - user-adtx4fhfg1qsiyzdoaxciooj + openai-processing-ms: + - '325' + openai-version: + - '2020-10-01' + strict-transport-security: + - max-age=15724800; includeSubDomains + x-ratelimit-limit-requests: + - '3000' + x-ratelimit-remaining-requests: + - '2999' + x-ratelimit-reset-requests: + - 20ms + x-request-id: + - f59ce3c6f76fb37599125046aec3d2bb + status: + code: 200 + message: OK +- request: + body: '{"input": ["Important Information"], "model": "text-embedding-ada-002", + "encoding_format": "base64"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '100' + Content-Type: + - application/json + method: POST + uri: https://api.openai.com/v1/embeddings + response: + body: + string: !!binary | + H4sIAAAAAAAAA1SaW8+6Srfl799PsbJu7TciCjVZdwjI2SoEj51OR0QREDlWAbWzv3sH/zu7u2+e + RCB5lJo15viNWf/xr7/++ruK8+ej//ufv/7+ZF3/9/+YryX3/v73P3/9z3/99ddff/3H7+//9+Sz + jJ9Jkn3T3+O/m9k3eY5///OX8N9X/u9D//z1N7ldGbNR1kfT59Co6Mw2K/aiVIi5YisGtOPUMVc/ + L9re624DJJoVM7PigS5k25cPVXN7MDsSyvbbeMOAFt0tZSRIHC4+lqELC7w4EyLkQtT7lXUGOVv4 + xP6aWj52jb5AVWAsmZY3H0Sr5pvJ3tn4sEc2Bfm0J7cMHo67IOq27vK+rnMT1MzcMUfRtvqg6h8N + neTdjm3dzTmezPutAtE+a8zpTl0+tXmwQGccXom7e9hxzz/GhBJtFxP7GR/ygdlYle8eUunickmi + US+7DkY/14n9El2PVpWkwUtRLlR+oi8atsc7hr47fYjrGEU+7dKwBOXerPD4dMN4bJMaQ4iMB9mb + m1gf40wI0CpbypSHFxSxaJpMFGYhJkTCu0jAbizA/dgTsn1POGdT4z7lNQ1Vtg9jFQ1ws314R+iM + uTUE8/pkmpwddJPpWvlup6phKZhH+0FcY0v4dE2eMvpe7IxoFwYxvSZnGazE3ODNEK50Zp8WGjpM + tkp2+15DvEpQAXW9jZkG6UYf3ru6QivPD/ellBr5NGy3AuyJR+jXMuS2t95+Awd4Jsw5Xl95Hwbd + E+KbOhDte3t443FRl0jp+RsPxKxaOhYhheubMyqHkhEJweK2kXUVUmYa/a4dJyT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AwBim/ij4SAAAA== + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 7bf0247aaeea96de-SJC + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json + Date: + - Fri, 28 Apr 2023 14:54:47 GMT + Server: + - cloudflare + access-control-allow-origin: + - '*' + alt-svc: + - h3=":443"; ma=86400, h3-29=":443"; ma=86400 + openai-organization: + - user-adtx4fhfg1qsiyzdoaxciooj + openai-processing-ms: + - '63' + openai-version: + - '2020-10-01' + strict-transport-security: + - max-age=15724800; includeSubDomains + x-ratelimit-limit-requests: + - '3000' + x-ratelimit-remaining-requests: + - '2999' + x-ratelimit-reset-requests: + - 20ms + x-request-id: + - 974557ca996688f2b7e568f6d601ad88 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/integration/test_memory_management.py b/tests/integration/test_memory_management.py new file mode 100644 index 000000000..c9ab9fc94 --- /dev/null +++ b/tests/integration/test_memory_management.py @@ -0,0 +1,64 @@ +import json + +import pytest + +from autogpt.config import Config +from autogpt.memory import get_memory +from autogpt.memory_management.store_memory import ( + save_memory_trimmed_from_context_window, +) +from tests.utils import requires_api_key + + +@pytest.fixture +def message_history_fixture(): + assistant_reply = { + "thoughts": { + "text": "thoughts", + "reasoning": "reasoning", + "plan": "plan", + "criticism": "criticism", + "speak": "speak", + }, + "command": {"name": "google", "args": {"query": "google_query"}}, + } + return [ + {"content": json.dumps(assistant_reply, indent=4)}, + {"content": "Command Result: Important Information."}, + ] + + +@pytest.fixture +def expected_permanent_memory() -> str: + return """Assistant Reply: { + "thoughts": { + "text": "thoughts", + "reasoning": "reasoning", + "plan": "plan", + "criticism": "criticism", + "speak": "speak" + }, + "command": { + "name": "google", + "args": { + "query": "google_query" + } + } +} +Result: None +Human Feedback:Command Result: Important Information.""" + + +@requires_api_key("OPENAI_API_KEY") +@pytest.mark.vcr +def test_save_memory_trimmed_from_context_window( + message_history_fixture, expected_permanent_memory, config: Config +): + next_message_to_add_index = len(message_history_fixture) - 1 + memory = get_memory(config, init=True) + save_memory_trimmed_from_context_window( + message_history_fixture, next_message_to_add_index, memory + ) + + memory_found = memory.get_relevant("Important Information", 5) + assert memory_found[0] == expected_permanent_memory