mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

parse_vision_messages fails to work correctly when encountering an array content.

Open growmuye opened this issue 2 months ago • 2 comments

🐛 Describe the bug

在非vision模式下,使用AsyncMemory await memory.add(messages) messages内容如下

[ {
  "role" : "user",
  "content" : "你好"
}, {
  "role" : "user",
  "content" : [ {
    "type" : "text",
    "text" : "For context:"
  }, {
    "type" : "text",
    "text" : "xxxxxxx"
  } ]
} ]
Image Image

在openai官网,他可能是个 text array

https://platform.openai.com/docs/api-reference/chat/create

Image

growmuye avatar Oct 22 '25 12:10 growmuye

Hey @growmuye sorry for the trouble caused, can you share when and how exactly this error occurs?

parshvadaftari avatar Oct 22 '25 13:10 parshvadaftari

Cause:

  • The parse_vision_messages function doesn't handle array-type message content (e.g. [{'type': 'text', 'text': ...}] as allowed by OpenAI API). Instead, it expects a simple string, so parsing fails and downstream output files like memories/{idx}.txt are never created.

Solution:

  • Update the parsing logic to flatten/join array-type content into a single string:
if isinstance(content, list):
    content_str = ''.join([ch['text'] for ch in content if 'text' in ch])
else:
    content_str = content
  • After this change, the pipeline should process messages correctly and create the expected files.

Let me know if you want a PR or code sample for the fix!

Anand0295 avatar Oct 31 '25 18:10 Anand0295