diff --git a/.changeset/quiet-config-reads.md b/.changeset/quiet-config-reads.md new file mode 100644 index 00000000000..dc75e8141fa --- /dev/null +++ b/.changeset/quiet-config-reads.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": patch +--- + +Reduce CPU usage during agent turns. diff --git a/packages/agent-core-v2/src/app/auth/configSection.ts b/packages/agent-core-v2/src/app/auth/configSection.ts index 0ac2dd6b834..1619eed5105 100644 --- a/packages/agent-core-v2/src/app/auth/configSection.ts +++ b/packages/agent-core-v2/src/app/auth/configSection.ts @@ -80,6 +80,7 @@ export const servicesEnvBindings: EnvBindings = envBindings( ); const servicesCredentialEnvOverlay: ConfigEffectiveOverlay = { + domains: [SERVICES_SECTION], apply(effective, getEnv, validate) { const services = effective[SERVICES_SECTION]; if (!isPlainObject(services)) return []; diff --git a/packages/agent-core-v2/src/app/config/config.ts b/packages/agent-core-v2/src/app/config/config.ts index 20a2a1f966e..e1937341b05 100644 --- a/packages/agent-core-v2/src/app/config/config.ts +++ b/packages/agent-core-v2/src/app/config/config.ts @@ -111,6 +111,7 @@ export interface RegisterSectionOptions { } export interface ConfigEffectiveOverlay { + readonly domains?: readonly string[]; apply( effective: Record, getEnv: (name: string) => string | undefined, diff --git a/packages/agent-core-v2/src/app/config/configService.ts b/packages/agent-core-v2/src/app/config/configService.ts index e4fefd88ec0..f6bad250ea5 100644 --- a/packages/agent-core-v2/src/app/config/configService.ts +++ b/packages/agent-core-v2/src/app/config/configService.ts @@ -401,6 +401,15 @@ export class ConfigService extends Disposable implements IConfigService { if (Object.prototype.hasOwnProperty.call(this.memory, domain)) { return this.memory[domain] as T; } + if ( + this.registry + .listEffectiveOverlays() + .every((overlay) => overlay.domains !== undefined && !overlay.domains.includes(domain)) + ) { + const effective: ResolvedConfig = { [domain]: this.validated[domain] }; + this.applySectionEnvBindings(effective, false, domain); + return effective[domain] as T; + } return this.freshEffective()[domain] as T; } @@ -766,9 +775,14 @@ export class ConfigService extends Disposable implements IConfigService { return names; } - private applySectionEnvBindings(effective: ResolvedConfig, reportErrors: boolean): void { + private applySectionEnvBindings( + effective: ResolvedConfig, + reportErrors: boolean, + domain?: string, + ): void { const getEnv = (name: string): string | undefined => this.bootstrap.getEnv(name); for (const section of this.registry.listSections()) { + if (domain !== undefined && section.domain !== domain) continue; if (section.env === undefined) continue; const base = effective[section.domain]; const envValues = this.sectionEnvNames(section).map(getEnv); diff --git a/packages/agent-core-v2/src/app/kosongConfig/envOverlay.ts b/packages/agent-core-v2/src/app/kosongConfig/envOverlay.ts index d0c4e631177..44ac4e938ca 100644 --- a/packages/agent-core-v2/src/app/kosongConfig/envOverlay.ts +++ b/packages/agent-core-v2/src/app/kosongConfig/envOverlay.ts @@ -85,6 +85,7 @@ function withoutKey(value: unknown, key: string): unknown { } export const kimiModelEnvOverlay: ConfigEffectiveOverlay = { + domains: ['models', 'providers', 'defaultModel', 'modelOverrides'], apply(effective, getEnv, validate) { const model = trimmed(getEnv('KIMI_MODEL_NAME')); const temperature = parseFloatEnv(