{
  "name": "End of turn detection for smoother AI agent chats with Telegram and Gemini",
  "nodes": [
    {
      "id": "dd511e76-27a0-47a1-b475-d00fffa22eb8",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1280,
        120
      ]
    },
    {
      "id": "fef3c7b6-ac57-4b83-8f21-2babd81d3b50",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1280,
        320
      ]
    },
    {
      "id": "084bfb67-c59b-44c4-a310-4c25743cd8f9",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1260,
        520
      ]
    },
    {
      "id": "4733b8d3-427d-4724-a5a3-7eb787941494",
      "name": "Redis Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        1420,
        520
      ]
    },
    {
      "id": "8f7e6148-b1a5-46b5-934a-0c75f20898d8",
      "name": "Get Values",
      "type": "n8n-nodes-base.set",
      "position": [
        -860,
        120
      ]
    },
    {
      "id": "52cc0bd2-bb0a-4c2c-a1a5-2a9104d891da",
      "name": "Update Session",
      "type": "n8n-nodes-base.redis",
      "position": [
        -920,
        700
      ]
    },
    {
      "id": "7bdee33c-a2e7-49a3-b782-d045f3f46dd3",
      "name": "Get Session",
      "type": "n8n-nodes-base.redis",
      "position": [
        -1100,
        700
      ]
    },
    {
      "id": "0fc0b9eb-3553-4fdb-befc-7d7891305405",
      "name": "Is Waiting?",
      "type": "n8n-nodes-base.if",
      "position": [
        -80,
        1020
      ]
    },
    {
      "id": "de3eb7bb-81e0-4169-a6f4-286a1ac9a2f7",
      "name": "Update Session1",
      "type": "n8n-nodes-base.redis",
      "position": [
        40,
        300
      ]
    },
    {
      "id": "c7fb3fba-9d6a-4c68-a995-5539ab6bcf63",
      "name": "is New Session?",
      "type": "n8n-nodes-base.if",
      "position": [
        -560,
        700
      ]
    },
    {
      "id": "8bbb222c-d3d1-4c03-931c-37f1d2d37df2",
      "name": "Google Gemini Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        300,
        460
      ]
    },
    {
      "id": "3a285fef-8c80-48dc-8e79-2c30ff9d351c",
      "name": "Get Session2",
      "type": "n8n-nodes-base.redis",
      "position": [
        720,
        460
      ]
    },
    {
      "id": "e8254612-ff46-4165-ab93-a6c9d7a2c583",
      "name": "Session Ref",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -120,
        300
      ]
    },
    {
      "id": "bdd227f1-65fd-46d0-8e0c-23e812f83967",
      "name": "Session Ended?",
      "type": "n8n-nodes-base.if",
      "position": [
        880,
        460
      ]
    },
    {
      "id": "a9611069-9cf9-4090-aa6e-cc6a3f4a0fa8",
      "name": "Wait For Webhook",
      "type": "n8n-nodes-base.wait",
      "position": [
        560,
        460
      ]
    },
    {
      "id": "456d5b81-7eee-49fd-9b27-93e9e8fbe7b8",
      "name": "Update Session2",
      "type": "n8n-nodes-base.redis",
      "position": [
        1620,
        320
      ]
    },
    {
      "id": "d778edf7-4152-4bd9-a720-a0a28db45369",
      "name": "Is Bot command?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1080,
        120
      ]
    },
    {
      "id": "a465cb15-8faf-42fb-b00e-51af15c596da",
      "name": "Predict End of Utterance",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        200,
        300
      ]
    },
    {
      "id": "14dd091f-636b-4944-81b4-35da5f0f64b2",
      "name": "Respond to User",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1800,
        320
      ]
    },
    {
      "id": "b6ae259c-9fc4-481a-bd6d-f1b3a0dc2d28",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1360,
        -80
      ],
      "parameters": {
        "width": 1020,
        "height": 440,
        "content": "## 1. Accept Telegram messages\n[Read more about the Telegram Trigger](https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.telegramtrigger)\n\nThis template will only work with chat sys"
      }
    },
    {
      "id": "33c5c000-5d3e-459a-814e-f2e5669e9592",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1360,
        400
      ],
      "parameters": {
        "width": 1020,
        "height": 560,
        "content": "## 2. Determine If New Message\n[Learn more about the subworkflow trigger](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflowtrigger)\n\nOur goal is ultimately to not \"int"
      }
    },
    {
      "id": "939f8f46-c7c1-468f-af83-2c4f15fca09b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        780
      ],
      "parameters": {
        "width": 660,
        "height": 460,
        "content": "## 3. Prediction Loop Already Running? Let's Resume!\n[Read more about the HTTP node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.httprequest/)\n\nUsing the session data, we can ch"
      }
    },
    {
      "id": "d36770f7-1992-4335-8e9d-01a73de44c0b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -60
      ],
      "parameters": {
        "width": 1340,
        "height": 800,
        "content": "## 2. Start of a New Utterance? Start the Prediction Wait Loop.\n[Learn more about the Text Classifier node](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.text-c"
      }
    },
    {
      "id": "d9dcc03f-8549-495e-969b-82c0f96c3057",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1160,
        80
      ],
      "parameters": {
        "width": 840,
        "height": 660,
        "content": "## 4. Send Reply Only When End of Utterance is Detected\n[Read more about the AI Agent node](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/)\n\nFinally! With"
      }
    },
    {
      "id": "c242729b-0d95-4201-adee-b3a537d28eb1",
      "name": "Resume Wait Node",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        140,
        1020
      ]
    },
    {
      "id": "321e48ff-9389-408f-af97-e1590ce13e0c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1860,
        -300
      ],
      "parameters": {
        "width": 460,
        "height": 1260,
        "content": "## Try It Out!\n### This n8n template demonstrates one approach to achieve a more natural and less frustration conversations with AI agents by reducing interrupts by predicting the end of user utteranc"
      }
    },
    {
      "id": "f56fe585-7ece-49aa-813a-2d72b11d5d0f",
      "name": "Call Prediction Subworkflow",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        -640,
        120
      ]
    },
    {
      "id": "6d24bc9e-223e-48f8-b32d-84cabf1febfc",
      "name": "Prediction Subworkflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -1280,
        700
      ]
    },
    {
      "id": "f711ff8e-4b68-4379-8abe-33bc673bab1f",
      "name": "Get Updated Session Values",
      "type": "n8n-nodes-base.set",
      "position": [
        -740,
        700
      ]
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Update Session2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Values": {
      "main": [
        [
          {
            "node": "Call Prediction Subworkflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Session": {
      "main": [
        [
          {
            "node": "Update Session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Waiting?": {
      "main": [
        [
          {
            "node": "Resume Wait Node",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Session Ref": {
      "main": [
        [
          {
            "node": "Update Session1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Session2": {
      "main": [
        [
          {
            "node": "Session Ended?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Session Ended?": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Session Ref",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Session": {
      "main": [
        [
          {
            "node": "Get Updated Session Values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Bot command?": {
      "main": [
        [],
        [
          {
            "node": "Get Values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Respond to User": {
      "main": [
        []
      ]
    },
    "Update Session1": {
      "main": [
        [
          {
            "node": "Predict End of Utterance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Session2": {
      "main": [
        [
          {
            "node": "Respond to User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "is New Session?": {
      "main": [
        [
          {
            "node": "Session Ref",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Is Waiting?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Is Bot command?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait For Webhook": {
      "main": [
        [
          {
            "node": "Get Session2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redis Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Prediction Subworkflow": {
      "main": [
        [
          {
            "node": "Get Session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Predict End of Utterance": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait For Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Predict End of Utterance",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Updated Session Values": {
      "main": [
        [
          {
            "node": "is New Session?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call Prediction Subworkflow": {
      "main": [
        []
      ]
    }
  }
}