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

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

修复说明

文件: electron/harness/agent-loop/engine.ts

问题: Engine 的 DEFAULT_CONFIG.contextWindow 硬编码为 128_000,从未调用 adapter.getContextWindow() 同步,导致各 Provider(DeepSeek 64K / Agnes 1M / Ollama 4096)的压缩阈值计算错误。

修复方案:

  1. 新增 syncContextWindow() 私有方法:从 adapter.getContextWindow() 读取并同步到 this.config.contextWindow
  2. setAdapter() 热切换 adapter 时调用同步
  3. executeRunStream() 开始处也调用同步(确保每次 run 基于当前 adapter 的上下文窗口)

验证: tsc --noEmit 类型检查通过。

## 修复说明 **文件**: `electron/harness/agent-loop/engine.ts` **问题**: Engine 的 `DEFAULT_CONFIG.contextWindow` 硬编码为 128_000,从未调用 `adapter.getContextWindow()` 同步,导致各 Provider(DeepSeek 64K / Agnes 1M / Ollama 4096)的压缩阈值计算错误。 **修复方案**: 1. 新增 `syncContextWindow()` 私有方法:从 `adapter.getContextWindow()` 读取并同步到 `this.config.contextWindow` 2. 在 `setAdapter()` 热切换 adapter 时调用同步 3. 在 `executeRunStream()` 开始处也调用同步(确保每次 run 基于当前 adapter 的上下文窗口) **验证**: `tsc --noEmit` 类型检查通过。
thzxx closed this issue 2026-07-22 09:14:47 +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