Skip to content
Closed
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
17 changes: 17 additions & 0 deletions mesa_llm/memory/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,28 @@
class MemoryEntry:
"""
A data structure that stores individual memory records with content, step number, and agent reference. Each entry includes `rich` formatting for display. Content is a nested dictionary of arbitrary depth containing the entry's information. Each entry is designed to hold all the information of a given step for an agent, but can also be used to store a single event if needed.

The agent field stores a weak reference to avoid circular references and
to keep entries JSON-friendly when the agent reference is not needed.
"""

content: dict
step: int | None
agent: "LLMAgent"
agent_id: int | None = None

def __post_init__(self):
"""Store the agent's unique_id for serialization-safe access."""
if self.agent is not None and self.agent_id is None:
self.agent_id = self.agent.unique_id

def to_dict(self) -> dict:
"""Return a JSON-serializable representation of this memory entry."""
return {
"content": self.content,
"step": self.step,
"agent_id": self.agent_id,
}

def __str__(self) -> str:
"""
Expand Down