[P1/高] Agnes Adapter 多模态索引映射在 system 消息存在时错位 #28

Open
opened 2026-07-21 21:55:55 +08:00 by thzxx · 0 comments
Owner

问题类型

缺陷 / 高 / LLM 适配器

文件位置

electron/harness/adapters/agnes-ai.adapter.ts

问题描述

Agnes Adapter 使用独立的 multimodalIndex 数组跟踪图片:

const multimodalIndex: number[] = [];
messages.forEach((msg, i) => {
  if (msg.images && msg.images.length > 0) {
    multimodalIndex.push(i);
    // 处理图片...
  }
});

但 Agnes API 要求 multimodal index 必须对应其在最终请求 messages 数组中的位置。
当存在 system 消息时:

  • Metona: [user(with image), assistant, user(with image)]
  • 发往 Agnes: [system, user(image), assistant, user(image)]
  • multimodal index 应为 [1, 3],但代码计算为 [0, 2]

影响

  • 图片与错误的消息关联
  • 模型理解错乱
  • 多模态能力部分失效

建议修复

const finalMessages: any[] = [];
if (systemPrompt) {
  finalMessages.push({ role: 'system', content: systemPrompt });
}

const multimodalIndices: number[] = [];
messages.forEach((msg) => {
  const finalIndex = finalMessages.length;
  if (msg.images && msg.images.length > 0) {
    multimodalIndices.push(finalIndex);
  }
  finalMessages.push(buildMessage(msg));
});

// 使用 finalMessages.length 计算 index,确保正确

或使用 inline image_url 格式而非 index 引用。

## 问题类型 缺陷 / 高 / LLM 适配器 ## 文件位置 `electron/harness/adapters/agnes-ai.adapter.ts` ## 问题描述 Agnes Adapter 使用独立的 `multimodalIndex` 数组跟踪图片: ```ts const multimodalIndex: number[] = []; messages.forEach((msg, i) => { if (msg.images && msg.images.length > 0) { multimodalIndex.push(i); // 处理图片... } }); ``` 但 Agnes API 要求 multimodal index 必须对应其在最终请求 messages 数组中的位置。 当存在 system 消息时: - Metona: `[user(with image), assistant, user(with image)]` - 发往 Agnes: `[system, user(image), assistant, user(image)]` - multimodal index 应为 `[1, 3]`,但代码计算为 `[0, 2]` ## 影响 - 图片与错误的消息关联 - 模型理解错乱 - 多模态能力部分失效 ## 建议修复 ```ts const finalMessages: any[] = []; if (systemPrompt) { finalMessages.push({ role: 'system', content: systemPrompt }); } const multimodalIndices: number[] = []; messages.forEach((msg) => { const finalIndex = finalMessages.length; if (msg.images && msg.images.length > 0) { multimodalIndices.push(finalIndex); } finalMessages.push(buildMessage(msg)); }); // 使用 finalMessages.length 计算 index,确保正确 ``` 或使用 inline image_url 格式而非 index 引用。
thzxx added the LLM?????? labels 2026-07-21 21:55:55 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#28