How to use SerpAPI tool with AI Agent? AI Agent is not using it for search

Problem: AI chatbot that can search the web is not searching the web.

Using the n8n template (with no changes). Asked what are current (nov 2024) college football rankings. The query to SerpAPI was “query”: “November 2024 college football rankings”. The output was “response”: “{"title":"FBS I rankings"}”

The result from OpenAI was November 2023 CFP rankings.

In another example, I asked “What are some potential uses of AI Agents in 2025?”

In this case, SerpAPI was not even involved in the workflow.

Is there a way to force the AI Agent to use the tools? In this case, is there a way to force it to use SerpAPI? (Although, considering it’s response on CFP rankings, there isn’t anything to use.)

I’ve have multiple use cases for wanting to search the web and use the results in a workflow. My luck so far was a couple of different workflows with SerpAPI has not been very good.

Please share your workflow

The workflow is the exact same as the: AI chatbot that can search the web template.

{
“nodes”: [
{
“parameters”: {
“content”: “### The conversation history(last 20 messages) is stored in a buffer memory”,
“height”: 185,
“width”: 300
},
“id”: “3a3bcb2d-cb94-40d8-8b9e-322ea9d27f6e”,
“name”: “Sticky Note4”,
“type”: “n8n-nodes-base.stickyNote”,
“position”: [
640,
540
],
“typeVersion”: 1
},
{
“parameters”: {},
“id”: “e279af43-b003-4499-b221-58716e735379”,
“name”: “On new manual Chat Message”,
“type”: “@n8n/n8n-nodes-langchain.manualChatTrigger”,
“position”: [
380,
240
],
“typeVersion”: 1
},
{
“parameters”: {
“options”: {
“temperature”: 0.3
}
},
“id”: “f4f8bf03-a43e-4a1f-a592-cd0f8408f552”,
“name”: “Chat OpenAI”,
“type”: “@n8n/n8n-nodes-langchain.lmChatOpenAi”,
“position”: [
480,
560
],
“typeVersion”: 1,
“credentials”: {
“openAiApi”: {
“id”: “N20CD6FcL79RauXg”,
“name”: “OpenAi account”
}
}
},
{
“parameters”: {},
“id”: “66b60f68-bae8-4958-ac81-03883f563ab3”,
“name”: “Wikipedia”,
“type”: “@n8n/n8n-nodes-langchain.toolWikipedia”,
“position”: [
1120,
600
],
“typeVersion”: 1,
“disabled”: true
},
{
“parameters”: {
“content”: “### Tools which agent can use to accomplish the task”,
“height”: 185,
“width”: 300
},
“id”: “70f6b43b-9290-4fbc-992f-0895d4578c9f”,
“name”: “Sticky Note3”,
“type”: “n8n-nodes-base.stickyNote”,
“position”: [
980,
540
],
“typeVersion”: 1
},
{
“parameters”: {
“content”: "### Conversational agent will utilise available tools to answer the prompt. ",
“height”: 211,
“width”: 422
},
“id”: “8696269f-6556-41f1-bbe4-5597e4e46e02”,
“name”: “Sticky Note6”,
“type”: “n8n-nodes-base.stickyNote”,
“position”: [
600,
160
],
“typeVersion”: 1
},
{
“parameters”: {
“contextWindowLength”: 20
},
“id”: “6814967b-4567-4cdd-bf09-6b1b5ed0c68e”,
“name”: “Window Buffer Memory”,
“type”: “@n8n/n8n-nodes-langchain.memoryBufferWindow”,
“position”: [
740,
600
],
“typeVersion”: 1
},
{
“parameters”: {
“options”: {}
},
“id”: “ce4358ac-c2cc-45ba-b950-247f8360b36c”,
“name”: “SerpAPI”,
“type”: “@n8n/n8n-nodes-langchain.toolSerpApi”,
“position”: [
1000,
600
],
“typeVersion”: 1,
“credentials”: {
“serpApi”: {
“id”: “YrSqEaULxI1MxdTN”,
“name”: “SerpAPI account”
}
}
},
{
“parameters”: {
“promptType”: “define”,
“text”: “={{ $json.input }}”,
“options”: {}
},
“id”: “de80add8-c37d-4d46-80ec-b43234e21150”,
“name”: “AI Agent”,
“type”: “@n8n/n8n-nodes-langchain.agent”,
“position”: [
680,
240
],
“typeVersion”: 1.6
}
],
“connections”: {
“On new manual Chat Message”: {
“main”: [
[
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
},
“Chat OpenAI”: {
“ai_languageModel”: [
[
{
“node”: “AI Agent”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“Wikipedia”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Window Buffer Memory”: {
“ai_memory”: [
[
{
“node”: “AI Agent”,
“type”: “ai_memory”,
“index”: 0
}
]
]
},
“SerpAPI”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
}
},
“pinData”: {}
}



## Share the output returned by the last node
<!-- If you need help with data transformations, please also share your expected output. -->

## Information on your n8n setup

n8n version. Just signed up for free trial of cloud yesterday. So, presumably the latest release.
Free SerpAPI account.

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 @wergle,

I wasn’t able to directly access your current workflow, but I’ve created a similar workflow based on your use case. Feel free to take a look at that to see if it aligns with your requirements.

Regarding your query, please double-check if you’re using the OpenAI function agent correctly in the AI Agent node. This is crucial for the AI to respond properly.

To ensure the agent uses a specific tool, such as SerpAPI, there isn’t a direct option in n8n to force it. However, you can guide the AI by specifying this in the prompt itself. This will make sure the agent always uses the intended tool when responding.

Here’s a sample prompt you can use:

You are a helpful AI assistant. Always use the SERP API tool connected to you to answer the user’s query. Do not provide information based on assumptions or hallucinations; it is your responsibility to rely on the SERP API for accurate and real-time information. Whenever a user asks something, make sure to use the SERP API to retrieve the most relevant and up-to-date details.

Hello @Sudhanshu_Sharma

Thanks for looking into this for me!

Since I wrote it, I did add instruction in the prompt to tell the agent to use the SerpApi tool. I wasn’t as specific as you (especially the part about assumptions and hallucinations), but I did get better results. I will definitely go back and add your sample prompt (or something similar.)

I’m new to n8n. Coming from make.com and learning n8n as of yesterday.

Thanks again!

1 Like

Welcome to the n8n community @wergle!

I assure you, you will have great fun using n8n. :slight_smile:

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