memU icon indicating copy to clipboard operation
memU copied to clipboard

`cluster_memories` always fails

Open BritishTeapot opened this issue 4 months ago • 1 comments

Whenever an agent calls cluster_memories is called, an error is thrown:

2025-08-16 15:26:40 | memu.memory.memory_agent:445 | ERROR | Function call failed: cluster_memories - KeyError('router troubleshooting')
Traceback (most recent call last):
  File "/app/memu/memory/memory_agent.py", line 433, in call_function
    result = action.execute(**arguments)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/memu/memory/actions/cluster_memories.py", line 83, in execute
    new_clusters = self._detect_new_clusters(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/memu/memory/actions/cluster_memories.py", line 280, in _detect_new_clusters
    new_clusters[cluster].append(memory_id)
    ~~~~~~~~~~~~^^^^^^^^^
KeyError: 'router troubleshooting'

From what I can see, it prevents memories from being retrieved, as the quality of retrieval is supbar so far. That said, I am not 100% sure if this actually causes practical issue, but it may be a hint to a larger issue.

BritishTeapot avatar Aug 16 '25 15:08 BritishTeapot

I wish i could tacke the issue, but I can't understand what's the intent behind the code that causes the problem.

(memu/memory/actions/cluster_memories.py:280)


        new_clusters = {}

        for line in response.split("\n"):
            if not line.startswith("- "):
                continue

            cluster, memory_ids = line[2:].split(": ", 1)
            cluster = cluster.strip().lower()

            if cluster not in self.memory_types["cluster"]:
                new_clusters[cluster] = []
                self.storage_manager.create_cluster_category(cluster)

            for memory_id in memory_ids.split(","):
                memory_id = memory_id.strip()
                if memory_id not in all_items:
                    continue
                self.storage_manager.append_memory_file(cluster, self._format_memory_item(all_items[memory_id]))

                new_clusters[cluster].append(memory_id)

It seems that new_clusters is intialised as empty before the for loop, but is only filled with KV pairs on L271 (new_clusters[cluster] = []). If L271 isn't hit, L280 causes the error as the key cluster never had a chance to be initalised.

BritishTeapot avatar Aug 16 '25 15:08 BritishTeapot