feat: subagent runtime & CLI display - wip

This commit is contained in:
tanzhenxin
2025-09-08 20:01:49 +08:00
parent 1f8ea7ab7a
commit 4985bfc000
31 changed files with 2664 additions and 390 deletions

View File

@@ -25,6 +25,7 @@ import {
METRIC_INVALID_CHUNK_COUNT,
METRIC_CONTENT_RETRY_COUNT,
METRIC_CONTENT_RETRY_FAILURE_COUNT,
METRIC_SUBAGENT_EXECUTION_COUNT,
} from './constants.js';
import { Config } from '../config/config.js';
import { DiffStat } from '../tools/tools.js';
@@ -46,6 +47,7 @@ let chatCompressionCounter: Counter | undefined;
let invalidChunkCounter: Counter | undefined;
let contentRetryCounter: Counter | undefined;
let contentRetryFailureCounter: Counter | undefined;
let subagentExecutionCounter: Counter | undefined;
let isMetricsInitialized = false;
function getCommonAttributes(config: Config): Attributes {
@@ -117,6 +119,14 @@ export function initializeMetrics(config: Config): void {
valueType: ValueType.INT,
},
);
subagentExecutionCounter = meter.createCounter(
METRIC_SUBAGENT_EXECUTION_COUNT,
{
description:
'Counts subagent execution events, tagged by status and subagent name.',
valueType: ValueType.INT,
},
);
const sessionCounter = meter.createCounter(METRIC_SESSION_COUNT, {
description: 'Count of CLI sessions started.',
@@ -277,3 +287,27 @@ export function recordContentRetryFailure(config: Config): void {
if (!contentRetryFailureCounter || !isMetricsInitialized) return;
contentRetryFailureCounter.add(1, getCommonAttributes(config));
}
/**
* Records a metric for subagent execution events.
*/
export function recordSubagentExecutionMetrics(
config: Config,
subagentName: string,
status: 'started' | 'progress' | 'completed' | 'failed',
terminateReason?: string,
): void {
if (!subagentExecutionCounter || !isMetricsInitialized) return;
const attributes: Attributes = {
...getCommonAttributes(config),
subagent_name: subagentName,
status,
};
if (terminateReason) {
attributes['terminate_reason'] = terminateReason;
}
subagentExecutionCounter.add(1, attributes);
}