fix(memory): handle block-list content in remove_code_blocks

A custom LangChain LLM passed to AsyncMemory._create_procedural_memory
returns AIMessage.content, which is str | list[str | dict]. Providers
that emit content blocks hit content.strip() on a list and raised
AttributeError.

remove_code_blocks already normalized None, so the list case is handled
in the same guard rather than at the single call site.

Closes #6150
This commit is contained in:
kartik-mem0
2026-08-13 17:23:37 +05:30
parent 96d45b78c7
commit d5b041e942
3 changed files with 63 additions and 4 deletions
+18
View File
@@ -192,3 +192,21 @@ class TestProcessTelemetryFilters:
class TestRemoveCodeBlocks:
def test_none_content_returns_empty_string(self):
assert remove_code_blocks(None) == ""
def test_block_list_content_is_flattened(self):
assert remove_code_blocks([{"type": "text", "text": "step one"}]) == "step one"
def test_block_list_content_strips_code_fences(self):
content = [{"type": "text", "text": '```json\n{"a": 1}\n```'}]
assert remove_code_blocks(content) == '{"a": 1}'
def test_block_list_content_joins_multiple_blocks(self):
content = [{"type": "text", "text": "step one. "}, {"type": "text", "text": "step two"}]
assert remove_code_blocks(content) == "step one. step two"
def test_block_list_content_ignores_non_text_blocks(self):
content = [{"type": "thinking", "thinking": "hmm"}, {"type": "text", "text": "answer"}]
assert remove_code_blocks(content) == "answer"
def test_plain_string_blocks_are_supported(self):
assert remove_code_blocks(["step one. ", "step two"]) == "step one. step two"