How to Link Function Node with HTTP Request in AI Agent Workflow

I’m pretty new to n8n and programming overall, so this is probably a basic question. I can’t figure out how to link a Function node to an HTTP Request node when working inside an AI Agent workflow.

What I’m trying to do is make an HTTP call to the Google Places API to find new restaurants in my area. After getting the response, I want to use a Function node to filter the data so it only shows places with ratings above 4 stars and limits the results to just the top 10 entries. Everything I’ve read suggests connecting the HTTP Request node to a Function node for data processing, but I’m having trouble making this connection work in this specific setup.

Is there a special way to chain these nodes together when they’re part of an AI Agent? Any help would be great since I’m stuck on this step.

Connecting HTTP Request nodes to Function nodes in AI Agent workflows works differently than regular n8n setups. You’ll need to configure your Function node to pull data from the HTTP Request output. Access the response data through the items array and ensure your filtered results are correctly formatted for the next stage in the AI Agent. Be mindful of Google Places API responses, as they can often be nested and may lack ratings data, which could lead to issues during execution.

The problem is that AI Agent workflows handle node connections through data references, not visual connections. You can’t just connect nodes visually - you need to access the previous node’s output data programmatically in your Function node. Reference the HTTP Request node output using the node name or position. Google Places API puts restaurant data under the ‘results’ key, so target that path specifically. Make sure your Function node returns data wrapped in JSON objects like n8n expects. AI Agent workflows are pickier about data formatting between nodes than regular workflows. Double-check your filtered results keep the structure the workflow needs. Test your filtering logic with console.log statements first to verify you’re actually getting the data you expect from Google’s response.

Had this exact problem when setting up location workflows last year. AI Agent workflows don’t work like normal drag-and-drop connections.

You’ve got to explicitly reference the HTTP Request output in your Function node. Use $input.all() to grab the Google Places response, then filter:

const places = $input.all()[0].json.results;
const filtered = places
  .filter(place => place.rating && place.rating > 4)
  .slice(0, 10);

return filtered.map(place => ({json: place}));

Big gotcha - name your HTTP Request node clearly. AI Agents get confused with unnamed nodes. Also, Google Places API sometimes returns places without ratings, so that filter check saves you.

Connection works fine once you reference the previous node output correctly in your Function code.