Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-config-reads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Reduce CPU usage during agent turns.
1 change: 1 addition & 0 deletions packages/agent-core-v2/src/app/auth/configSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const servicesEnvBindings: EnvBindings<ServicesConfig> = envBindings(
);

const servicesCredentialEnvOverlay: ConfigEffectiveOverlay = {
domains: [SERVICES_SECTION],
apply(effective, getEnv, validate) {
const services = effective[SERVICES_SECTION];
if (!isPlainObject(services)) return [];
Expand Down
1 change: 1 addition & 0 deletions packages/agent-core-v2/src/app/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface RegisterSectionOptions<T> {
}

export interface ConfigEffectiveOverlay {
readonly domains?: readonly string[];
apply(
effective: Record<string, unknown>,
getEnv: (name: string) => string | undefined,
Expand Down
16 changes: 15 additions & 1 deletion packages/agent-core-v2/src/app/config/configService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/agent-core-v2/src/app/kosongConfig/envOverlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading