[Agent Builder] Fix graph recursion limit and cycle state carry-over#265538
Draft
hop-dev wants to merge 1 commit intoelastic:mainfrom
Draft
[Agent Builder] Fix graph recursion limit and cycle state carry-over#265538hop-dev wants to merge 1 commit intoelastic:mainfrom
hop-dev wants to merge 1 commit intoelastic:mainfrom
Conversation
The `getRecursionLimit` formula assumed 2 graph steps per research cycle (researchAgent + executeTool), but the actual graph has 3 steps per cycle (checkBackgroundWork + researchAgent + executeTool). This caused LangGraph's GRAPH_RECURSION_LIMIT to fire at ~11 tool cycles instead of the intended 15, particularly affecting tool-heavy skills like entity analytics. Additionally, `currentCycle` and `errorCount` were unconditionally restored from the previous round's state, meaning each new user message inherited the accumulated cycle count from the prior turn. This is only correct for HITL (human-in-the-loop) resume when the round status is `awaitingPrompt`; completed rounds should start fresh at cycle 0. Made-with: Cursor
|
🤖 Jobs for this PR can be triggered through checkboxes. 🚧
ℹ️ To trigger the CI, please tick the checkbox below 👇
|
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
We noticed that the Entity Analytics skill in Agent Builder was often hitting a
GRAPH_RECURSION_LIMITerror during multi-turn conversations. The repro is straightforward: ask the agent to show the Entity Analytics dashboard, then follow up with something like "help me analyze the 3 critical risks" — the second turn would fail with the LangGraph recursion error.Digging in, it looks like the Entity Analytics skill surfaces this because it's one of the more tool-heavy flows (search entities → get entity per result → add dashboard attachment), but the underlying issue appears to be in the platform agent builder graph, not the skill itself.
Fix 1:
getRecursionLimitformulaThe
getRecursionLimitfunction assumed 2 graph steps per research cycle (researchAgent + executeTool), but the graph actually traverses 3 nodes per cycle becausecheckBackgroundWorksits betweenexecuteToolandresearchAgenton every loop. This meant the LangGraph recursion limit was set to 38 (15 * 2 + 8) when the graph could need up to ~55 steps to complete 15 cycles plus the answer phase. In practice the graph would hit the hard limit at around 11 tool cycles instead of the intended 15.Updated to
cycleLimit * 3 + 10.Fix 2:
currentCyclecarry-over across roundscurrentCycleanderrorCountwere being restored from the previous round's state unconditionally. This means if round 1 used 6 cycles, round 2 would start at cycle 6 instead of 0 — shrinking the effective tool budget for every subsequent turn in a conversation. This state restoration looks like it's intended for HITL (human-in-the-loop) resume when the round isawaitingPrompt, so the fix gates it on that status.