Agent with custom HTTP Request n8n Workflow Template

n8n workflow template · 16 nodes · OpenAI

Agent with custom HTTP Request is a free n8n workflow template that starts from a chat message in the n8n editor and works with OpenAI. It has 16 nodes, 4 of them AI nodes (Manual Chat Trigger, OpenAI Chat Model, AI Agent and Call n8n Workflow Tool). To run it, you add your own credentials for OpenAI API.

At a glance

Trigger
Manual Chat Trigger (On new manual Chat Message)
Nodes
16
Apps
OpenAI
AI nodes
4
Credentials
1 type
Category
AI agents and LLM tools

Apps and integrations

  • OpenAI

Node types used

  • Manual Chat Trigger
  • OpenAI Chat Model
  • HTTP Request
  • Edit Fields (Set)
  • If
  • Execute Workflow Trigger
  • AI Agent
  • Markdown
  • Call n8n Workflow Tool

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Example ReAct AI Agent

  1. Agent Prompt is default
  2. Check the description of the HTTP_Request_Tool, it guides the agent to provide a query string with several parameters instead of a JSON object

Convert the query string into JSON, apply the limit for a page length

Send an error message

  1. If query param was incorrect, return the instruction. AI Agent should pick up on this and adapt the query on the next iteration.
  2. If the query is OK and an error was during the HTTP Request, then send back the original error message.

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Post-processing of the HTML page

  1. Keep only content
  2. Remove inline tag entirely, as well as: NOSCRIPT, IFRAME, OBJECT, EMBED, VIDEO, AUDIO, SVG, and HTML comments.
  3. In case query parameter method=simplified, replace all page URLs (a href) and IMG (src) with NOURL / NOIMG - this may save up to 20% of the page length
  4. Convert the remaining HTML to Markdown. This step further reduces the length of the page: long HTML tags and styles are eliminated, but the markdown syntax keeps some page structure. This gives much better results compared to just a blank text.
  5. Finally, check the page length. If it's too long, send an "ERROR: PAGE CONTENT TOO LONG" instead of the actual page. Of course, you could split the page content in chunks, but sometimes long pages just don't have a needed content, so it makes little sense to burn tokens on them.

Nodes in this workflow

The 16 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. On new manual Chat Message (Manual Chat Trigger)
  2. OpenAI Chat Model (OpenAI Chat Model)
  3. HTTP Request (HTTP Request)
  4. Exctract HTML Body (Edit Fields (Set))
  5. Is error? (If)
  6. Stringify error message (Edit Fields (Set))
  7. Execute Workflow Trigger (Execute Workflow Trigger)
  8. Remove extra tags (Edit Fields (Set))
  9. Simplify output (Edit Fields (Set))remove links and image URLs
  10. Simplify? (If)
  11. QUERY_PARAMS (Edit Fields (Set))
  12. CONFIG (Edit Fields (Set))
  13. ReAct AI Agent (AI Agent)
  14. Convert to Markdown (Markdown)
  15. Send Page Content (Edit Fields (Set))
  16. HTTP_Request_Tool (Call n8n Workflow Tool)

Credentials you need

  • OpenAI API – used by OpenAI Chat Model

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us