summaryrefslogtreecommitdiff
path: root/packages/core/src/services/loopDetectionService.ts
diff options
context:
space:
mode:
authorSandy Tao <[email protected]>2025-07-23 22:37:28 -0700
committerGitHub <[email protected]>2025-07-24 05:37:28 +0000
commit0ef9c0b792f056015d0eee4486480c1f80015fc5 (patch)
treedd07e9c5c241362e0f8c395b3cbcedfe92abd736 /packages/core/src/services/loopDetectionService.ts
parent6380bfe35c80e71f6a43bc7b549e61561d675a07 (diff)
Log prompt id when a loop is detected (#4765)
Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/core/src/services/loopDetectionService.ts')
-rw-r--r--packages/core/src/services/loopDetectionService.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/packages/core/src/services/loopDetectionService.ts b/packages/core/src/services/loopDetectionService.ts
index 1c3ea412..85f38c12 100644
--- a/packages/core/src/services/loopDetectionService.ts
+++ b/packages/core/src/services/loopDetectionService.ts
@@ -50,6 +50,7 @@ const SENTENCE_ENDING_PUNCTUATION_REGEX = /[.!?]+(?=\s|$)/;
*/
export class LoopDetectionService {
private readonly config: Config;
+ private promptId = '';
// Tool call tracking
private lastToolCallKey: string | null = null;
@@ -129,7 +130,10 @@ export class LoopDetectionService {
if (this.toolCallRepetitionCount >= TOOL_CALL_LOOP_THRESHOLD) {
logLoopDetected(
this.config,
- new LoopDetectedEvent(LoopType.CONSECUTIVE_IDENTICAL_TOOL_CALLS),
+ new LoopDetectedEvent(
+ LoopType.CONSECUTIVE_IDENTICAL_TOOL_CALLS,
+ this.promptId,
+ ),
);
return true;
}
@@ -170,7 +174,10 @@ export class LoopDetectionService {
if (this.sentenceRepetitionCount >= CONTENT_LOOP_THRESHOLD) {
logLoopDetected(
this.config,
- new LoopDetectedEvent(LoopType.CHANTING_IDENTICAL_SENTENCES),
+ new LoopDetectedEvent(
+ LoopType.CHANTING_IDENTICAL_SENTENCES,
+ this.promptId,
+ ),
);
return true;
}
@@ -234,7 +241,7 @@ Please analyze the conversation history to determine the possibility that the co
}
logLoopDetected(
this.config,
- new LoopDetectedEvent(LoopType.LLM_DETECTED_LOOP),
+ new LoopDetectedEvent(LoopType.LLM_DETECTED_LOOP, this.promptId),
);
return true;
} else {
@@ -251,7 +258,8 @@ Please analyze the conversation history to determine the possibility that the co
/**
* Resets all loop detection state.
*/
- reset(): void {
+ reset(promptId: string): void {
+ this.promptId = promptId;
this.resetToolCallCount();
this.resetSentenceCount();
this.resetLlmCheckTracking();