feat: add AgentLoopDetectionMetric for detecting infinite loops and cyclical patterns#2819
Open
Ruthwik-Data wants to merge 11 commits into
Open
feat: add AgentLoopDetectionMetric for detecting infinite loops and cyclical patterns#2819Ruthwik-Data wants to merge 11 commits into
Ruthwik-Data wants to merge 11 commits into
Conversation
This class analyzes agent execution traces to detect infinite loops and cyclical patterns, including tool call repetition, reasoning stagnation, and call cycles.
|
@Ruthwik-Data is attempting to deploy a commit to the Confident AI Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds AgentLoopDetectionMetric to detect production failures where agents get stuck in infinite loops before completing their tasks. Addresses issue #2643.
What's included
Core detection mechanisms
API
Output structure
Design decisions
Deterministic by default: Uses n-gram overlap for reasoning stagnation to keep the metric zero-latency. Embedding-based detection is opt-in for higher recall.
min_identical_args_ratio: Prevents false positives on legitimate retry-with-variation patterns (e.g., a search tool re-querying with slightly different params).Actionable output: The
loop_triggersfield annotates exactly which steps triggered detection and why, enabling teams to debug and fix agent logic.Trace-only: Requires
test_case._trace_dictwith astepsfield. Each step should include:tool_nameandtool_argsfor tool callsllm_outputorreasoningfor reasoning detectionRelated
Testing
Before merging, will add:
@observedecoratorHappy to coordinate with @rohitmannur007 to avoid conflicts. Let me know if the API/approach aligns with the intended design!