Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: passing tests but memory access is weird #1610

Merged
merged 4 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions memgpt/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,21 +813,8 @@ def update_agent(

# update the core memory of the agent
if request.memory:
old_core_memory = self.get_agent_memory(agent_id=request.id)
new_memory_contents = request.memory.to_dict()

# edit memory fields
modified = False
for key, value in new_memory_contents.items():
if value is None:
continue
if key in old_core_memory and old_core_memory[key] != value:
memgpt_agent.memory.memory[key].value = value # update agent memory
modified = True

# If we modified the memory contents, we need to rebuild the memory block inside the system message
if modified:
memgpt_agent.rebuild_memory()
new_memory_contents = {k: v.value for k, v in request.memory.memory.items() if v is not None}
_ = self.update_agent_core_memory(user_id=user_id, agent_id=request.id, new_memory_contents=new_memory_contents)

# update the system prompt
if request.system:
Expand Down Expand Up @@ -1307,7 +1294,7 @@ def update_agent_core_memory(self, user_id: str, agent_id: str, new_memory_conte
# Get the agent object (loaded in memory)
memgpt_agent = self._get_or_load_agent(agent_id=agent_id)

old_core_memory = self.get_agent_memory(agent_id=agent_id)
# old_core_memory = self.get_agent_memory(agent_id=agent_id)

modified = False
for key, value in new_memory_contents.items():
Expand Down
18 changes: 14 additions & 4 deletions tests/test_new_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,20 @@ def test_agent(client):
assert client.get_agent(agent_state_test.id).tools == new_agent_tools

# update agent: memory
# new_memory = ChatMemory(human="My name is Mr Test, 100 percent human.", persona="I am an all-knowing AI.")
# assert new_memory != agent_state.memory
# client.update_agent(agent_state_test.id, memory=new_memory)
# assert client.get_agent(agent_state_test.id).memory == new_memory
new_human = "My name is Mr Test, 100 percent human."
new_persona = "I am an all-knowing AI."
new_memory = ChatMemory(human=new_human, persona=new_persona)

# TODO this needs to be updated to agent_state.memory.memory
# NOTE there is a bug, it should be the uncommented lines
assert agent_state.memory["human"]["value"] != new_human
assert agent_state.memory["persona"]["value"] != new_persona
# assert agent_state.memory["human"].value != new_human
# assert agent_state.memory["persona"].value != new_persona

client.update_agent(agent_state_test.id, memory=new_memory)
assert client.get_agent(agent_state_test.id).memory.memory["human"].value == new_human
assert client.get_agent(agent_state_test.id).memory.memory["persona"].value == new_persona

# update agent: llm config
new_llm_config = agent_state.llm_config.model_copy(deep=True)
Expand Down
Loading