Skip to content

EpisodicMemory: Graded entries are never stored, as a result LLM never receives memory context #108

@psbuilds

Description

@psbuilds

Describe the bug
EpisodicMemory has an add_to_memory() function that grades each event's importance, but the graded content is never stored as a MemoryEntry in self.memory_entries.

The grading result is placed into self.step_content (via super().add_to_memory()), which is then immediately cleared in process_step.

As a result, memory_entries is always empty, retrieve_top_k_entries() returns nothing, and get_prompt_ready() provides no memory context to the LLM during reasoning.

Expected behavior

After calling add_to_memory(), the graded event should be stored as a MemoryEntry in self.memory_entries so that:

  • retrieve_top_k_entries() can retrieve the most important + recent memories
  • get_prompt_ready() returns meaningful context to the LLM during reasoning

To Reproduce

from unittest.mock import MagicMock
from mesa_llm.memory.episodic_memory import EpisodicMemory
import json

agent = MagicMock()
agent.model.steps = 1
mock_response = MagicMock()
mock_response.choices[0].message.content = json.dumps({"grade": 4})
agent.llm.generate.return_value = mock_response

memory = EpisodicMemory(agent=agent, llm_model="provider/test_model")

# Add a graded memory
memory.add_to_memory("observation", {"data": "saw 3 cops nearby"})

# Bug: memory_entries is empty even after adding a graded event
print(len(memory.memory_entries))  # → 0 (expected: 1)
print(memory.get_prompt_ready())   # → "Top 5 memory entries:\n\n" (no actual entries)

Additional context
I was initially going through the logic for grading in episodic_memory which also seems to be flawed when a lot of steps are involved in the agents simulation.

Due to the lack of normalisation over long simulations the grading logic seems to give more weight to recency rather than the other two factors, when in reality according to the research paper mentioned in the file all the factors must be given equal weight.

But this can be tackled only after fixing the bug mentioned in this issue as without entires to grade and supply to the LLM properly episodic_memory file doesn't make sense.

If I am wrong in my interpretation please do help me to understand where I went wrong in interpreting this. :)

I'm currently working on a PR for this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelease notes label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions