From 6f6d1346d9ac683e5ae53a769e3c4bb166ebebb7 Mon Sep 17 00:00:00 2001 From: cpacker Date: Mon, 26 Aug 2024 16:39:47 -0700 Subject: [PATCH] refactor: change 'string' name to 'compile' --- memgpt/agent.py | 6 +++--- memgpt/schemas/memory.py | 6 +++--- tests/test_client.py | 2 +- tests/test_tools.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/memgpt/agent.py b/memgpt/agent.py index 83e56970..b11497a2 100644 --- a/memgpt/agent.py +++ b/memgpt/agent.py @@ -107,7 +107,7 @@ def compile_system_message( archival_memory=archival_memory, recall_memory=recall_memory, ) - full_memory_string = memory_metadata_string + "\n" + in_context_memory.string() + full_memory_string = memory_metadata_string + "\n" + in_context_memory.compile() # Add to the variables list to inject variables[IN_CONTEXT_MEMORY_KEYWORD] = full_memory_string @@ -216,7 +216,7 @@ class Agent(object): # Initialize the memory object self.memory = self.agent_state.memory assert isinstance(self.memory, Memory), f"Memory object is not of type Memory: {type(self.memory)}" - printd("Initialized memory object", self.memory.string()) + printd("Initialized memory object", self.memory.compile()) # Interface must implement: # - internal_monologue @@ -992,7 +992,7 @@ class Agent(object): curr_system_message = self.messages[0] # this is the system + memory bank, not just the system prompt # NOTE: This is a hacky way to check if the memory has changed - memory_repr = self.memory.string() + memory_repr = self.memory.compile() if not force and memory_repr == curr_system_message["content"][-(len(memory_repr)) :]: printd(f"Memory has not changed, not rebuilding system") return diff --git a/memgpt/schemas/memory.py b/memgpt/schemas/memory.py index 4709f436..e81692ce 100644 --- a/memgpt/schemas/memory.py +++ b/memgpt/schemas/memory.py @@ -20,10 +20,10 @@ class Memory(BaseModel, validate_assignment=True): return obj def __str__(self) -> str: - raise NotImplementedError("Use the .string() method instead") + raise NotImplementedError("Use the .compile() method instead") - def string(self) -> str: - """Representation of the memory in-context""" + def compile(self) -> str: + """Generate a string representation of the memory in-context""" section_strs = [] for section, module in self.memory.items(): section_strs.append(f'<{section} characters="{len(module)}/{module.limit}">\n{module.value}\n') diff --git a/tests/test_client.py b/tests/test_client.py index 20fc5d04..fb168046 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -104,7 +104,7 @@ def test_memory(client, agent): # _reset_config() memory_response = client.get_in_context_memory(agent_id=agent.id) - print("MEMORY", memory_response.string()) + print("MEMORY", memory_response.compile()) updated_memory = {"human": "Updated human memory", "persona": "Updated persona memory"} client.update_in_context_memory(agent_id=agent.id, section="human", value=updated_memory["human"]) diff --git a/tests/test_tools.py b/tests/test_tools.py index ae251680..8bcc0b21 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -173,7 +173,7 @@ def test_create_agent_tool(client): # initial memory initial_memory = client.get_in_context_memory(agent.id) - print("initial memory", initial_memory.string()) + print("initial memory", initial_memory.compile()) human = initial_memory.get_block("human") persona = initial_memory.get_block("persona") print("Initial memory:", human, persona)