MemOS icon indicating copy to clipboard operation
MemOS copied to clipboard

fix: Anthropic API 端点被错误规范化为 OpenAI 格式,导致技能演化失败

Open starm0on opened this issue 8 months ago • 2 comments

Pre-submission checklist | 提交前检查

  • [x] I have searched existing issues and this hasn't been mentioned before | 我已搜索现有问题,确认此问题尚未被提及
  • [x] I have read the project documentation and confirmed this issue doesn't already exist | 我已阅读项目文档并确认此问题尚未存在
  • [x] This issue is specific to MemOS and not a general software issue | 该问题是针对 MemOS 的,而不是一般软件问题

Bug Description | 问题描述

在使用 Anthropic(或兼容 Anthropic 的)API 进行技能演化时,已配置的端点 URL 会被错误地追加 /chat/completions,从而导致 404 错误。仪表盘中的“Test Connection(测试连接)”按钮显示成功,但实际的技能演化会静默失败。此外,仪表盘还会显示误导性的技能计数(显示为 37,但实际为 0)。

How to Reproduce | 如何重现

详细测试过程与分析

阶段 1:初始配置与测试

步骤 1:在仪表盘中配置 Skill Evolution

  • 进入 Dashboard → Settings → Skill Evolution

  • 将 Provider 设置为:anthropic

  • 将 Endpoint 设置为:https://api.aihubmix.com/v1/messages

  • 将 Model 设置为:claude-sonnet-4-6-think

  • 填入有效的 API Key

步骤 2:测试连接

  • 点击“Test Connection”按钮

  • 结果:✅ 连接成功

  • 仪表盘显示绿色状态指示

步骤 3:运行后处理

  • 进入 Import → Post-process

  • 选择 “Generate Tasks & Skills”

  • 启用 “Trigger task summarization” 和 “Trigger skill evolution”

  • 开始处理

阶段 2:观察失败现象

处理过程中仪表盘显示:

 Processing... (Tasks: 38, Skills: 37, Errors: 0)

处理完成后数据库实际状态:

 -- 检查 tasks 表
 SELECT skill_status, COUNT(*) as count
 FROM tasks
 WHERE status='completed'
 GROUP BY skill_status;
 ​
 -- 结果:
 -- not_generated | 31
 -- skipped       | 7
 -- (NULL)       | 0
 ​
 -- 检查 skills 表
 SELECT COUNT(*) FROM skills;
 -- 结果:0
 ​
 -- 检查 skill_versions 表
 SELECT COUNT(*) FROM skill_versions;
 -- 结果:0
 ​
 -- 检查 skills-store 目录
 ls -la ~/.openclaw/skills-store/
 -- 结果:空目录

任务详情(失败任务样例):

 SELECT id, title, skill_status, skill_reason 
 FROM tasks
 WHERE skill_status = 'not_generated'
 LIMIT 5;
id | title | skill_status | skill_reason -- | -- | -- | -- fa976966-... | OpenClaw MemOS 插件 + Kimi Code 接入问题诊断 | not_generated | error: Error: LLM call failed (404): {"error":{"message":"The requested resource was not found","type":"resource_not_found_error"}} f6094356-... | 请用中文介绍一下你现在的默认工作方式。 | not_generated | error: Error: LLM call failed (404)... 3105e143-... | System: [2026-03-15 00:30:35 GMT+8] Feishu... | not_generated | error: Error: LLM call failed (404)... ... | ... | ... | ...

用户体验影响:

  1. 静默失败:测试通过,但实际功能失败

  2. 误导性指标:仪表盘显示成功,实际上却失败

  3. 浪费处理时间:用户以为技能正在生成,实际上没有任何结果

  4. 调试困难:UI 中没有明显报错,必须检查数据库或日志才能发现问题


源码验证

已在 main 分支确认

仓库: https://github.com/MemTensor/MemOS分支: main路径: apps/memos-local-openclaw/src/shared/llm-call.ts

 // 第 65-72 行(当前 main 分支)
 function normalizeEndpoint(url: string): string {
   const stripped = url.replace(/\/+$/, "");
   if (stripped.endsWith("/chat/completions")) return stripped;
   if (stripped.endsWith("/completions")) return stripped;
   return `${stripped}/chat/completions`;
 }
 ​
 // 第 78-95 行(当前 main 分支)
 export async function callLLMOnce(...): Promise<string> {
   const endpoint = normalizeEndpoint(cfg.endpoint ?? "...");
   // ... 始终按 OpenAI 格式处理
   const headers: Record<string, string> = {
     "Content-Type": "application/json",
     Authorization: `Bearer ${cfg.apiKey}`,  // 没有针对 provider 做特殊处理
     ...cfg.headers,
  };
   // ...
   const json = (await resp.json()) as { choices: Array<{ message: { content: string } }> };
   return json.choices[0]?.message?.content?.trim() ?? "";
 }

缺失的 Provider 检测:callLLMOnce 函数没有检查 cfg.provider,来决定端点格式、鉴权头或响应解析方式。它对所有情况都假定为 OpenAI 兼容格式。

Environment | 环境信息

  • 插件:@memtensor/memos-local-openclaw-plugin(main 分支最新版本)

  • 源码仓库:https://github.com/MemTensor/MemOS/tree/main/apps/memos-local-openclaw

  • 操作系统:Linux(Ubuntu 22.04)

  • Node.js:20.x

  • 安装路径:~/.openclaw/extensions/memos-local-openclaw-plugin

Additional Context | 其他信息

使用的配置

{
  "plugins": {
    "entries": {
      "memos-local-openclaw-plugin": {
        "enabled": true,
        "config": {
          "skillEvolution": {
            "enabled": true,
            "autoInstall": true,
            "minConfidence": 0.8,
            "minChunksForEval": 6,
            "summarizer": {
              "provider": "anthropic",
              "model": "claude-sonnet-4-6-think",
              "endpoint": "https://api.aihubmix.com/v1/messages",
              "apiKey": "sk-xxx"
            }
          }
        }
      }
    }
  }
}

Willingness to Implement | 实现意愿

  • [x] I'm willing to implement this myself | 我愿意自己解决
  • [ ] I would like someone else to implement this | 我希望其他人来解决

starm0on avatar Mar 17 '26 06:03 starm0on

PR submitted: #1263

已提交 PR:#1263。问题原因:loadOpenClawFallbackConfig() 始终将 provider 设为 openai_compatible 并追加 /chat/completions,导致 Anthropic 端点被错误规范化。修复后根据 provider key 或 baseUrl 自动识别 Anthropic/Bedrock/OpenAI,使用正确的端点格式。

hijzy avatar Mar 17 '26 10:03 hijzy

Hey @starm0on! Thanks for the contribution — already solved the issue, thanks for helping us to catch the bug! 🐞

Btw if you enjoyed contributing and want to stay connected with the project, we run a Discord server for contributors, a chill space to discuss features, ask questions, or pick up new issues  👉🏻 MemOS Discord Server (Contributor Exclusive)

Thanks again for shipping this, and happy MemOSing 🧠✨

angarchie avatar May 19 '26 13:05 angarchie