Skip to content

Feature: 支持 compaction 使用独立模型(compaction_model 配置项) #840

Closed

Description

@li-xiu-qi

What feature would you like to see?

支持在 config.toml 中为 compaction(上下文压缩)单独指定模型,与主对话模型解耦。

当前行为:

packages/agent-core/src/agent/compaction/full.ts 第 263-282 行,compaction 硬编码使用 this.agent.config.model 和 this.agent.config.provider:

// full.ts:263
const model = this.agent.config.model;                    // ← 始终用主模型
const provider = applyCompletionBudget({
  provider: this.agent.config.provider,                    // ← 始终用主 provider
  budget: resolveCompletionBudget({
    reservedContextSize: this.agent.kimiConfig?.loopControl?.reservedContextSize,
  }),
  capability: this.agent.config.modelCapabilities,
});
// full.ts:282
const response = await this.agent.generate(
  provider,
  this.agent.config.systemPrompt,
  [...this.agent.tools.loopTools],
  messages,
  undefined,
  { signal },
);

没有入口可以配置独立的 compaction 模型。

期望行为:

在 [loop_control] 下新增 compaction_model 配置项:

[loop_control]
# ... 现有选项 ...

# 可选:compaction 使用独立模型
# 不设置则 fallback 到主模型(向后兼容)
compaction_model = "stepfun/step-3.7-flash"

compaction 触发时,解析 compaction_model 别名 → 对应 provider,用它替代 this.agent.config.model/provider。

实现草图:

// full.ts:263 改为
const compactionModelAlias = this.agent.kimiConfig?.loopControl?.compactionModel;
const resolved = compactionModelAlias
  ? this.agent.modelProvider?.resolveProviderConfig(compactionModelAlias)
  : undefined;

const model = resolved?.model ?? this.agent.config.model;
const provider = applyCompletionBudget({
  provider: resolved?.provider ?? this.agent.config.provider,
  budget: resolveCompletionBudget({ ... }),
  capability: resolved?.capabilities ?? this.agent.config.modelCapabilities,
});

Additional information

使用场景:

角色 模型 通道 成本
主对话 zhipu/glm-5.2(1M 上下文) 标准 API 按 token 计费(贵)
compaction stepfun/step-3.7-flash(256K,400 TPS) Step Plan 订阅 Credit 月池(不额外消耗人民币)

用户用 GLM 5.2 做高质量编码对话,compaction 时切到 step-3.7-flash,既快又省钱。这个场景对所有「主模型贵 + 有订阅制便宜模型」的用户都有价值。

为什么不直接用便宜模型做主模型:

  • 不同模型在编码、推理、长上下文理解上能力差异大
  • 用户希望在对话质量上用最好的模型,只在压缩这种简单任务上省成本
  • Step Plan 等订阅制的 Credit 额度如果不用完就清零,用来做 compaction 是零成本

先例:

  • OpenClaw 已有 agents.defaults.compaction.model 配置(openclaw.json),虽然目前有 bug(#80784 导致运行时被忽略),但说明这个需求是普遍的
  • claude-code-router 也有同样的 feature request(musistudio/claude-code-router#828)

向后兼容:compaction_model 不设置时行为完全不变,compaction 使用主模型。纯增量功能,不影响现有用户。

Activity

  1. tt-a1i commented on Jun 20, 2026

    @tt-a1i
    Contributor

    I can take this. I'll keep it backwards compatible: add loop_control.compaction_model, resolve it through the existing model alias/provider path, and fall back to the main model when it is not set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions