mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-09 17:29:12 +00:00
feat(agent-core): add thinkingLevel to compaction telemetry (#954)
Report the effective thinking effort (off/low/medium/high/xhigh/max) on compaction_finished, compaction_failed, and micro_compaction_finished events. The value matches the thinking level applied to the compaction provider, so we can analyze how thinking mode affects compaction token usage, duration, and failures.
This commit is contained in:
parent
ba64072559
commit
3443a00a43
4 changed files with 14 additions and 1 deletions
|
|
@ -344,6 +344,7 @@ export class FullCompaction {
|
|||
compactedCount: result.compactedCount,
|
||||
retryCount,
|
||||
round,
|
||||
thinkingLevel: this.agent.config.thinkingLevel,
|
||||
...usage,
|
||||
...data,
|
||||
});
|
||||
|
|
@ -357,6 +358,7 @@ export class FullCompaction {
|
|||
duration: Date.now() - startedAt,
|
||||
round,
|
||||
retryCount,
|
||||
thinkingLevel: this.agent.config.thinkingLevel,
|
||||
errorType: error instanceof Error ? error.name : 'Unknown',
|
||||
});
|
||||
if (isKimiError(error) && error.code === ErrorCodes.AUTH_LOGIN_REQUIRED) throw error;
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ export class MicroCompaction {
|
|||
cutoff: nextCutoff,
|
||||
message_count: history.length,
|
||||
cache_age_ms: cacheAgeMs,
|
||||
thinkingLevel: this.agent.config.thinkingLevel,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -240,6 +240,7 @@ describe('FullCompaction', () => {
|
|||
duration: expect.any(Number),
|
||||
compactedCount: 6,
|
||||
retryCount: 0,
|
||||
thinkingLevel: 'off',
|
||||
inputOther: 520,
|
||||
output: 8,
|
||||
inputCacheRead: 0,
|
||||
|
|
@ -1589,6 +1590,7 @@ describe('FullCompaction', () => {
|
|||
|
||||
it('preserves thinking effort when compacting after provider context overflow', async () => {
|
||||
let callCount = 0;
|
||||
const records: TelemetryRecord[] = [];
|
||||
const providerThinkingEfforts: Array<Parameters<GenerateFn>[0]['thinkingEffort']> = [];
|
||||
const generate: GenerateFn = async (provider, _system, _tools, _history, callbacks) => {
|
||||
callCount += 1;
|
||||
|
|
@ -1612,7 +1614,7 @@ describe('FullCompaction', () => {
|
|||
}
|
||||
throw new Error(`Unexpected generate call ${String(callCount)}`);
|
||||
};
|
||||
const ctx = testAgent({ generate });
|
||||
const ctx = testAgent({ generate, telemetry: recordingTelemetry(records) });
|
||||
ctx.configure({
|
||||
provider: CATALOGUED_PROVIDER,
|
||||
modelCapabilities: CATALOGUED_MODEL_CAPABILITIES,
|
||||
|
|
@ -1626,6 +1628,13 @@ describe('FullCompaction', () => {
|
|||
|
||||
expect(callCount).toBe(3);
|
||||
expect(providerThinkingEfforts).toEqual(['high', 'high', 'high']);
|
||||
expect(records).toContainEqual({
|
||||
event: 'compaction_finished',
|
||||
properties: expect.objectContaining({
|
||||
source: 'auto',
|
||||
thinkingLevel: 'high',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
it('compacts provider overflow when model context size is unknown', async () => {
|
||||
|
|
|
|||
|
|
@ -482,6 +482,7 @@ describe('MicroCompaction', () => {
|
|||
truncatedToolResultTokensAfter: expect.any(Number),
|
||||
tokensBefore: expect.any(Number),
|
||||
tokensAfter: expect.any(Number),
|
||||
thinkingLevel: 'off',
|
||||
});
|
||||
expect(numberProperty(event, 'truncatedToolResultTokensBefore')).toBeGreaterThan(
|
||||
numberProperty(event, 'truncatedToolResultTokensAfter'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue