Skip to content

feat: add tool-call loop detection for ReAct agents - #147

Merged
JDOxygen merged 2 commits into
jd-opensource:mainfrom
yangyalong6:feature-loopdetection-20261014-yangyalong
Oct 27, 2026
Merged

JDOxygen merged 2 commits into
jd-opensource:mainfrom
yangyalong6:feature-loopdetection-20261014-yangyalong

Conversation

@yangyalong6

@yangyalong6 yangyalong6 commented Oct 16, 2026 •

Copy link
Copy Markdown

Summary

  • 为 ReActAgent(及继承它的 SkillAgent)新增工具调用循环检测,覆盖四种模式:error_retry / repeat / repeat_by_output / cycle
  • 提供三种处理模式:disabled(默认,不改变现有行为)/ warn(注入系统提示并继续)/ block(终止 ReAct 循环并返回兜底消息)
  • 新增 oxygent/utils/loop_detector.py、oxygent/utils/loop_signatures.py;react_agent.py 仅 +46 行(2 个字段 + 检测钩子)
  • 配套文档 docs/loop_detection_feature.md、docs/loop_detection_test_report.md 与端到端 demo examples/agents/demo_loop_detection.py

Test plan

  • 单元测试:tests/unittest/test_loop_detector.py 16 条用例全部通过
  • 端到端:三种 mode 的 smoke 测试通过
  • Web UI 真实请求验证通过
  • 回归:45 条定向回归 + 346 条全量回归全部通过
  • 默认 disabled,现有用户零感知

🤖 Generated with Claude Code

yangyalong6 and others added 2 commits October 14, 2026 14:32
Detects four loop patterns (error_retry / repeat / repeat_by_output / cycle)
during ReAct tool execution and reacts via a configurable mode:
  - disabled (default): no behaviour change
  - warn: inject a system hint into react_memory and keep going
  - block / fallback: stop the ReAct loop and return loop_fallback_message

New files:
  - oxygent/utils/loop_detector.py   core detection + prompt builder
  - oxygent/utils/loop_signatures.py tool-level signature registry
  - tests/unittest/test_loop_detector.py 16 unit tests
  - examples/agents/demo_loop_detection.py end-to-end demo

Modified:
  - oxygent/oxy/agents/react_agent.py +47 lines (2 Fields + detection hook)

SkillAgent inherits from ReActAgent so it gets the feature for free.
Default mode is disabled; existing users see no behaviour change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Add docs/loop_detection_feature.md (12-section feature spec covering
  problem statement, architecture, four detection patterns, three handling
  modes, two-layer signature mechanism, usage examples, design trade-offs
  and FAQ)
- Add docs/loop_detection_test_report.md (comprehensive test report:
  16 unit tests, 3-mode e2e smoke, Web UI real-request verification,
  45-test targeted regression, 346-test full regression, performance
  comparison, risk analysis)
- Remove 'fallback' mode (semantic duplicate of 'block'); loop_detection_mode
  now accepts only 'disabled' | 'warn' | 'block'
- Tighten demo prompt so the LLM reliably triggers the search tool

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@JDOxygen
JDOxygen merged commit 546333f into jd-opensource:main Oct 27, 2026
1 check passed
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.

2 participants