fix: add serialization-safe agent_id and to_dict() to MemoryEntry (#156)#256
fix: add serialization-safe agent_id and to_dict() to MemoryEntry (#156)#256
Conversation
…sa#156) MemoryEntry stores a direct reference to LLMAgent objects, which causes JSON serialization errors when memory entries need to be serialized (e.g., for logging, export, or LLM context construction). Changes: - Added agent_id field to MemoryEntry that auto-populates from agent.unique_id - Added to_dict() method returning a JSON-serializable representation - Backwards compatible: agent field unchanged, agent_id has default None Fixes mesa#156
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can use your project's `ruff` configuration to improve the quality of Python code reviews.Add a Ruff configuration file to your project to customize how CodeRabbit runs |
IlamaranMagesh
left a comment
There was a problem hiding this comment.
Coul you please elaborate what's the issue here? I see the issue #156 is already closed and it has some fixes on JSON serialisation error.
Hi @IlamaranMagesh , thanks for the review! You're right that #156 was closed, but looking at the fix that was merged, it addressed the send_message/asend_message methods specifically. |
|
Closing because #156 was already fixed, and this PR does not address that code path. Making |
Summary
Fixes #156 — MemoryEntry stores a direct LLMAgent object reference in its agent field, which causes TypeError: Object of type LLMAgent is not JSON serializable when memory entries are serialized.
Root Cause
The MemoryEntry dataclass (in mesa_llm/memory/memory.py) has agent: "LLMAgent" as a field. Every memory module (st_memory, lt_memory, st_lt_memory, episodic_memory) creates entries with agent=self.agent, embedding the full Agent object. Any downstream code that attempts json.dumps() on a MemoryEntry or its fields fails.
Changes
Testing
Existing tests unaffected — change is purely additive (new field with default + new method).
Context
I'm a GSoC 2026 candidate working on the Mesa-LLM stabilization project proposal. This is one of the critical issues I identified for Phase 1.