refactor: change 'string' name to 'compile'

This commit is contained in:
cpacker
2024-08-26 16:39:47 -07:00
parent 8221693890
commit 6f6d1346d9
4 changed files with 8 additions and 8 deletions

View File

@@ -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

View File

@@ -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</{section}>')

View File

@@ -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"])

View File

@@ -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)