AutomationFlowsAI & RAG › AI Agent Chat with OpenAI

AI Agent Chat with OpenAI

Original n8n title: Agent Snippet

Agent Snippet. Uses httpRequest, lmChatOpenAi, agent. Manual trigger; 5 nodes.

Manual trigger★★★★☆ complexityAI-powered5 nodesHTTP RequestOpenAI ChatAgent
AI & RAG Trigger: Manual Nodes: 5 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow follows the Agent → HTTP Request recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "=https://dev.api.hybridtrader.ai/v1/webhooks/live-activity/ingest",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "activities",
              "value": "={{ $json.activities }}"
            }
          ]
        },
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1
            }
          }
        }
      },
      "id": "7d714a9b-c241-44d4-a261-a5a86d955733",
      "name": "POST to BFF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -816,
        240
      ]
    },
    {
      "parameters": {
        "jsCode": "// Parse the AI agent's output\nlet output = $input.first().json.output;\n\n// Remove any markdown code blocks if present\noutput = output.replace(/\\n?/g, '').replace(/```\\n?/g, '');\noutput = output.trim();\n\n// Parse the JSON array\nconst activities = JSON.parse(output);\n\n// Return each activity as a separate item (n8n requires json to be an object, not array)\nreturn activities.map(activity => ({ json: activity }));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1264,
        240
      ],
      "id": "7418f0e8-549f-4754-bb83-b64a397871c9",
      "name": "Parse JSON"
    },
    {
      "parameters": {
        "jsCode": "// Collect all activities from all items\nconst activities = $input.all().map(item => item.json);\n\n// Return single item with activities array\nreturn [{\n  json: {\n    activities: activities\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1040,
        240
      ],
      "id": "5537f21b-ee5a-4639-b0d6-09993874d894",
      "name": "Format Payload"
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "options": {
          "maxTokens": 4000,
          "temperature": 0.3
        }
      },
      "id": "d20efba8-7203-45cb-9967-28e13fd5b839",
      "name": "OpenAI Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        -1552,
        464
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Prepare Search Query').item.json.searchQuery }}",
        "options": {
          "systemMessage": "=Current Time: {{ $now.toISO() }}\n\n{{ $json.promptInput }}\n\nYou are a financial markets analyst. Curate a list of no more than 10 market-moving events that were published or posted within the last 12 hours from the input data. Do not use any new posts that were posted more than 12 hours ago\n\nBase events on typical market patterns:\n- Central bank announcements (Fed, ECB, BoE)\n- Economic data releases (inflation, employment, GDP)\n- Commodity movements (Gold, Oil, Silver)\n- Forex majors (EUR/USD, GBP/USD, USD/JPY)\n- Stock indices (S&P 500, NASDAQ, Dow)\n- Cryptocurrency (Bitcoin, Ethereum)\n- Geopolitical events\n\nFor each event:\n- Title: max 60 characters\n- Description: 100-200 characters\n- Type: NEWS, PRICE_ALERT, VOLATILITY_ALERT, EVENT_UPCOMING, or INSIGHT_UPDATE\n- Sentiment: BULLISH, BEARISH, NEUTRAL, or NONE\n- Timestamp: use times close to {{ $now.toISO() }}\n\nReturn ONLY a valid JSON array. No markdown, no code blocks:\n\n[\n  {\n    \"type\": \"NEWS\",\n    \"title\": \"Fed Rate-Cut Odds Surge\",\n    \"description\": \"Markets price in ~90% chance of 25 bps rate cut by the Federal Reserve next week\",\n    \"sentiment\": \"NEUTRAL\",\n    \"timestamp\": \"2025-12-05T14:30:00Z\"\n  }\n]"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        -1616,
        240
      ],
      "id": "f376b69c-e171-43b8-9484-dafc63e8433f",
      "name": "AI Agent"
    }
  ],
  "connections": {
    "POST to BFF": {
      "main": [
        []
      ]
    },
    "Parse JSON": {
      "main": [
        [
          {
            "node": "Format Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Payload": {
      "main": [
        [
          {
            "node": "POST to BFF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Parse JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Agent Snippet. Uses httpRequest, lmChatOpenAi, agent. Manual trigger; 5 nodes.

Source: https://github.com/firegenieuk/ht-bff/blob/db56af10cb387affe07b4b45d48cd9ae02eee8e3/n8n-workflows/old/agent_snippet.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Send one WhatsApp message → Get AI-optimized content across 7+ social platforms.

Output Parser Structured, Google Gemini Chat, OpenAI Chat +8
AI & RAG

This template is built for solo attorneys, small law firms, and legal billing coordinators who receive timesheet documents by email and need to produce LEDES-compliant e-billing files for client billi

Email Read Imap, Microsoft Excel, N8N Nodes Word2Text +4
AI & RAG

This workflow automates your entire sales outreach process across LinkedIn, Email, and WhatsApp using AI to create hyper-personalized messages for each prospect. Instead of spending hours crafting ind

Google Sheets, Gmail, Agent +4
AI & RAG

This is an elite-tier HealthTech solution designed for the secure processing of high-volume medical records. Monolithic EMR exports (often 200+ pages) are atomized into individual pages, allowing for

HTTP Request, Postgres, Google Drive +6
AI & RAG

LEAD RESEARCH ENRICHMENT. Uses stickyNote, toolSerpApi, lmChatOpenAi, outputParserStructured. Manual trigger; 19 nodes.

Tool Serp Api, OpenAI Chat, Output Parser Structured +3