Skip to content

Commit e35095f

Browse files
committed
Reset tool loop detector after degenerate loop error
When a degenerate tool call loop is detected, reset the loop detector so that the user can resume the conversation without immediately hitting the same error on the next tool call. Assisted-By: docker-agent
1 parent 9318923 commit e35095f

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

pkg/runtime/loop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ func (r *LocalRuntime) RunStream(ctx context.Context, sess *session.Session) <-c
352352
loopDetector.consecutive, toolName)
353353
events <- Error(errMsg)
354354
r.executeNotificationHooks(ctx, a, sess.ID, "error", errMsg)
355+
loopDetector.reset()
355356
return
356357
}
357358

pkg/runtime/tool_loop_detector.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ func newToolLoopDetector(threshold int) *toolLoopDetector {
2424
return &toolLoopDetector{threshold: threshold}
2525
}
2626

27+
// reset clears the detector state so it can be reused after recovery.
28+
func (d *toolLoopDetector) reset() {
29+
d.lastSignature = ""
30+
d.consecutive = 0
31+
}
32+
2733
// record updates the detector with the latest tool call batch and returns
2834
// true if the consecutive-duplicate threshold has been reached.
2935
func (d *toolLoopDetector) record(calls []tools.ToolCall) bool {

0 commit comments

Comments
 (0)