fix(planner): add iteration limit to PlanController to prevent unbounded agent loops#36
fix(planner): add iteration limit to PlanController to prevent unbounded agent loops#36jihunkeom wants to merge 1 commit intocuga-project:mainfrom
Conversation
…ded agent loops Add plan_controller_iteration_count to AgentState and enforce max_plan_iterations (default 15) in PlanController. When exceeded, the agent is routed to FinalAnswerAgent with partial progress. Also set recursion_limit=135 on SDK invoke/stream calls. Refs: cuga-project#21 Signed-off-by: Ji Hun Keom <Jihun.Keom@ibm.com>
📝 WalkthroughWalkthroughThese changes implement two-level protection against unbounded agent loops: a default recursion_limit of 135 at the SDK level and a PlanController iteration counter (max_plan_iterations default 15) that forces early task conclusion when exceeded. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
83568da to
1b3bfb6
Compare
Bug Fix Pull Request
Related Issue
Fixes #21
Description
PlanController can enter an unbounded loop, executing 800+ steps when the LLM
never returns
conclude_task=True. This adds an iteration limit to forcegraceful termination.
Type of Changes
Root Cause
PlanController's loop-return path had no iteration cap. If the LLM kept
generating new subtasks without concluding, the agent would cycle indefinitely,
consuming tokens and compute.
Solution
plan_controller_iteration_countfield toAgentState(default0)PlanControllerNode; reset to0on freshentry from
TaskDecompositionAgentmax_plan_iterations(configurable, default15), routedirectly to
FinalAnswerAgentwith partial progress summaryrecursion_limit=135on SDKinvokeandstreamcalls to matchagent_loop.pyand prevent LangGraph-level recursion errorsTesting
Checklist
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests