I want to implement an ai agent which is using another implemented workflow as a tool.
Everything works, the workflow is called successfully, but the tool node within the main workflow fails with error message: There was an error: “The workflow did not return a response”.
When I look into executions of the (sub-) workflow, it was executed successfully and returned an respose.
I invested already hours into that problem without any progress. Tried a SET Node instead of a Code node as last node within the sub-workflow, same result.
I don`t want to implement a HTTP Request, because the sub-workflow will only be used n8n internal.
Even if your sub-workflow runs successfully and ends with a Set or Code node, the AI Agent still shows this kind of error.
This is because when a sub-workflow is invoked as a tool, it expects a proper response structure.
This behavior has been observed and discussed in the community previously:
Use “Respond to a Webhook” node (Respond to Webhook | n8n Docs) to control the response to incoming webhooks. Try to set “First incoming Item” as response
If you want to preserve the json object, you’ll need to use a Structured output on the agent.
If no structured output, it’ll try and use something valuable from the response, else if structured, it’ll just return what the sub node produces (a json object in this case)
Its difficult to understand your problem without a workflow. Can you share the workflow in a code block? My example returns data from the sub node, so there must a problem somewhere in your workflow
I solved my issue. It was nothing related to the AI Agent itself, or the combination with “Execute Sub-Workflow”. It was just related to an error-prone workflow architecture.
Problem: In my workflow I had 2 parallel Workflow Streams after an implemented switch node, which both resulted later again in one “Code Node”.
The assumption, that my java script code with .all()
deals with these potential race conditions was just wrong.
Implementing a “Merge Node” just before the Code Node which delivers also the final result solved everything.