{
  "name": "Chatbot with Conversation Memory",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "chat",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "cwm0001-0001-4000-8000-000000000001",
      "name": "Chat Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.body.sessionId }}",
        "contextWindowLength": 10
      },
      "id": "cwm0001-0002-4000-8000-000000000002",
      "name": "Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1,
      "position": [460, 180]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list"
        },
        "options": {
          "systemMessage": "You are a helpful AI assistant. Use the conversation history to provide contextually relevant answers. Be concise and friendly.",
          "temperature": 0.7
        }
      },
      "id": "cwm0001-0003-4000-8000-000000000003",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1,
      "position": [680, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "reply",
              "value": "={{ $json.output }}",
              "type": "string"
            },
            {
              "name": "sessionId",
              "value": "={{ $('Chat Webhook').item.json.body.sessionId }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "cwm0001-0004-4000-8000-000000000004",
      "name": "Format Reply",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [900, 300]
    }
  ],
  "connections": {
    "Chat Webhook": {
      "main": [[{ "node": "AI Agent", "type": "main", "index": 0 }]]
    },
    "Conversation Memory": {
      "main": [[{ "node": "AI Agent", "type": "main", "index": 0 }]]
    },
    "AI Agent": {
      "main": [[{ "node": "Format Reply", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {},
  "pinData": {}
}
