AI Agent Workflow: Passing data between ai_tool nodes (SerpAPI to Code Tool)
Hi n8n community,
I’m working on an AI Agent workflow where the agent needs to use a Fallback - Enrich with Google Search (SerpAPI) tool and then process its output with a Code Tool.
Both the SerpAPI tool and the Code Tool are connected to the AI Agent - Lead Collection node as ai_tool connections (dashed lines), meaning the AI Agent orchestrates their use.
The core problem: I cannot draw a direct solid connection line from the Fallback - Enrich with Google Search node to the Code Tool (or to a Set node in between) because the Fallback node, when used as an ai_tool, doesn’t seem to have a direct sequential output for items[].
My understanding is that the AI Agent itself needs to handle the data transfer:
- The
AI Agentcalls theFallback - Enrich with Google Searchtool. - The
AI Agentreceives the output from theFallbacktool. - The
AI Agentthen needs to pass this output as an argument to theCode Toolwhen calling it.
I’ve tried adjusting the AI Agent’s systemMessage to instruct it to perform this sequence (e.g., “Upon receiving results from Fallback, pass them to Code Tool”). I’ve also adjusted the Code Tool to receive data as an argument (e.g., const raw = data; instead of $input.first()).
My questions are:
- Is this the correct approach for handling data flow between
ai_toolnodes orchestrated by anAI Agent? - Are there specific prompt engineering techniques or best practices for the
AI Agent’ssystemMessageto ensure it correctly passes the output from oneai_toolto another? - How should the
Code Toolbe structured to reliably receive this data when it’s passed as an argument by theAI Agent?
Any guidance or examples on this inter-tool data transfer within an AI Agent’s orchestration would be greatly appreciated!
Thanks in advance!