Max iterations reached allthough nothing seems to happen during each iteration

I am using an AI Agent with openrouter model kwaipilot/kat-coder-pro:free and tools (duckduckgo) and from time to time I am getting “Max Iterations (20) reached”.

I can understand that the AI Agent is stopping after a number of iterations but it seems that nothing is really happening for all these iterations except the first 2.

Here the execution:

So the “MCP Client” is properly calling Duckduckgo to retrieve information from 10 different sites but then all the iterations after that don’t seem to do anything really:

  • at least if I check the input of the last iteration it looks pretty the same as the input for the first iteration.
  • Here below you see the output of the last iteration:

This issue typically occurs when the AI Agent is stuck in a loop, unable to find a satisfactory response or action to take. Here’s how you can address it:

1. **Check the Prompt**: Ensure the initial prompt is clear and specific. Vague prompts can lead to the AI Agent repeatedly searching without finding useful information.

2. **Adjust Iteration Limit**: You can increase the iteration limit in the AI Agent node settings if you believe more iterations could yield better results.

3. **Add Constraints**: Use tools like the `Output Parsing` node or `Function` node to add constraints or conditions that prevent the AI Agent from continuing unnecessary iterations.

4. **Debug Outputs**: Inspect the outputs of each iteration to identify if the AI Agent is getting stuck on a particular step. You can use the `Function` node to log intermediate results.

If the issue persists, consider simplifying the workflow or breaking it into smaller, more manageable steps. Share your workflow JSON if you need further assistance!