[P0/严重] Agent Engine 未调用 adapter.getContextWindow() 同步压缩阈值 #3

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

问题类型

缺陷 / 严重 / Agent 引擎

文件位置

electron/harness/agent-loop/engine.ts (DEFAULT_CONFIG.contextWindow = 128_000)

问题描述

Engine 的 DEFAULT_CONFIG.contextWindow 硬编码为 128_000,而各 Provider 实际支持的上下文窗口差异巨大:

  • DeepSeek: 64K (thinking)
  • Agnes AI: 1M
  • MiMo: 131K
  • Ollama: 视本地模型而定

Engine 在初始化和 runStream 时从未调用 adapter.getContextWindow() 同步该值,导致:

  1. 上下文压缩阈值 (compressionThreshold * contextWindow) 计算错误
  2. DeepSeek 用户可能因阈值过高导致请求超长被 API 拒绝
  3. Agnes 用户可能因阈值过低导致频繁压缩,损失上下文

这违反了 project_memory.md 中的硬性约束:

Engine context window must be synchronized with the LLM adapter's configured context window value

建议修复

runStream 开始处同步:

private async executeRunStream(...) {
  // ...
  // 同步 adapter 的 contextWindow 到 Engine 配置
  const adapterCtx = this.adapter.getContextWindow?.();
  if (adapterCtx && adapterCtx > 0) {
    this.config.contextWindow = adapterCtx;
  }
  // ...
}

同时在 setAdapter 热切换时也要同步。

## 问题类型 缺陷 / 严重 / Agent 引擎 ## 文件位置 `electron/harness/agent-loop/engine.ts` (DEFAULT_CONFIG.contextWindow = 128_000) ## 问题描述 Engine 的 `DEFAULT_CONFIG.contextWindow` 硬编码为 128_000,而各 Provider 实际支持的上下文窗口差异巨大: - DeepSeek: 64K (thinking) - Agnes AI: 1M - MiMo: 131K - Ollama: 视本地模型而定 Engine 在初始化和 runStream 时从未调用 `adapter.getContextWindow()` 同步该值,导致: 1. 上下文压缩阈值 (`compressionThreshold * contextWindow`) 计算错误 2. DeepSeek 用户可能因阈值过高导致请求超长被 API 拒绝 3. Agnes 用户可能因阈值过低导致频繁压缩,损失上下文 这违反了 project_memory.md 中的硬性约束: > Engine context window must be synchronized with the LLM adapter's configured context window value ## 建议修复 在 `runStream` 开始处同步: ```ts private async executeRunStream(...) { // ... // 同步 adapter 的 contextWindow 到 Engine 配置 const adapterCtx = this.adapter.getContextWindow?.(); if (adapterCtx && adapterCtx > 0) { this.config.contextWindow = adapterCtx; } // ... } ``` 同时在 `setAdapter` 热切换时也要同步。
thzxx added the Agent?????? labels 2026-07-21 21:55:35 +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#3