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

Closed
opened 2026-07-21 21:55:55 +08:00 by thzxx · 1 comment
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
Author
Owner

修复说明

文件: electron/harness/adapters/agnes-ai.adapter.ts

结论: 工单描述的问题不存在(误报)。

当前代码不使用工单描述的 multimodalIndex 数组,而是使用 inline image_url 格式(content 数组中的 image_url 对象),不存在 index 引用。索引映射 messages[i]nonSystemMsgs[i-1](i 从 1 开始跳过 system)是正确的,不存在错位。

## 修复说明 **文件**: `electron/harness/adapters/agnes-ai.adapter.ts` **结论**: 工单描述的问题**不存在**(误报)。 当前代码不使用工单描述的 `multimodalIndex` 数组,而是使用 inline `image_url` 格式(content 数组中的 `image_url` 对象),不存在 index 引用。索引映射 `messages[i]` → `nonSystemMsgs[i-1]`(i 从 1 开始跳过 system)是正确的,不存在错位。
thzxx closed this issue 2026-07-22 09:43:04 +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