fix(core): Summary Agent 从 Global Defaults 继承模型配置

- 移除 Summary Agent 中硬编码的 Anthropic 配置
- 修改 initSummaryModel 逻辑,当 Summary Agent 未指定模型时使用主配置
- 允许用户只配置一个 provider 即可使用所有功能
This commit is contained in:
2025-12-18 11:24:29 +08:00
parent 1801298dce
commit b2bb26a92b
2 changed files with 14 additions and 9 deletions
+4 -5
View File
@@ -3,15 +3,14 @@ import type { AgentInfo } from '../types.js';
/** /**
* Summary Agent * Summary Agent
* 内部 Agent,用于对话压缩时生成摘要 * 内部 Agent,用于对话压缩时生成摘要
* 推荐使用成本较低的模型 *
* 注意:不指定 provider,会从 Global Defaults 继承
* 这样用户只需配置一个 provider 即可使用所有功能
*/ */
export const summaryAgent: Omit<AgentInfo, 'name'> = { export const summaryAgent: Omit<AgentInfo, 'name'> = {
description: '对话压缩摘要生成(内部使用)', description: '对话压缩摘要生成(内部使用)',
mode: 'internal', mode: 'internal',
model: { // 不指定 model.provider,从 Global Defaults 或主配置继承
provider: 'anthropic',
model: 'claude-3-5-haiku-20241022',
},
tools: { tools: {
enabled: [], // 无工具,纯文本生成 enabled: [], // 无工具,纯文本生成
noTask: true, noTask: true,
+10 -4
View File
@@ -94,6 +94,9 @@ export class Agent {
/** /**
* 从 Agent Registry 初始化 Summary 模型 * 从 Agent Registry 初始化 Summary 模型
*
* 如果 Summary Agent 配置了 model,使用配置的模型
* 否则使用主配置的模型(从 Global Defaults 继承)
*/ */
private initSummaryModel( private initSummaryModel(
config: AgentConfig, config: AgentConfig,
@@ -101,11 +104,14 @@ export class Agent {
compressionManager: CompressionManager compressionManager: CompressionManager
): void { ): void {
const summaryAgentInfo = agentRegistry.getInternal('summary'); const summaryAgentInfo = agentRegistry.getInternal('summary');
if (!summaryAgentInfo?.model) {
return;
}
const modelConfig = summaryAgentInfo.model; // 如果 Summary Agent 配置了 model,使用它
// 否则使用主配置(从 Global Defaults 继承)
const modelConfig = summaryAgentInfo?.model || {
provider: config.provider,
model: config.model,
};
const provider = modelConfig.provider || config.provider; const provider = modelConfig.provider || config.provider;
const providerConfig = providerRegistry.getConfig(provider); const providerConfig = providerRegistry.getConfig(provider);
const apiKey = resolveApiKey(providerConfig) || config.apiKey; const apiKey = resolveApiKey(providerConfig) || config.apiKey;