Need help with a JS Function for AI

So I found this Reader and Search
and instead of using it as HTTP request I would like to use it as an JS Function in an AI Custom Code Tool.

  • in that case; the goal is to search the web :wink:

Here my JS based on API Form

fetch('', {
  method: 'GET',
  headers: {
  "X-Return-Format": "markdown",
  "Accept": "application/json"

But how could I …

  1. ensure my prompt use that function ?
  2. return the result and use it in my prompt

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:
1 Like

Hi @JOduMonT

That’s a really neat AI you found there :slight_smile:

So to answer your questions, you can use the AI Agent with the custom n8n Workflow tool, which will “outsource” the task to a sub-workflow using the HTTP request node. This way you should have better control over the request and also add authentication if necessary.

Then you could use the returned response for the 2nd tool (Custom Code Tool) for your further coding endeavors. It’s important to rename the output of the HTTP Request node to response so that the agent can read it.

We made a little example workflow below to demonstrate (using some simple upperCase() functionality for the code as example).

The importance here is that you structure the prompt in the AI Agent well enough, that it will use the tools correctly.

So the prompt we gave to the Agent was:

And then name the tools accordingly, so the Agent will recognize them.


I hope this helps and let us know how you get on! :bird:


PS. This could be a cool template when you’re done!
Make sure to check out our creator platform and keep us posted! :robot:

1 Like

well; while it work :wink: thanks for that it gave me new idea

the result is not as expected

  1. if I ask a full sentence question; it should use AI to reconize only the keywords and send them to instead of the whole sentence.
  2. OpenAI still give me hold information (embedded in his model) instead of considering the info found on the internet.
  • IE: Such as I wrote Rolland Garros in the chat and it gave me info about Rolland Garros 2023 while clearly return 2024 infos.