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โ
- Clarify the Task Flow: Ensure that the task call paths are convergent, not infinite loops.
- Implement Exit Mechanisms: Define stop conditions in agent logicโe.g., max rounds reached, goal achieved, confidence no longer improving.
- Avoid Unnecessary Nesting: Minimize deep call chains. Prefer flat, modular agent designs with clear responsibilities.
- 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
5. Temporarily Increase the Limit (Not Recommended for Production)โ
- 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โ
Scenario | Issue | Optimization Tip |
---|---|---|
Agent keeps rewriting the same response | No stop condition | Set a max rewrite round limit (e.g., 3) |
Multiple subtasks depend on each other | Circular dependency | Designate one master agent to control task dispatching |
Retry logic lacks a cap | Infinite retries | Add 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.