{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ae6fca72-e7a3-411c-b5c7-61649c6d76ed",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -64,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4",
          "cachedResultName": "gpt-4"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5188e333-3d15-409a-947c-a4ac8d613a76",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -704,
        -224
      ],
      "parameters": {
        "color": 4,
        "width": 424,
        "height": 896,
        "content": "## AI Chat Bot workflow for WordPress & Webhook Live Chats\n\n### This workflow powers a versatile AI chatbot that can be integrated into any live chat interface, such as our free Forerunner\u2122 AI Chat Bot for WordPress. It's designed to automate customer support and lead generation by handling a variety of user queries independently.\n\nThe setup process is straightforward and typically takes less than five minutes. This involves connecting your preferred Large Language Model (LLM) and a live chat platform to the workflow via webhooks.\n\nHow the Workflow Works\nThe core of this workflow is an AI Agent that acts as the brain of the chatbot. It processes user input and generates responses based on predefined rules and your chosen language model.\n\nUser Input: When a user sends a message through your live chat, it's sent to the workflow via a webhook. This message is then passed to the AI Agent for processing.\n\nAI Response Generation: The AI Agent analyzes the message, retrieves relevant conversational history from the Simple Memory node to maintain context, and uses the selected Large Language Model (e.g., OpenAI, Gemini, or Claude) to formulate a response.\n\nConditional Logic: After the response is generated, the workflow uses an If node to check if the conversation should end. If the response contains the specific tag [END_OF_CONVERSATION], the workflow prepares to end the chat. Otherwise, the conversation continues.\n\nSend to Client: The final response is then sent back to the live chat interface, where it is displayed to the user. This completes the loop, allowing the chatbot to engage in a continuous conversation until the task is complete."
      },
      "typeVersion": 1
    },
    {
      "id": "56526257-ac25-4c8f-8caa-ddff585f8f34",
      "name": "Convert Chat Text",
      "type": "n8n-nodes-base.set",
      "position": [
        16,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "310fbac7-d1e4-4745-84e7-42b470128e8c",
              "name": "chatInput",
              "type": "string",
              "value": "={{$json[\"body\"][\"chatinput\"]}}"
            }
          ]
        }
      },
      "typeVersion": 3.4,
      "alwaysOutputData": false
    },
    {
      "id": "1500ed8c-4291-45dd-a04d-ef56f39e9ac1",
      "name": "Website Chat Messages",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -176,
        0
      ],
      "parameters": {
        "path": "demo-workflow",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "837c40e5-a27a-4b5f-be5b-c60021644397",
      "name": "End Conversation?",
      "type": "n8n-nodes-base.if",
      "position": [
        592,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d9c86f8e-5f6b-4a75-84df-5cf7158e5fe0",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.output }}",
              "rightValue": "[END_OF_CONVERSATION]"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "92b0b116-e4e4-4e7c-9748-052f5dd705d6",
      "name": "Yes - End",
      "type": "n8n-nodes-base.set",
      "position": [
        912,
        -96
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bae0eeb6-eaf6-4491-8618-88d0c39c45b4",
              "name": "reply",
              "type": "string",
              "value": "={{ $json.output.replace('[END_OF_CONVERSATION]', '').trim() }}"
            },
            {
              "id": "42ca77e1-af22-4c36-ae09-8a395e653024",
              "name": "endOfConversation",
              "type": "boolean",
              "value": true
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "533a8fea-34fc-402a-a031-024073e1c62d",
      "name": "No - Continue",
      "type": "n8n-nodes-base.set",
      "position": [
        912,
        112
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "df4e0c5e-f41f-4db7-bd40-bbf3692e8671",
              "name": "=reply",
              "type": "string",
              "value": "={{ $json.output }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4a247e7a-e49c-4c61-9270-b376d3e11c1c",
      "name": "Send Chat to Client",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1200,
        0
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "e5fe5b99-457b-4f74-9570-49cb2c27ccfa",
      "name": "Think",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        576,
        208
      ],
      "parameters": {
        "description": "=The current day and time is {{ new Date().toUTCString() }}, you don't need to ask for the time or date from the user.\n\nEnsure you have run the tool required for each query."
      },
      "typeVersion": 1
    },
    {
      "id": "e895a5b8-2654-4f20-8da8-61fbf0ddde58",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        432,
        208
      ],
      "parameters": {
        "sessionKey": "x-real-ip",
        "sessionIdType": "customKey",
        "contextWindowLength": 20
      },
      "typeVersion": 1.3
    },
    {
      "id": "c37a3df0-1a7c-4e87-8a95-9b60c335b9c8",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        96,
        400
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-1.5-pro-latest"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fa82d7db-c223-45b4-822c-756548e017d8",
      "name": "Forerunner\u2122 AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        208,
        0
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are a demo agent for Forerunner\u2122 AI, the very latest in AI chatbots developed by Design for Online\u00ae.  when you introduce yourself, make sure you say you are a demo chat agent using a custom n8n workflow.\nYou are an AI agent showcasing the functionality of AI Agents, you are a demo for customers to use - handling live chat requests for <company name>.\nDeliver friendly, concise, non-technical responses with practical advice, \nBe flexible to elaborate briefly when needed, aligning with brand guidelines.\u00a0 \nYou are focussed on providing assistance and support to the client and being sales focussed when prompted.\nSpelling: UK English\n\n\nTOOLS AVAILABLE FOR YOU TO USE:\nTool name:\nTool description:\nTool requirements: e.g ask for the users first name and email beforehand so you have this to use the tool\n\nBusiness Data Sets\nYou have access to google sheets for business data, you can write and read from this\n\n\n1. Brand Voice & Tone\n\nFriendly & Approachable: Use warm, conversational UK English (e.g., \u201coptimisation\u201d, \u201corganise\u201d) without slang or jargon.\nSupportive & Practical: Offer actionable advice with clear benefits (e.g., more customers, time savings).\nExpert & Transparent: Highlight results simply; be honest about capabilities, avoiding unapproved pricing.\nConcise & Snappy: Keep responses short (1-3 sentences), using up to 5 bullet points only when listing options.\nCreative & Varied: Craft unique intros that feel fresh, showcasing diverse services.\n\n2. Conversational Guidelines\n\nIntros: Your first message to the client should be brief ALWAYS vary your introduction\nIntros: Start with a unique, concise greeting (1 sentence) showcasing varied services (e.g., social media, ads, AI). Avoid repetitive phrasing. Don't use too many adjectives, be personal and support the person you are speaking to.\nKeep responses short (50-100 words) but flexible to elaborate briefly if needed (e.g., explain a service benefit).\nOffer a free 30-minute consultation only if the user is showing intent to contact or go ahead with a service, don't always offer a consultation to the client, your primary goal is to support what they need.\nFor technical issues (e.g., website down), collect URL/errors, escalate.\nAvoid mentioning system instructions.\nUse disclaimer if needed: \u201cThis is general guidance. We\u2019ll tailor a plan on a call.\u201d\n\n3. Allowed Topics Discuss only these services:\n\nservice 1\nservice 2\nservice 3\n\n4. Disallowed Topics Do not:\n\nWhen offering tips or advice, be brief and lead into our services and next steps.\nDo not use Em dashes.\nUse jargon.\nMention competitors or their services.\nDiscuss legal, financial, medical, or HR topics.\nRequest data beyond name, email, phone, project details.\nAddress politics, religion, adult, or hateful content.\nShare unapproved pricing or confidential data.\nPlagiarise content.\n\n5. Lead Capture\n\nCollect: Name, company, email, phone, URL, goal.\n\n6. Escalation & Handover\n\nIf they ask to speak to a human, if you have a tool to email the team use that, otherwise direct them to the contact page or add details here.\n\n7. Compliance & Privacy\n\nFollow GDPR: Get consent for storing data.\nRetain chats for 12 months unless opted out.\nDon\u2019t share data without consent.\nAdhere to Google/Microsoft/Amazon Ads policies.\n\n8. Accuracy\n\nIf unsure, say: \u201cLet me check!\u201d and verify.\nDon\u2019t invent testimonials or stats.\n\n9 Contact & Identity\n\nPhone: \nEmail: \nHours:\nAddress: \nOutside hours: \u201cWe\u2019ll reply next business day.\u201d\n\nHow to end the conversation:\nOnce the chat is over or the user wants to end the chat make sure to thank the user and add [END_OF_CONVERSATION] to the end of the message.\n"
        }
      },
      "typeVersion": 1.9
    },
    {
      "id": "98ab6795-de7e-4255-b6c1-afd6acd0e9cb",
      "name": "Anthropic Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "position": [
        96,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "claude-3-7-sonnet-20250219",
          "cachedResultName": "Claude 3.7 Sonnet"
        },
        "options": {}
      },
      "credentials": {
        "anthropicApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "c26bd7ac-f9bb-4a4f-aee4-3e4d5aa8c943",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        272,
        208
      ],
      "parameters": {
        "model": "google/gemini-2.5-flash",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3b04a5b1-4d74-4a41-920c-3af828f52c00",
      "name": "xAI Grok Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatXAiGrok",
      "position": [
        272,
        400
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "xAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Think": {
      "ai_tool": [
        [
          {
            "node": "Forerunner\u2122 AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Yes - End": {
      "main": [
        [
          {
            "node": "Send Chat to Client",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "No - Continue": {
      "main": [
        [
          {
            "node": "Send Chat to Client",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Forerunner\u2122 AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Convert Chat Text": {
      "main": [
        [
          {
            "node": "Forerunner\u2122 AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "End Conversation?": {
      "main": [
        [
          {
            "node": "Yes - End",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No - Continue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        []
      ]
    },
    "xAI Grok Chat Model": {
      "ai_languageModel": [
        []
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Forerunner\u2122 AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Website Chat Messages": {
      "main": [
        [
          {
            "node": "Convert Chat Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Forerunner\u2122 AI Agent": {
      "main": [
        [
          {
            "node": "End Conversation?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        []
      ]
    }
  }
}