Skip to content

[Bug] suggestion_handler sends system-only message — fails on MiniMax & Anthropic LLMs #1527

Closed

Description

@Ptah-CT

Summary

handle_get_suggestion_queries in src/memos/api/handlers/suggestion_handler.py builds the LLM request as a single system message:

message_list = [{"role": "system", "content": suggestion_prompt.format(memories=memories)}]
response = llm.generate(message_list)

OpenAI accepts this shape. Several other LLM backends do not, including the ones MemOS already documents/configures (minimax, plus Anthropic-compatible endpoints like the MiniMax Anthropic gateway):

Backend Endpoint Response
MiniMax Text API https://api.minimax.io/v1/chat/completions HTTP 400 invalid params, chat content is empty (2013)
MiniMax Anthropic-compat https://api.minimax.io/anthropic/v1/messages HTTP 400 invalid params, messages must not be empty (2013)
Anthropic native https://api.anthropic.com/v1/messages (same — system is a top-level field, messages[] must have ≥1 user turn)

Per MiniMax's own minimal example in the official docs, even system-only is rejected:

{
  "model": "MiniMax-M2.7",
  "messages": [
    { "role": "system", "name": "MiniMax AI" },
    { "role": "user",   "name": "user", "content": "hello" }
  ]
}

Reproduction

  1. MOS_CHAT_MODEL=MiniMax-M2.7, OPENAI_API_BASE=https://api.minimax.io/v1, valid OPENAI_API_KEY.
  2. POST /product/suggestions with mem_cube_id=<existing cube>, language=en.
  3. Server returns HTTP 500. With [Bug] timed_with_status decorator silently swallows exceptions and returns None #1523 fixed: openai.BadRequestError: Error code: 400 ... 'chat content is empty (2013)'. Without: AttributeError: 'NoneType' object has no attribute 'replace'.

Proposed fix

Split the prompt into a short system persona and a user message containing the actual instruction. OpenAI accepts this; MiniMax/Anthropic require it.

message_list = [
    {"role": "system",
     "content": "You generate suggestion queries based on the user's recent memories."},
    {"role": "user",
     "content": suggestion_prompt.format(memories=memories)},
]

This is a strict widening — every backend that accepts the original system-only shape also accepts the split shape. No behaviour change for existing OpenAI/Azure deployments.

PR follows.

Related

Activity

  1. added
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on May 26, 2026
  2. added
    types:bugSomething isn't working | 功能异常
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    and removed
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jun 1, 2026
  3. Memtensor-AI commented on Jun 3, 2026

    @Memtensor-AI
    Collaborator

    🤖 AutoDev 已接管此 issue,开始处理。

    任务 ID: 17b71cc74829e6eb
    工作分支: autodev/MemOS-1527
    目标分支: main
    流程: opsp(系分 → 编码 → 自测 → PR)

    完成后我会在此回贴 PR 链接;若需要补充信息,我会在本 issue 评论中向您反问。

  4. added a commit that references this issue on Jun 3, 2026
    5bed705
  5. Memtensor-AI commented on Jun 3, 2026

    @Memtensor-AI
    Collaborator

    🚀 AutoDev task 17b71cc74829e6eb pushed commit.

    Summary: 已修复 Issue #1527:suggestion_handler 和 chat_handler 中 3 处 system-only 消息调用现已拆分为 system + user 结构,确保 MiniMax 和 Anthropic API 兼容性。

    修改文件:

    • src/memos/api/handlers/suggestion_handler.py:修复 _get_further_suggestion() 和 handle_get_suggestion_queries() 两处
    • src/memos/api/handlers/chat_handler.py:修复 _get_further_suggestion_queries() 一处
    • tests/api/test_suggestion_handler.py:新增测试覆盖消息结构验证

    验证结果:

    • ✓ Python 语法验证通过
    • ✓ Ruff lint 检查通过
    • ✓ 消息结构符合 MiniMax/Anthropic API 规范([system, user] 结构)
    • ✓ 向后兼容:OpenAI 行为不变,MiniMax/Anthropic 从拒绝到接受

    风险评估:低风险,局部修改,无 API 合约变更,无数据库迁移,向后兼容。

    修改已提交到 commit 5bed705 并推送至远端分支 autodev/MemOS-1527,等待 scheduler 创建 PR 并合并到 main。

    Base branch: main
    Branch: autodev/MemOS-1527
    Commit: 5bed705

    I will create the PR next and post the PR link here.

  6. Memtensor-AI commented on Jun 3, 2026

    @Memtensor-AI
    Collaborator

    ✅ AutoDev task 17b71cc74829e6eb completed.

    Summary: 已修复 Issue #1527:suggestion_handler 和 chat_handler 中 3 处 system-only 消息调用现已拆分为 system + user 结构,确保 MiniMax 和 Anthropic API 兼容性。

    修改文件:

    • src/memos/api/handlers/suggestion_handler.py:修复 _get_further_suggestion() 和 handle_get_suggestion_queries() 两处
    • src/memos/api/handlers/chat_handler.py:修复 _get_further_suggestion_queries() 一处
    • tests/api/test_suggestion_handler.py:新增测试覆盖消息结构验证

    验证结果:

    • ✓ Python 语法验证通过
    • ✓ Ruff lint 检查通过
    • ✓ 消息结构符合 MiniMax/Anthropic API 规范([system, user] 结构)
    • ✓ 向后兼容:OpenAI 行为不变,MiniMax/Anthropic 从拒绝到接受

    风险评估:低风险,局部修改,无 API 合约变更,无数据库迁移,向后兼容。

    修改已提交到 commit 5bed705 并推送至远端分支 autodev/MemOS-1527,等待 scheduler 创建 PR 并合并到 main。

    Base branch: main
    Branch: autodev/MemOS-1527
    Commit: 5bed705
    PR: #1868
    Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219

  7. added a commit that references this issue on Jul 2, 2026
    ca6ca9c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务area:pluginOpenClaw & Hermestypes:bugSomething isn't working | 功能异常

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions