Skip to content

fix: make loop detection thresholds configurable via config.yaml#2119

Open
Ricardo-M-L wants to merge 1 commit intobytedance:mainfrom
Ricardo-M-L:fix/configurable-loop-detection-thresholds
Open

fix: make loop detection thresholds configurable via config.yaml#2119
Ricardo-M-L wants to merge 1 commit intobytedance:mainfrom
Ricardo-M-L:fix/configurable-loop-detection-thresholds

Conversation

@Ricardo-M-L
Copy link
Copy Markdown

Summary

  • Problem: LoopDetectionMiddleware uses hardcoded thresholds (warn_threshold=3, hard_limit=5) that are not exposed in config.yaml. This causes false positives with smaller context window models (e.g. DeepSeek) on legitimate retry-heavy tasks.
  • Fix: Add a loop_detection section to config.yaml with four tunable parameters (warn_threshold, hard_limit, window_size, max_tracked_threads). Both the create_deerflow_agent factory and the make_lead_agent application factory now read these values from config.
  • Backwards compatible: Default values match the original hardcoded constants (3, 5, 20, 100), so existing setups are unaffected.

Changes

File Description
config.example.yaml New loop_detection section with documented defaults
deerflow/config/loop_detection_config.py New Pydantic config model with validation (ge constraints)
deerflow/config/app_config.py Added loop_detection field to AppConfig
deerflow/agents/features.py Added loop_detection field to RuntimeFeatures
deerflow/agents/factory.py Wire config values into LoopDetectionMiddleware constructor
deerflow/agents/lead_agent/agent.py Wire config values into LoopDetectionMiddleware constructor
backend/tests/test_loop_detection_config.py 229-line test suite covering config defaults, validation, custom thresholds, and DeepSeek-friendly scenarios

Example usage

# config.yaml — raise thresholds for DeepSeek or retry-heavy workflows
loop_detection:
  warn_threshold: 5
  hard_limit: 10

Fixes #2116

Test plan

  • Existing test_loop_detection_middleware.py tests pass unchanged (backwards compat)
  • New test_loop_detection_config.py tests verify: default values, custom values, Pydantic validation, higher thresholds avoiding false positives, DeepSeek-friendly config scenario
  • Config loading: AppConfig correctly parses loop_detection from YAML and falls back to defaults when omitted

🤖 Generated with Claude Code

LoopDetectionMiddleware used hardcoded thresholds (warn_threshold=3,
hard_limit=5) that caused false positives with smaller context window
models like DeepSeek on legitimate retry-heavy tasks.

This adds a `loop_detection` section to config.yaml with four tunable
parameters: warn_threshold, hard_limit, window_size, and
max_tracked_threads. Both the factory (create_deerflow_agent) and the
lead_agent (make_lead_agent) paths now read these values from config.
Default values preserve existing behavior for backwards compatibility.

Fixes bytedance#2116
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loop detection false positives on legitimate retries — thresholds not configurable via config.yaml

2 participants