Skip to content
Merged
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
24 changes: 19 additions & 5 deletions packages/agent-core-v2/src/agent/profile/profileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ export class AgentProfileService extends Disposable implements IAgentProfileServ
this.states.contributeState(profileEmittedToolPatternWarningsKey);
this.states.contributeState(profileEmittedPluginBudgetWarningsKey);
this.configure({});
this._register(
this.dispatcher.hooks.onDidRestore.register('profile', async (_ctx, next) => {
this.syncTelemetryModelContext(this.modelAlias);
await next();
}),
);
this._register(
this.config.onDidSectionChange(({ domain }) => {
if (domain === TOOLS_SECTION) {
Expand Down Expand Up @@ -542,11 +548,7 @@ export class AgentProfileService extends Disposable implements IAgentProfileServ

private afterConfigDispatch(changed: Omit<ProfileUpdateData, 'activeToolNames'>): void {
if (changed.modelAlias !== undefined) {
const model = this.tryResolveRawModel();
this.telemetry.setContext({
provider_type: model?.providerType ?? model?.protocol,
protocol: model?.protocol,
});
this.syncTelemetryModelContext(changed.modelAlias);
}
if (changed.modelAlias !== undefined || changed.thinkingLevel !== undefined) {
this.warnAboutAnthropicThinkingEffort();
Expand All @@ -556,6 +558,18 @@ export class AgentProfileService extends Disposable implements IAgentProfileServ
);
}

private syncTelemetryModelContext(modelAlias: string | undefined): void {
if (modelAlias === undefined) {
return;
}
const model = this.tryResolveRawModel();
this.telemetry.setContext({
model: modelAlias,
provider_type: model?.providerType ?? model?.protocol,
protocol: model?.protocol,
});
}

private warnAboutAnthropicThinkingEffort(): void {
try {
const model = this.tryResolveRawModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ describe('FullCompaction', () => {
from: 'compacting',
trace_id: 'trace-compact-retry',
mode: 'agent',
model: 'kimi-code',
protocol: 'openai',
provider_type: 'kimi',
},
Expand Down
1 change: 1 addition & 0 deletions packages/agent-core-v2/test/agent/loop/loop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ describe('turn telemetry', () => {
turn_id: 0,
agent_id: 'main',
mode: 'agent',
model: 'mock-model',
provider_type: 'kimi',
protocol: 'openai',
thinking_effort: 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('setModeAndBroadcast', () => {
expect(ctx.get(IAgentPermissionModeService).mode).toBe('auto');
expect(records).toContainEqual({
event: 'afk_toggle',
properties: { agent_id: 'main', enabled: true, mode: 'agent', protocol: 'openai', provider_type: 'kimi' },
properties: { agent_id: 'main', enabled: true, mode: 'agent', model: 'mock-model', protocol: 'openai', provider_type: 'kimi' },
});
});

Expand All @@ -40,11 +40,11 @@ describe('setModeAndBroadcast', () => {
expect(ctx.get(IAgentPermissionModeService).mode).toBe('manual');
expect(records).toContainEqual({
event: 'yolo_toggle',
properties: { agent_id: 'main', enabled: true, mode: 'agent', protocol: 'openai', provider_type: 'kimi' },
properties: { agent_id: 'main', enabled: true, mode: 'agent', model: 'mock-model', protocol: 'openai', provider_type: 'kimi' },
});
expect(records).toContainEqual({
event: 'yolo_toggle',
properties: { agent_id: 'main', enabled: false, mode: 'agent', protocol: 'openai', provider_type: 'kimi' },
properties: { agent_id: 'main', enabled: false, mode: 'agent', model: 'mock-model', protocol: 'openai', provider_type: 'kimi' },
});
});
});
81 changes: 81 additions & 0 deletions packages/agent-core-v2/test/agent/profile/config-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { IAgentLLMRequesterService } from '#/agent/llmRequester/llmRequester';
import { IAgentProfileService } from '#/agent/profile/profile';
import { ITelemetryService } from '#/app/telemetry/telemetry';
import type { ModelRecord } from '#/kosong/model/model';
import {
configServices,
createTestAgent,
InMemoryWireRecordPersistence,
llmGenerateServices,
modelProviderOptionServices,
telemetryServices,
wireRecordPersistenceServices,
type TestAgentContext,
} from '../../harness';
import { recordingTelemetry, type TelemetryRecord } from '../../app/telemetry/stubs';
Expand Down Expand Up @@ -162,12 +165,90 @@ describe('ConfigState model capabilities', () => {
effort: 'low',
from: 'off',
mode: 'agent',
model: 'kimi-code/kimi-for-coding',
protocol: 'openai',
provider_type: 'kimi',
},
});
});

it('writes the bound model into the ambient telemetry context', () => {
kimiConfig = {
providers: {
kimi: {
type: 'kimi',
apiKey: 'test-key',
baseUrl: 'https://api.example.test/v1',
},
},
models: {
'kimi-code/kimi-for-coding': {
provider: 'kimi',
model: 'kimi-for-coding',
maxContextSize: 1_000_000,
},
},
};

profile.update({ modelAlias: 'kimi-code/kimi-for-coding' });

expect(ctx.get(ITelemetryService).getContext()).toMatchObject({
model: 'kimi-code/kimi-for-coding',
provider_type: 'kimi',
protocol: 'openai',
});
});

it('keeps the alias as ambient model when the bound model does not resolve', () => {
profile.update({ modelAlias: 'ghost/model' });

expect(ctx.get(ITelemetryService).getContext()).toMatchObject({
model: 'ghost/model',
});
});

it('restores the ambient model after a cold resume', async () => {
kimiConfig = {
providers: {
kimi: {
type: 'kimi',
apiKey: 'test-key',
baseUrl: 'https://api.example.test/v1',
},
},
models: {
'kimi-code/kimi-for-coding': {
provider: 'kimi',
model: 'kimi-for-coding',
maxContextSize: 1_000_000,
},
},
};
const resumedRecords: TelemetryRecord[] = [];
const resumed = createTestAgent(
{ autoConfigure: false },
configServices(() => kimiConfig),
llmGenerateServices((...args) => generate(...args)),
telemetryServices(recordingTelemetry(resumedRecords)),
wireRecordPersistenceServices(
new InMemoryWireRecordPersistence([
{ type: 'config.update', agentId: 'main', modelAlias: 'kimi-code/kimi-for-coding' },
]),
),
);
try {
await resumed.restorePersisted();

expect(resumed.get(ITelemetryService).getContext()).toMatchObject({
model: 'kimi-code/kimi-for-coding',
provider_type: 'kimi',
protocol: 'openai',
});
} finally {
await resumed.dispose();
}
});

it('does not infer Kimi capabilities from the provider catalogue', () => {
kimiConfig = {
providers: {
Expand Down
2 changes: 2 additions & 0 deletions packages/agent-core-v2/test/agent/task/rpc-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ describe('AgentTaskService — event emission', () => {
task_id: taskId,
kind: 'bash',
mode: 'agent',
model: 'mock-model',
protocol: 'openai',
provider_type: 'kimi',
},
Expand Down Expand Up @@ -356,6 +357,7 @@ describe('AgentTaskService — event emission', () => {
task_id: taskId,
kind: 'agent',
mode: 'agent',
model: 'mock-model',
protocol: 'openai',
provider_type: 'kimi',
},
Expand Down
2 changes: 2 additions & 0 deletions packages/agent-core-v2/test/agent/undo/undo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ describe('AgentConversationUndoService', () => {
agent_id: 'main',
count: 1,
mode: 'agent',
model: 'mock-model',
protocol: 'openai',
provider_type: 'kimi',
},
Expand Down Expand Up @@ -582,6 +583,7 @@ describe('AgentConversationUndoService', () => {
agent_id: 'main',
count: 1,
mode: 'agent',
model: 'mock-model',
protocol: 'openai',
provider_type: 'kimi',
},
Expand Down
1 change: 1 addition & 0 deletions packages/agent-core-v2/test/features/goal/goal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ describe('AgentGoalService', () => {
actor: 'user',
replace: true,
mode: 'agent',
model: 'mock-model',
protocol: 'openai',
provider_type: 'kimi',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ describe('AgentPlanService EnterPlanMode telemetry', () => {
properties: {
agent_id: 'main',
mode: 'plan',
model: 'mock-model',
outcome: 'auto_approved',
protocol: 'openai',
provider_type: 'kimi',
Expand Down
Loading