Log the 2 types of loop detection (#4193)

This commit is contained in:
Sandy Tao
2025-07-14 21:44:07 -07:00
committed by GitHub
parent 734da8b9d2
commit 886faa2990
7 changed files with 102 additions and 5 deletions

View File

@@ -25,6 +25,7 @@ import {
ToolCallEvent,
UserPromptEvent,
FlashFallbackEvent,
LoopDetectedEvent,
} from './types.js';
import {
recordApiErrorMetrics,
@@ -288,3 +289,23 @@ export function logApiResponse(config: Config, event: ApiResponseEvent): void {
);
recordTokenUsageMetrics(config, event.model, event.tool_token_count, 'tool');
}
export function logLoopDetected(
config: Config,
event: LoopDetectedEvent,
): void {
ClearcutLogger.getInstance(config)?.logLoopDetectedEvent(event);
if (!isTelemetrySdkInitialized()) return;
const attributes: LogAttributes = {
...getCommonAttributes(config),
...event,
};
const logger = logs.getLogger(SERVICE_NAME);
const logRecord: LogRecord = {
body: `Loop detected. Type: ${event.loop_type}.`,
attributes,
};
logger.emit(logRecord);
}