{
  "name": "Create a human-like Evolution API WhatsApp agent with Redis, PostgreSQL and Gemini",
  "nodes": [
    {
      "id": "3068fa7a-cd7a-400e-915f-7c78dc041770",
      "name": "Descargar Media",
      "type": "n8n-nodes-evolution-api.evolutionApi",
      "position": [
        4400,
        1360
      ]
    },
    {
      "id": "27793e12-a412-418f-9836-5ff216eadf22",
      "name": "get_message (text)",
      "type": "n8n-nodes-base.set",
      "position": [
        4400,
        1024
      ]
    },
    {
      "id": "631fd381-296e-4434-9ae0-f13383adb95a",
      "name": "Message Type",
      "type": "n8n-nodes-base.switch",
      "position": [
        4160,
        1168
      ]
    },
    {
      "id": "40f61960-a240-41f3-b84c-6c29197807ba",
      "name": "Global Variables",
      "type": "n8n-nodes-base.set",
      "position": [
        3840,
        1184
      ]
    },
    {
      "id": "25d687a5-4ffc-405e-b56e-03013a894f0e",
      "name": "Buffer Route",
      "type": "n8n-nodes-base.switch",
      "position": [
        6048,
        1712
      ]
    },
    {
      "id": "a5a4181c-f1f6-495a-a32f-f7969764adc0",
      "name": "Push to Buffer",
      "type": "n8n-nodes-base.redis",
      "position": [
        5648,
        1728
      ]
    },
    {
      "id": "bccf8f52-62cb-4dc8-ba36-b001ce06848d",
      "name": "Get From Buffer",
      "type": "n8n-nodes-base.redis",
      "position": [
        5856,
        1728
      ]
    },
    {
      "id": "6e249e0a-e145-435a-825c-0246f7091b84",
      "name": "Delete Buffer",
      "type": "n8n-nodes-base.redis",
      "position": [
        6272,
        1728
      ]
    },
    {
      "id": "2a44f7ed-fe21-4173-9e5b-56349a996114",
      "name": "Normalize Buffer",
      "type": "n8n-nodes-base.set",
      "position": [
        6480,
        1728
      ]
    },
    {
      "id": "c77dff93-f6dc-4a9f-93e1-de98605e0218",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        6272,
        1568
      ]
    },
    {
      "id": "3fda8031-85c3-4301-8d8c-0e80583a5a40",
      "name": "Push to Buffer (AlbumGroup)",
      "type": "n8n-nodes-base.redis",
      "position": [
        4400,
        1184
      ]
    },
    {
      "id": "25e20eb6-c442-41bc-82dd-a594d4404010",
      "name": "Check AlbumGroup",
      "type": "n8n-nodes-base.redis",
      "position": [
        5232,
        1728
      ]
    },
    {
      "id": "d67f6545-0abb-4037-9a03-1c2e5c4bea10",
      "name": "Push Media to Buffer",
      "type": "n8n-nodes-base.redis",
      "position": [
        5648,
        1408
      ]
    },
    {
      "id": "bdc2da23-51dc-4ae8-8b43-9182aaddf377",
      "name": "Completed?",
      "type": "n8n-nodes-base.if",
      "position": [
        6048,
        1408
      ]
    },
    {
      "id": "66c2b5ea-2317-4264-8e5a-eba4a4af0ae8",
      "name": "Delete Media Buffer",
      "type": "n8n-nodes-base.redis",
      "position": [
        6272,
        1392
      ]
    },
    {
      "id": "d4506ca4-13b6-4e05-8360-d05654217636",
      "name": "Normalize MediaGroup Buffer",
      "type": "n8n-nodes-base.set",
      "position": [
        6480,
        1392
      ]
    },
    {
      "id": "f239e9f7-df49-4594-b9c4-9eab0d2344d7",
      "name": "Get Album From Buffer",
      "type": "n8n-nodes-base.redis",
      "position": [
        5856,
        1408
      ]
    },
    {
      "id": "bc745d6b-701a-46f7-8892-7ef1006b13a8",
      "name": "Album?",
      "type": "n8n-nodes-base.if",
      "position": [
        5440,
        1552
      ]
    },
    {
      "id": "4b5145e3-fc86-4f75-b4cc-1f83a82f6232",
      "name": "Get Message",
      "type": "n8n-nodes-base.set",
      "position": [
        6768,
        1552
      ]
    },
    {
      "id": "3d184031-6dde-42e1-a491-09225e94a936",
      "name": "Delete Buffer (chat_history)",
      "type": "n8n-nodes-base.redis",
      "position": [
        11296,
        1616
      ]
    },
    {
      "id": "f8e13e3d-1963-42b5-af32-638221abc74f",
      "name": "Wait For User Other Fast Message",
      "type": "n8n-nodes-base.wait",
      "position": [
        6272,
        1888
      ]
    },
    {
      "id": "c04113d1-4f5f-4278-9059-471fe6bf0ed6",
      "name": "Get chat_history",
      "type": "n8n-nodes-base.set",
      "position": [
        8544,
        1504
      ]
    },
    {
      "id": "d0fa7a20-9ff9-4094-ae2e-5ca4d64b3e99",
      "name": "No Operation, do nothing1",
      "type": "n8n-nodes-base.noOp",
      "position": [
        11296,
        1472
      ]
    },
    {
      "id": "ef4c0c24-0c33-4757-bbc6-726e36570127",
      "name": "Buffer (chat_history) Route",
      "type": "n8n-nodes-base.switch",
      "position": [
        11040,
        1488
      ]
    },
    {
      "id": "6256a7ad-6b16-4d37-bece-f87fc3b89eaf",
      "name": "Wait For end of conversation",
      "type": "n8n-nodes-base.wait",
      "position": [
        11296,
        1792
      ]
    },
    {
      "id": "dbb2d1d0-18d3-4c34-a9b0-e8ba0abd1917",
      "name": "Push to Buffer (chat_history)",
      "type": "n8n-nodes-base.redis",
      "position": [
        10608,
        1504
      ]
    },
    {
      "id": "5dc4db3a-4cb6-4f75-a8c6-56514137750c",
      "name": "Get From Buffer(chat_history)",
      "type": "n8n-nodes-base.redis",
      "position": [
        10848,
        1504
      ]
    },
    {
      "id": "acdb096a-64be-473c-8bc9-9b4e01315677",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        8976,
        1696
      ]
    },
    {
      "id": "fd1118a6-8586-42c1-8f5a-178866deece5",
      "name": "Delete Buffer (chat_history)2",
      "type": "n8n-nodes-base.redis",
      "position": [
        11488,
        1616
      ]
    },
    {
      "id": "c9a89669-a7a1-4d6e-af94-8241a993a9ca",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        3344,
        1184
      ]
    },
    {
      "id": "6c6db252-8067-4c8e-9ba2-7280e280aedb",
      "name": "Read Messages",
      "type": "n8n-nodes-evolution-api.evolutionApi",
      "position": [
        3648,
        320
      ]
    },
    {
      "id": "0f3d5ec8-cc88-4d6d-9f1e-cd31ea4b0980",
      "name": "Open session",
      "type": "n8n-nodes-evolution-api.evolutionApi",
      "position": [
        3648,
        128
      ]
    },
    {
      "id": "bd1017ec-e1b3-4e75-b6c1-a2b1eea076b0",
      "name": "Get chat_history From DataBase",
      "type": "n8n-nodes-base.postgres",
      "position": [
        7600,
        1776
      ]
    },
    {
      "id": "4c8f523a-4933-4c82-892b-0c3820fdfe63",
      "name": "Aggregate all Messges",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        7792,
        1776
      ]
    },
    {
      "id": "3cf1c290-c7c8-4452-a6e0-f7ac9386ab2a",
      "name": "chat_history In Buffer?",
      "type": "n8n-nodes-base.if",
      "position": [
        7424,
        1552
      ]
    },
    {
      "id": "6ad75b38-34bd-46d2-b54b-455534e83630",
      "name": "Writting...",
      "type": "n8n-nodes-evolution-api.evolutionApi",
      "position": [
        3856,
        512
      ]
    },
    {
      "id": "1694ed3c-d7ed-4ddc-8912-164d18975fc1",
      "name": "Create Table chat_history",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3536,
        -208
      ]
    },
    {
      "id": "c8a87e0c-b693-4e2f-aebf-ceaaceb29595",
      "name": "Send Response",
      "type": "n8n-nodes-evolution-api.evolutionApi",
      "position": [
        9856,
        1504
      ]
    },
    {
      "id": "dc6711be-d817-4e09-b0b5-a8a663607ad2",
      "name": "Extract from CSV",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3712,
        2160
      ]
    },
    {
      "id": "9c1a51b8-b00a-46a5-b9e4-597387417af1",
      "name": "Extract from ICS",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3712,
        2448
      ]
    },
    {
      "id": "91cb3721-2940-4faf-b675-3dbb2634840d",
      "name": "Extract from JSON",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3712,
        2592
      ]
    },
    {
      "id": "2567e452-58e8-416e-888b-9e05b9090163",
      "name": "Extract from ODS",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3712,
        2736
      ]
    },
    {
      "id": "9ee5e360-3992-4f7d-b6ae-246b78c8fa35",
      "name": "Extract from PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3712,
        2896
      ]
    },
    {
      "id": "99943307-996c-4a3b-9e62-8a2126e31819",
      "name": "Extract from RTF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3712,
        3200
      ]
    },
    {
      "id": "b0fe80d5-7480-4682-8387-8cd84393b32a",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3712,
        3344
      ]
    },
    {
      "id": "ee2b462b-c577-41a1-8679-f6c571a09159",
      "name": "Extract from XLSX",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3712,
        3632
      ]
    },
    {
      "id": "b4b638ed-5b5a-4468-b4a4-b7f27b808871",
      "name": "Analyze audio",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        3712,
        1856
      ]
    },
    {
      "id": "27d98d0d-58b8-443d-9d34-f1d0fb9a4516",
      "name": "get_message (File message)",
      "type": "n8n-nodes-base.set",
      "position": [
        4544,
        2576
      ]
    },
    {
      "id": "f765c4c8-d702-470b-b810-7f3004d9fa08",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        3888,
        2160
      ]
    },
    {
      "id": "e502ef06-bca0-453a-8894-0affaff2fa3e",
      "name": "get_error_message",
      "type": "n8n-nodes-base.set",
      "position": [
        3712,
        3792
      ]
    },
    {
      "id": "9d472f84-1ef1-40cb-82e7-719fd7000fcb",
      "name": "HTML Extract Generic1",
      "type": "n8n-nodes-base.html",
      "position": [
        3712,
        2304
      ]
    },
    {
      "id": "82f4508c-aca2-4b74-b7e7-61641c2449a2",
      "name": "Get ODS data",
      "type": "n8n-nodes-base.code",
      "position": [
        3888,
        2736
      ]
    },
    {
      "id": "d8f16a0d-0273-41c9-89ad-14a9a21a4875",
      "name": "Normalize ODS",
      "type": "n8n-nodes-base.set",
      "position": [
        4048,
        2736
      ]
    },
    {
      "id": "e940c6a8-f313-4ee5-aa4e-02dcc7168d44",
      "name": "Normalize CSV",
      "type": "n8n-nodes-base.set",
      "position": [
        4048,
        2160
      ]
    },
    {
      "id": "71f490ba-61a1-4737-875c-e1fdb3d15154",
      "name": "Normalize HTML",
      "type": "n8n-nodes-base.set",
      "position": [
        3888,
        2304
      ]
    },
    {
      "id": "e2c39585-31a4-48f1-ab2e-d127e55601b2",
      "name": "Normalize ICS",
      "type": "n8n-nodes-base.set",
      "position": [
        3888,
        2448
      ]
    },
    {
      "id": "b58a311a-94f0-4098-a8a6-170c140bd8b3",
      "name": "Normalize JSON",
      "type": "n8n-nodes-base.set",
      "position": [
        3888,
        2592
      ]
    },
    {
      "id": "acd71229-d42f-465d-94bf-7dfb778703d1",
      "name": "Normalize PDF",
      "type": "n8n-nodes-base.set",
      "position": [
        4048,
        2880
      ]
    },
    {
      "id": "b42370d0-8168-49e6-afd8-d46c90cf9241",
      "name": "Normalize RTF",
      "type": "n8n-nodes-base.set",
      "position": [
        4048,
        3200
      ]
    },
    {
      "id": "b136b15b-bd61-4588-a38e-20cb4a5da56a",
      "name": "Normalize text file",
      "type": "n8n-nodes-base.set",
      "position": [
        3888,
        3344
      ]
    },
    {
      "id": "61f3aba5-20af-4b05-bebd-4f30489d0700",
      "name": "Normalize XML",
      "type": "n8n-nodes-base.set",
      "position": [
        3888,
        3488
      ]
    },
    {
      "id": "b88503f3-3acf-43ee-b44c-f9410ca75453",
      "name": "Extract from XML",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3712,
        3488
      ]
    },
    {
      "id": "1fc00f6e-ad2b-464b-b42f-9b5cc6b71e2b",
      "name": "Normalize XLSX",
      "type": "n8n-nodes-base.set",
      "position": [
        4048,
        3632
      ]
    },
    {
      "id": "74de89ed-af3f-47bb-9b9c-b994a316f9e3",
      "name": "Get RTF data",
      "type": "n8n-nodes-base.code",
      "position": [
        3888,
        3200
      ]
    },
    {
      "id": "6f62da6c-32ba-4acc-8bea-4643a7fe3eba",
      "name": "Get RTF data1",
      "type": "n8n-nodes-base.code",
      "position": [
        3888,
        3632
      ]
    },
    {
      "id": "a3824f70-80fd-44c8-be70-e32cf6d2c26d",
      "name": "Text?",
      "type": "n8n-nodes-base.if",
      "position": [
        3888,
        2896
      ]
    },
    {
      "id": "3b1dc9af-f87b-48a9-ba64-c23460b43cc3",
      "name": "Analyze document",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        3888,
        3040
      ]
    },
    {
      "id": "34a65725-8005-446f-98da-4d6068a1eaf3",
      "name": "Normalize PDF (AI)",
      "type": "n8n-nodes-base.set",
      "position": [
        4048,
        3040
      ]
    },
    {
      "id": "2188e2ae-bb96-44b1-baa6-9ac055fc7cda",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        3712,
        3040
      ]
    },
    {
      "id": "8877af77-2336-48f8-b6be-9f426df22e25",
      "name": "Normalize input",
      "type": "n8n-nodes-base.set",
      "position": [
        5040,
        1728
      ]
    },
    {
      "id": "a70cf6e8-1fff-4065-af6e-9d1f79c66324",
      "name": "Convert to File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        3040,
        2720
      ]
    },
    {
      "id": "4083d78a-775c-4085-97a8-710c51e8d0a5",
      "name": "Analyze video",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        3712,
        2016
      ]
    },
    {
      "id": "6d3c8aed-82e3-4522-9788-91aa7389f160",
      "name": "get_message (Video)",
      "type": "n8n-nodes-base.set",
      "position": [
        3888,
        2016
      ]
    },
    {
      "id": "52ca5378-0bfa-439d-849e-ea7151930686",
      "name": "get_message (Audio)",
      "type": "n8n-nodes-base.set",
      "position": [
        3888,
        1856
      ]
    },
    {
      "id": "0912e7ec-818f-4ccf-b29e-4fb01bf70660",
      "name": "get_message (Image)",
      "type": "n8n-nodes-base.set",
      "position": [
        3888,
        1696
      ]
    },
    {
      "id": "6a66a1b2-1eef-453e-ae79-ad1d806f6cd3",
      "name": "Get Mime Type",
      "type": "n8n-nodes-base.code",
      "position": [
        3248,
        2720
      ]
    },
    {
      "id": "b45c9a72-3b1c-41b2-9caf-5ee10b5ebfcf",
      "name": "Media Type",
      "type": "n8n-nodes-base.switch",
      "position": [
        3440,
        2528
      ]
    },
    {
      "id": "6ee06090-67f3-4514-8797-5bb62f136826",
      "name": "Analyze Image",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        3712,
        1696
      ]
    },
    {
      "id": "2178effc-f7d2-4a20-b0c5-499c89352877",
      "name": "When clicking ‘Execute workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        3360,
        -208
      ]
    },
    {
      "id": "6387dd8e-69ed-46a1-b391-3ef1b95a70e4",
      "name": "Agent Response",
      "type": "n8n-nodes-base.set",
      "position": [
        9680,
        1504
      ]
    },
    {
      "id": "46a48d70-bf20-47c8-b770-979e89eb34fa",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        9376,
        1504
      ]
    },
    {
      "id": "eb0d0e55-1d6d-41a3-bffd-2c5e3d2d31f3",
      "name": "Context Refiner",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        8976,
        1504
      ]
    },
    {
      "id": "47a4fe06-7a45-44fe-92bc-79cda433b549",
      "name": "Push to chat_history",
      "type": "n8n-nodes-base.redis",
      "position": [
        8208,
        1680
      ]
    },
    {
      "id": "98c4bba6-775a-4d38-9c83-64b25bf83932",
      "name": "Push first message to chat_history",
      "type": "n8n-nodes-base.redis",
      "position": [
        8208,
        1872
      ]
    },
    {
      "id": "525f488e-5066-4c84-bd08-0959fdb3c33c",
      "name": "Get chat_history1",
      "type": "n8n-nodes-base.redis",
      "position": [
        7184,
        1552
      ]
    },
    {
      "id": "08497094-b7cd-4d03-8c0e-197360542870",
      "name": "Push message chat_history (User And Agent)",
      "type": "n8n-nodes-base.redis",
      "position": [
        10032,
        1504
      ]
    },
    {
      "id": "92b3ffab-fb04-4575-855a-cb1ab75adb57",
      "name": "Add Messages to chat_history (User And Agent)",
      "type": "n8n-nodes-base.postgres",
      "position": [
        10240,
        1504
      ]
    },
    {
      "id": "a23a94ca-0c81-48d5-bace-738af244c867",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        3408,
        336
      ]
    },
    {
      "id": "6e538c6a-1865-4784-a565-dac1ab16545e",
      "name": "Parallel Writing status",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        3504,
        960
      ]
    },
    {
      "id": "444d3835-f5d1-43dd-a7d1-7b9a2ada6610",
      "name": "Google Gemini Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        9376,
        1696
      ]
    },
    {
      "id": "eb8e098b-7c6b-4cde-bae9-fe4143122bb6",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        3648,
        512
      ]
    },
    {
      "id": "1920d4a8-78c2-41f1-8179-a912b43d38b9",
      "name": "chat_history in DataBase?",
      "type": "n8n-nodes-base.if",
      "position": [
        8000,
        1776
      ]
    },
    {
      "id": "3f6f770b-3b44-4675-b538-33ae53d39597",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3280,
        -336
      ],
      "parameters": {
        "width": 512,
        "height": 320,
        "content": "## 1. Database Setup\nCreates the `chat_history` table in PostgreSQL. Execute this node manually **once** before activating the workflow."
      }
    },
    {
      "id": "4b6f4dff-5454-407f-be33-4bd779f0b381",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3280,
        32
      ],
      "parameters": {
        "width": 832,
        "height": 688,
        "content": "## 2. Parallel UX Handling\nManages user experience (Read receipts, 'Typing...' status) in parallel using a sub-workflow to avoid adding latency to the main AI processing logic."
      }
    },
    {
      "id": "bd72d726-84ed-4434-95b7-173b24c82ca0",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3280,
        768
      ],
      "parameters": {
        "width": 1440,
        "height": 752,
        "content": "## 3. Webhook & Configuration\nReceives the Evolution API payload and defines global variables (Buffer wait time, Cache duration, History limit)."
      }
    },
    {
      "id": "9e9ea3aa-852a-432c-bc26-ee13552f8dab",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2896,
        1584
      ],
      "parameters": {
        "width": 1840,
        "height": 2400,
        "content": "## 4. Media Normalization\nDetects media types (Images, Audio, Documents) and downloads/converts them into a format compatible with the AI Agent."
      }
    },
    {
      "id": "3ddc5983-ec8a-496b-b21d-d02cac687e9b",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4928,
        1184
      ],
      "parameters": {
        "width": 2080,
        "height": 1072,
        "content": "## 5. Smart Input Buffering\nUses Redis to:\n1. Group **Album files** into a single input.\n2. Debounce **Text messages** (waits X seconds) to prevent fragmented AI responses."
      }
    },
    {
      "id": "4dc66b66-9a03-43a5-ad23-1dffd23659b8",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7120,
        1376
      ],
      "parameters": {
        "width": 1600,
        "height": 720,
        "content": "## 6. Hybrid Memory Retrieval\nOptimized fetch strategy: Checks Redis (fast cache) for recent history first. If empty, falls back to PostgreSQL (permanent storage)."
      }
    },
    {
      "id": "163ace07-b710-43fb-a754-c5ed15556a83",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        8848,
        1360
      ],
      "parameters": {
        "width": 1600,
        "height": 608,
        "content": "## 7. Context Refinement & Generation\n1. **Refiner Agent:** Summarizes chat history to save tokens and reduce context rot.\n2. **Main Agent:** Generates the final response.\n3. **Sync:** Saves the inter"
      }
    },
    {
      "id": "fb24f4eb-c334-4aa1-b247-c8a72cf1d247",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        10528,
        1360
      ],
      "parameters": {
        "width": 1184,
        "height": 640,
        "content": "## 8. Cache Lifecycle Manager\nKeeps the conversation active in Redis for a specific duration (e.g., 300s) after the last message to ensure high-speed retrieval."
      }
    },
    {
      "id": "52b4fc49-49bc-4fc3-a231-8377cd367344",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3680,
        896
      ],
      "parameters": {
        "width": 400,
        "height": 464,
        "content": "## ⚠️ Core Configuration\nControl the buffering and memory logic here:\n\n*   **wait_buffer**: The debounce window (in seconds). The workflow waits this long for subsequent text messages to group them in"
      }
    },
    {
      "id": "99b522bd-49bf-4041-928c-91660c46c4cc",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2800,
        -336
      ],
      "parameters": {
        "width": 388,
        "height": 1070,
        "content": "## Advanced Evolution API Agent with Redis Buffering & Context Refinement\n\nThis production-ready template builds a high-performance WhatsApp chatbot using Evolution API. It solves common AI bot issues"
      }
    },
    {
      "id": "252dc60c-71df-49ae-bbb0-ed561843872a",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4160,
        512
      ],
      "parameters": {
        "width": 368,
        "height": 208,
        "content": "## 💡 Need Assistance?\n\nIf you’d like help customizing or extending this workflow, feel free to reach out:  \n\n📧 Email: [johnsilva11031@gmail.com](mailto:johnsilva11031@gmail.com)  \n🔗 LinkedIn: [John Al"
      }
    }
  ],
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Writting...",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Analyze document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text?": {
      "main": [
        [
          {
            "node": "Normalize PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Album?": {
      "main": [
        [
          {
            "node": "Push Media to Buffer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Push to Buffer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Global Variables",
            "type": "main",
            "index": 0
          },
          {
            "node": "Parallel Writing status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Agent Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Normalize CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Completed?": {
      "main": [
        [
          {
            "node": "Delete Media Buffer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Media Type": {
      "main": [
        [
          {
            "node": "Analyze Image",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Analyze audio",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Analyze video",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from CSV",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HTML Extract Generic1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from ICS",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from JSON",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from ODS",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from PDF",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ],
        [
          {
            "node": "Extract from RTF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from XML",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from XLSX",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "get_error_message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Message": {
      "main": [
        [
          {
            "node": "Get chat_history1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buffer Route": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete Buffer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait For User Other Fast Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get ODS data": {
      "main": [
        [
          {
            "node": "Normalize ODS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get RTF data": {
      "main": [
        [
          {
            "node": "Normalize RTF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message Type": {
      "main": [
        [
          {
            "node": "get_message (text)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Push to Buffer (AlbumGroup)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Descargar Media",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Open session": {
      "main": [
        []
      ]
    },
    "Analyze Image": {
      "main": [
        [
          {
            "node": "get_message (Image)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze audio": {
      "main": [
        [
          {
            "node": "get_message (Audio)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze video": {
      "main": [
        [
          {
            "node": "get_message (Video)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Buffer": {
      "main": [
        [
          {
            "node": "Normalize Buffer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Mime Type": {
      "main": [
        [
          {
            "node": "Media Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get RTF data1": {
      "main": [
        [
          {
            "node": "Normalize XLSX",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize CSV": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize ICS": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize ODS": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize PDF": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize RTF": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize XML": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Messages": {
      "main": [
        []
      ]
    },
    "Send Response": {
      "main": [
        [
          {
            "node": "Push message chat_history (User And Agent)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent Response": {
      "main": [
        [
          {
            "node": "Send Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize HTML": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize JSON": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize XLSX": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Push to Buffer": {
      "main": [
        [
          {
            "node": "Get From Buffer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Context Refiner": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "Get Mime Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Descargar Media": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get From Buffer": {
      "main": [
        [
          {
            "node": "Buffer Route",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize input": {
      "main": [
        [
          {
            "node": "Check AlbumGroup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze document": {
      "main": [
        [
          {
            "node": "Normalize PDF (AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check AlbumGroup": {
      "main": [
        [
          {
            "node": "Album?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from CSV": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from ICS": {
      "main": [
        [
          {
            "node": "Normalize ICS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from ODS": {
      "main": [
        [
          {
            "node": "Get ODS data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from PDF": {
      "main": [
        [
          {
            "node": "Text?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from RTF": {
      "main": [
        [
          {
            "node": "Get RTF data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from XML": {
      "main": [
        [
          {
            "node": "Normalize XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get chat_history": {
      "main": [
        [
          {
            "node": "Context Refiner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Global Variables": {
      "main": [
        [
          {
            "node": "Message Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Buffer": {
      "main": [
        [
          {
            "node": "Get Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Normalize text file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from JSON": {
      "main": [
        [
          {
            "node": "Normalize JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from XLSX": {
      "main": [
        [
          {
            "node": "Get RTF data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get chat_history1": {
      "main": [
        [
          {
            "node": "chat_history In Buffer?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_error_message": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize PDF (AI)": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_message (text)": {
      "main": [
        [
          {
            "node": "Push to Buffer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Media Buffer": {
      "main": [
        [
          {
            "node": "Normalize MediaGroup Buffer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize text file": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_message (Audio)": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_message (Image)": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_message (Video)": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Push Media to Buffer": {
      "main": [
        [
          {
            "node": "Get Album From Buffer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Push to chat_history": {
      "main": [
        [
          {
            "node": "Get chat_history",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate all Messges": {
      "main": [
        [
          {
            "node": "chat_history in DataBase?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Album From Buffer": {
      "main": [
        [
          {
            "node": "Completed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Extract Generic1": {
      "main": [
        [
          {
            "node": "Normalize HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "chat_history In Buffer?": {
      "main": [
        [
          {
            "node": "Get chat_history",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get chat_history From DataBase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Context Refiner",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "chat_history in DataBase?": {
      "main": [
        [
          {
            "node": "Push to chat_history",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Push first message to chat_history",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_message (File message)": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buffer (chat_history) Route": {
      "main": [
        [
          {
            "node": "No Operation, do nothing1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete Buffer (chat_history)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait For end of conversation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize MediaGroup Buffer": {
      "main": [
        [
          {
            "node": "Get Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Buffer (chat_history)": {
      "main": [
        [
          {
            "node": "Delete Buffer (chat_history)2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait For end of conversation": {
      "main": [
        [
          {
            "node": "Get From Buffer(chat_history)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get From Buffer(chat_history)": {
      "main": [
        [
          {
            "node": "Buffer (chat_history) Route",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Push to Buffer (chat_history)": {
      "main": [
        [
          {
            "node": "Get From Buffer(chat_history)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get chat_history From DataBase": {
      "main": [
        [
          {
            "node": "Aggregate all Messges",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait For User Other Fast Message": {
      "main": [
        [
          {
            "node": "Get From Buffer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Open session",
            "type": "main",
            "index": 0
          },
          {
            "node": "Read Messages",
            "type": "main",
            "index": 0
          },
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Push first message to chat_history": {
      "main": [
        [
          {
            "node": "Get chat_history",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Create Table chat_history",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Push message chat_history (User And Agent)": {
      "main": [
        [
          {
            "node": "Add Messages to chat_history (User And Agent)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Messages to chat_history (User And Agent)": {
      "main": [
        [
          {
            "node": "Push to Buffer (chat_history)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}