Skip to main content

Recursion Limit

When using the Xpert AI platform for agent invocation or task orchestration, you may encounter an error message like:

Before reaching the stopping condition, the recursion limit of 20 has been hit. You can increase this limit by configuring the "Recursion Limit" in the Agent Settings of the Digital Expert Studio.

Or a similar error stack message, indicating that the recursion depth has exceeded the systemโ€™s preset limit. This guide will help you understand why this limit exists and provide best practices and troubleshooting tips.


โ“ Why is a Recursion Limit Needed?โ€‹

The Xpert AI platform supports collaboration among multiple agents, enabling multi-turn processing, conditional logic, and context passing. These features may lead to nested invocations, such as:

  • Agent A delegates part of a task to Agent B, which then delegates to Agent C, and so on
  • A failed task triggers a rollback or retry mechanism
  • An agent re-invokes itself to optimize inference based on output results

Without a recursion limit, misconfigured logic or infinite loops can cause:

  • Excessive token consumption
  • Severe response delays
  • System instability

To ensure system performance and stability, the platform enforces a maximum recursion limit.


โœ… Best Practicesโ€‹

  1. Clarify the Task Flow: Ensure that the task call paths are convergent, not infinite loops.
  2. Implement Exit Mechanisms: Define stop conditions in agent logicโ€”e.g., max rounds reached, goal achieved, confidence no longer improving.
  3. Avoid Unnecessary Nesting: Minimize deep call chains. Prefer flat, modular agent designs with clear responsibilities.
  4. Configure Limits Wisely: In certain modes (e.g., developer mode), recursion limits can be manually increased. Set conservatively.

๐Ÿ” How to Troubleshoot recursion_limit Errorsโ€‹

Follow these steps:

1. Check Invocation Logsโ€‹

  • Log into the Xpert AI Console
  • Navigate to the agent execution logs
  • Locate the faulty task and inspect the message chain

2. Identify Recursion Pathsโ€‹

  • Review model capabilities used by the agent
  • Check for circular invocation patterns, such as A โ†’ B โ†’ A โ†’ B โ†’ โ€ฆ

3. Check Condition Logicโ€‹

  • Verify whether stop conditions like if complete are functioning
  • Ensure conditional checks prevent redundant inferences

4. Fix and Testโ€‹

  • Modify the agent prompt or logic to avoid infinite loops
  • Monitor task logs to confirm if the recursion limit is still being triggered
  • In development or testing environments, advanced settings allow you to raise the recursion_limit
  • Always monitor logs and revert to a safe value once the issue is resolved

๐Ÿ“Œ Example Scenarios and Optimization Tipsโ€‹

ScenarioIssueOptimization Tip
Agent keeps rewriting the same responseNo stop conditionSet a max rewrite round limit (e.g., 3)
Multiple subtasks depend on each otherCircular dependencyDesignate one master agent to control task dispatching
Retry logic lacks a capInfinite retriesAdd a max retry counter

๐Ÿ“ž Need Help?โ€‹

If you're still unable to identify the issue, feel free to contact our technical support team. Weโ€™re here to assist with a step-by-step inspection of the agent behavior chain to ensure stable platform operation.