fix: render readable text in get_communication_history for all memory…#194
fix: render readable text in get_communication_history for all memory…#194
Conversation
|
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)
📝 Coding Plan for PR comments
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 |
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #194 +/- ##
==========================================
+ Coverage 90.64% 90.69% +0.04%
==========================================
Files 19 19
Lines 1540 1548 +8
==========================================
+ Hits 1396 1404 +8
Misses 144 144 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #193
Summary
get_communication_history()in all three memory classes (ShortTermMemory,STLTMemory,EpisodicMemory) was rendering raw Python dicts instead of readable message strings in the LLM prompt_format_message_entry()helper inmemory.pythat extracts human-readable text from the nested dict structure produced byspeak_toRoot Cause
The
speak_totool stores messages as a nested dict:This means
entry.content["message"]is always a dict, not a string. Butget_communication_history()passed it directly into the f-string:This garbled output was injected into the ReAct reasoning prompt on every step where agents had exchanged messages, silently corrupting the LLM's view of inter-agent communication.
Changes
mesa_llm/memory/memory.py_format_message_entry(msg_value) -> strhelper that renders{"message": "...", "sender": 42, ...}as"Agent 42 says: ...", with a plain-string passthrough for backward compatibilitymesa_llm/memory/episodic_memory.py,st_lt_memory.py,st_memory.pyget_communication_history()in all three to use_format_message_entry()instead of raw f-string interpolationTests
TestFormatMessageEntry(5 tests) intest_memory_parent.py— unit tests for the helper covering: nested dict with sender, without sender, plain string passthrough, missing message key fallback, and EpisodicMemory's importance-augmented payloadtest_get_communication_history_nested_dictadded to all three memory test files — reproduces the realspeak_topayload structure and asserts readable outputtest_get_communication_history_skips_non_message_entriesadded to all three — asserts non-message entries are correctly excludedtest_get_communication_history_returns_empty_string_when_no_messagesadded toSTLTMemoryandShortTermMemoryBefore / After