"Agent has stopped due to max iterations" error message

Working through Competitor Research Workflow and I continue to get an error message

Agent has stopped due to max iterations

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Karthik_Shetty

1. Add Break Clauses for Agents

I find this error is common with agents with tools like web scrapers; basically means the agent doesn’t know when to stop or if it should stop after a certain amount of attempts or duration.

For an (extreme) example scenario: if you tell the agent to scour a website looking for contact details, the common assumption is it’ll stop once it collected the ones off the contact page. Technically speaking though, it could be interpreted that you intended to fetch every page of the site; blog, documentation, social media etc. until you’ve exhausted every possible resource.

One fix you could try is to define limits, caps or break clauses for the agent:

  • “fetch a max of 5 contacts.”
  • “fetch a max of 5 C-suite level contacts.”
  • “follow links no more then 1 level deep.”
  • “after the 3rd attempt, give up and proceed to the next step.”
  • “if you receive no response, do not attempt to visit the link again.”
  • “call this tool only if you have a valid email address”

2. Increase Max Iterations

The other problem could be that the agent has too many tools for the default max iterations value. The default max iterations value for AI agents was presumely decided for the 1-3 tools scenario (happy to be corrected!) which is sensible.

For this particular workflow where you might desire much more frequent tool usage ie. aggressive scraping, you can try increasing the max iteration option to see if that helps. Be warned however that this is akin to opening up the firehose on unsuspecting sites and could get your IP blacklisted!

3. Try Smaller Mini-Agents

Finally, there’s nothing to stop you from breaking up these tool agents into smaller ones. This way the max interations are not shared between multiple tools. Sure your workflow does get a little bit messy but I find smaller agents working easier to debug when things go wrong.

Hope this helps!
Jim

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.