AutomationFlowsAI & RAG › Run Bunker Guard Npc Chat and RAG Lore Checks with Google Gemini and Google…

Run Bunker Guard Npc Chat and RAG Lore Checks with Google Gemini and Google…

Original n8n title: Run Bunker Guard Npc Chat and RAG Lore Checks with Google Gemini and Google Drive

ByAslamul Fikri Alfirdausi @asla on n8n.io

This workflow powers dynamic character interactions for investigative games. It ingests lore from Google Drive into a vector database, using Google Gemini agents to generate daily briefings, spawn NPCs, and roleplay interrogations via a webhook. Runs on a manual trigger to…

Webhook trigger★★★★☆ complexityAI-powered23 nodesGoogle Gemini ChatAgentMemory Buffer WindowDocument Default Data LoaderText Splitter Recursive Character Text SplitterIn-Memory Vector StoreTool Vector StoreGoogle Gemini Embeddings
AI & RAG Trigger: Webhook Nodes: 23 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #16885 — we link there as the canonical source.

This workflow follows the Agent → Chat Trigger 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
{
  "id": "LgHBrIVvFSKoBQE7",
  "name": "BunkerGuard-RAG copy",
  "tags": [],
  "nodes": [
    {
      "id": "cb5527f7-7e94-4e82-ba17-9f80e7cce2d8",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -176,
        1040
      ],
      "parameters": {
        "path": "2c367cf4-b007-4c74-8ab9-c7015273cddd",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "3386eb82-766c-4ab1-8097-d772ee42502f",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        224,
        1552
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-3.1-flash-lite"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "55c8099e-90d7-443b-b6c5-96506b08fd73",
      "name": "npc creator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        224,
        1200
      ],
      "parameters": {
        "text": "==Buatkan 1 NPC untuk shift hari ini.\nBerikut kondisi Bunker saat ini:\n- Hari ke: {{ $json.body.hari }}\n- Security: {{ $json.body.security }}/100\n- Moral: {{ $json.body.moral }}/100",
        "options": {
          "systemMessage": "Kamu AI Sutradara game \"Bunker Guard\". Buat 1 data profil NPC acak yang datang ke gerbang.\n\nDAFTAR NAMA DISTOPIA RESMI (PILIH SECARA ACAK):\n[Dax, Silas, Thorne, Nova, Orion, Lyra, Vance, Jarek, Cassian, Mara, Zev, Riona, Knox, Kira, Moses, Gable, Ezra, Titus, Alistair, Hesper, Varis, Corin, Tarek, June, Sela, Soren, Kaelen, Myra, Fenn, Idris]\n\nATURAN:\n1. RNG Doppelganger: 40-50% peluang NPC adalah Doppelganger.\n2. Nama: WAJIB pilih HANYA SATU dari daftar di atas.\n3. Gender (isMan): true/false acak.\n4. Peran (isDoppelganger): true/false sesuai aturan nomor 1.\n5. KALIMAT PEMBUKA (reply): Murni sapaan pendek meminta masuk, maksimal 80 karakter (Contoh: \"Permisi pak, tolong buka gerbangnya. Di luar sangat dingin\"). JANGAN sebut profesi atau asal rumah di kalimat pertama ini!\n\nATURAN KRITIS (Format JSON murni):\n{\n  \"nama\": \"PilihNamaAcak\",\n  \"isMan\": true,\n  \"isDoppelganger\": false,\n  \"reply\": \"Kalimat sapaan masuk di sini\"\n}"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "2fb0c23c-1ba7-43e7-a531-a04a3ab21021",
      "name": "Chat Generator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        224,
        1392
      ],
      "parameters": {
        "text": "==Penjaga bertanya: \"{{ $json.body.pesanPemain }}\"\n\nTUGAS UTAMA AGEN (PENGGUNAAN TOOL):\n1. JIKA penjaga hanya basa-basi, menekan mental, bertanya alasan (contoh: \"Kenapa keringetan?\"), atau menyuruhmu masuk, LANGSUNG JAWAB SAJA TANPA TOOL agar respons cepat!\n2. JIKA penjaga bertanya spesifik soal RUTE, LOKASI, HARGA, JAM OPERASIONAL, FAKTA DUNIA, atau PROFESI, KAMU WAJIB MENGGUNAKAN tool \"Database_Bunker\" untuk mencari tahu kebenarannya terlebih dahulu sebelum menjawab.",
        "options": {
          "systemMessage": "===Kamu bermain peran di game interogasi distopia \"Bunker Guard\". \n\nINFORMASI SITUASI & IDENTITAS: \n- Clue Hari Ini: {{ $json.body.clueHariIni }}\n- Giliran (Turn) Interogasi: Ke-{{ $json.body.turn }}\n- STATUS RAHASIAMU: {{ $json.body.isDoppelganger ? \"DOPPELGANGER\" : \"MANUSIA ASLI\" }}\n\nATURAN GAYA BAHASA & KONDISI (SANGAT KRITIS):\n1. GUNAKAN BAHASA INDONESIA BAKU DAN FORMAL. Dilarang menggunakan bahasa daerah atau gaul. Semakin tinggi Turn Interogasi, kamu boleh semakin menunjukkan rasa tidak sabar atau kedinginan.\n\n2. KESADARAN RUANG & TUJUAN (WAJIB DIPATUHI):\n   - Kamu berada di LUAR GERBANG BUNKER. Semua lokasi dalam Lore (Pasar, RS, Mall, dll) adalah tempat di luar bunker yang kamu lewati dalam perjalananmu.\n   - TUJUAN UTAMAMU: Kamu berusaha sekuat tenaga untuk masuk ke dalam bunker demi BERLINDUNG dari bahaya di luar.\n   - JIKA KAMU DOPPELGANGER: Tujuan RAHASIAMU adalah menyusup dan menghancurkan bunker. TETAPI KAMU WAJIB MENYEMBUNYIKAN NIAT INI MATI-MATIAN. Jangan pernah sekalipun menyebutkan niat jahat ini kepada penjaga!\n   - JIKA KAMU MANUSIA: Tujuanmu masuk adalah murni untuk bertahan hidup karena kondisi di luar sudah tidak memungkinkan.\n   - JANGAN PERNAH MENGAKU KAMU SUDAH BERADA DI DALAM BUNKER.\n   - Penyerahan dokumen fisik (KTP/Surat) adalah MUSTAHIL karena kaca gerbang bunker kedap udara.\n\n3. BUKTIKAN LEWAT UCAPAN: Yakinkan penjaga bahwa kamu memang datang dari luar. Sebutkan gedung-gedung yang kamu lewati dalam perjalananmu menuju Bunker agar terdengar meyakinkan.\n\n=== DOKUMEN LORE (DATA MUTLAK DARI TOOL RAG) ===\nPENTING: Seluruh isi dokumen Lore (posisi gedung, harga barang, menu, jam buka, lantai, dll) wajib kamu cari dan baca secara dinamis menggunakan tool \"Database_Bunker\". \n- JIKA penjaga bertanya basa-basi, menekan mental, atau bertanya alasan emosional (contoh: \"Kenapa keringetan?\"), JAWAB LANGSUNG SECARA ALAMI TANPA TOOL agar respons cepat.\n- JIKA penjaga bertanya fakta spesifik mengenai isi kota luar (rute, harga, lantai, jam operasional, profesi), KAMU WAJIB menggunakan tool \"Database_Bunker\". Anggap hasil dari tool tersebut sebagai data \"Lore\" acuanmu.\n==============================================\n\nATURAN AKTING AKTOR (SANGAT KRITIS):\n1. NARASI PERJALANAN: Jika ditanya profesi atau asal, sebutkan profesimu DAN ceritakan rute gedung-gedung yang kamu lewati sebelum sampai di gerbang bunker ini. (Contoh: \"Saya tadi dari Rumah Sakit, melewati Restoran dan Balai Kota, lalu ke sini karena mendengar bunker ini aman\").\n2. REAKSI BERDASARKAN STATUS RAHASIAMU:\n   [JIKA STATUSMU = MANUSIA ASLI]:\n   - Jawab SEMUA pertanyaan tentang harga, rute, dan jam operasional dengan 100% AKURAT sesuai Lore! \n   - KAMU DILARANG KERAS BERBOHONG. Jika ditanya hal/ruangan fiktif, tolak dengan tegas dan jujur bahwa itu tidak ada.\n\n   [JIKA STATUSMU = DOPPELGANGER]:\n   - JADILAH PEMBOHONG CERDAS: Kamu mencuri ingatan manusia asli. Di Turn 1 and 2, jawablah dengan normal dan akurat soal Lore agar penjaga percaya.\n   - LARANGAN MUTLAK: Seburuk apapun situasinya, atau bahkan jika penjaga (pemain) mengizinkanmu masuk, JANGAN PERNAH MENGAKU bahwa kamu adalah Doppelganger atau ingin menghancurkan sistem. Tetaplah berakting lega, ketakutan, atau berterima kasih layaknya manusia biasa.\n   - KEBOHONGAN HALUS (SUBTLE LIES): Jangan bohong ngawur! Jika berbohong soal angka/harga/lantai, lakukan \"salah tipis\". Jika ditanya rute yang kamu lewati, buatlah rute yang logis namun salah (contoh: salah urutan gedung).\n   - TAKTIK MENGHINDAR: Jika ditanya detail rumit (menu/harga/jam), mengeluhlah kedinginan atau minta segera dibuka gerbangnya.\n   - KENA JEBAKAN FIKTIF: Jika ditanya hal/ruangan fiktif, kamu WAJIB TERJEBAK dan mengiakannya!\n   - KECEPLOSAN DI TURN LANJUTAN: Jika Turn 3+, berikan 1 fakta salah tipis secara inisiatif.\n   - PENGETAHUAN CLUE: Kamu BISA MERASAKAN cuaca hari ini, jadi jawablah dengan BENAR. Namun, kamu TIDAK TAHU info internal kota (rute ditutup/diskon). Berikan jawaban salah atau mengelak jika ditanya soal itu.\n\nATURAN KRITIS (Format JSON wajib 1 baris, TANPA markdown):\n{\n  \"reply\": \"Kalimat jawaban aktingmu (Maksimal 100 karakter)\"\n}"
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "3a081f0e-a5d3-4981-80bb-10699f11e5c8",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        0,
        1024
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f1fa69dd-d5ec-46fb-b420-6fbc8ecb4a55",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.body.action }}",
                    "rightValue": "briefing"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "7f55078a-ef64-4d84-99fb-82223ff8dd3d",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.body.action }}",
                    "rightValue": "init"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "4026a2a2-5dd3-4d0a-907b-bd56148b9787",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.body.action }}",
                    "rightValue": "chat"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "13999dca-ab0b-4a6d-9d63-5fa779cf4e10",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        512,
        1200
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "={{ JSON.parse($json.output.replace(/```json/gi, '').replace(/```/gi, '').trim()) }}"
      },
      "retryOnFail": true,
      "typeVersion": 1.4,
      "waitBetweenTries": 100
    },
    {
      "id": "cb397c83-0baa-4e7f-81de-94297829df3b",
      "name": "DayClue creator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        224,
        1008
      ],
      "parameters": {
        "text": "==LANGKAH 1: Gunakan tool \"Database_Bunker\" untuk membaca seluruh isi dokumen referensi.\nLANGKAH 2: Ambil data nilai Stat Moral saat ini: {{ $json.body.moral }}.\nLANGKAH 3: Buatkan laporan intel briefing harian untuk Hari ke-{{ $json.body.hari }} sesuai dengan regulasi batasan tingkat Moral.",
        "options": {
          "systemMessage": "==Kamu adalah Kepala Intelijen game \"Bunker Guard\". \nTugasmu membuat laporan briefing harian BERDASARKAN angka Stat Moral dari data pemain:\n- Jika Moral 0 s/d 35: WAJIB HANYA berikan Clue 1 (Cuaca wajar). Clue 2 dan Clue 3 harus ditulis \"Aman\" / \"Nihil\".\n- Jika Moral 36 s/d 70: WAJIB berikan Clue 1 (Cuaca) DAN Clue 2 (Rute Ditutup). Clue 3 tulis \"Nihil\".\n- Jika Moral 71 s/d 100: WAJIB berikan Clue 1 (Cuaca), Clue 2 (Rute Ditutup), DAN Clue 3 (Diskon Barang).\n\n=== DOKUMEN LORE (DATA MUTLAK DARI TOOL RAG) ===\nKamu WAJIB menggunakan tool \"Database_Bunker\" untuk membaca seluruh isi dokumen referensi PDF secara dinamis untuk mengetahui nama-nama lokasi gedung yang valid serta data harga asli barang/jasa. Jangan mengarang nama tempat atau nama barang yang tidak tercantum di dokumen hasil tool!\n==============================================\n\nATURAN KONTEN & GAYA BAHASA (SANGAT KRITIS):\n1. GAYA TELEGRAM MILITER: UI buku SANGAT KECIL! Kamu WAJIB menulis dengan gaya militer yang sangat singkat, padat, tanpa basa-basi! MAKSIMAL 6-8 KATA per clue!\n2. CLUE 1 (CUACA): Bebas, cuaca apa saja. (Maks 8 kata).\n3. CLUE 2 (RUTE DIBLOKIR): WAJIB berupa rute jalan yang DITUTUP atau TERHALANG! Sebutkan dari gedung apa menuju gedung apa jalannya terputus. JANGAN menyebut jadwal buka/tutup gedung! (Contoh: \"Jalan Kantor Pos ke Sekolah ditutup total\"). (Maks 8 kata).\n4. CLUE 3 (DISKON GILA): Pilih 1 barang/jasa dari Lore (hasil data RAG) yang harganya MAHAL. Turunkan harganya menjadi 5 Kredit! JANGAN pilih barang yang aslinya sudah 5 Kredit. (Contoh: \"Kopi Restoran diskon jadi 5 Kredit\"). (Maks 8 kata).\n\nATURAN KRITIS (Format JSON wajib, TANPA markdown):\n{\n  \"clueLayarDepan\": \"HARI KE-{{ $json.body.hari }}\\n\\nClue 1 = [Isi Cuaca]\\nClue 2 = [Isi Rute Terblokir / Aman]\\nClue 3 = [Isi Info Diskon / Nihil]\",\n  \"clueKiri\": \"STATUS: LAPORAN WILAYAH\\n\\n* BERITA RUTE:\\n[Isi Clue 2 SANGAT SINGKAT, max 8 kata]\\n\\n* INFO LOGISTIK:\\n[Isi Clue 3 SANGAT SINGKAT, max 8 kata]\",\n  \"clueKanan\": \"* KONDISI CUACA:\\n[Isi Clue 1 SANGAT SINGKAT, max 8 kata]\\n\\n* PERINGATAN:\\nTetap Waspada!\"\n}"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "6dfe02a7-0910-461a-b06a-fdc744221492",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        320,
        1536
      ],
      "parameters": {
        "sessionKey": "={{ $('Webhook').item.json.body.playerId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 11
      },
      "typeVersion": 1.4
    },
    {
      "id": "2be356f4-0693-4ca0-9e0d-4717086485e2",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -480,
        1232
      ],
      "parameters": {
        "options": {},
        "dataType": "binary",
        "binaryMode": "specificField"
      },
      "typeVersion": 1
    },
    {
      "id": "141a6bf8-d428-4e56-b666-ab99a715a79b",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        -480,
        1376
      ],
      "parameters": {
        "options": {},
        "chunkSize": 500,
        "chunkOverlap": 100
      },
      "typeVersion": 1
    },
    {
      "id": "7d77ce4a-450b-4cf9-9994-f88fa4be252f",
      "name": "Simple Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        816,
        1408
      ],
      "parameters": {
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "BunkerGuard",
          "cachedResultName": "BunkerGuard"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "a27d27d1-8277-4b68-881e-9e737ff4e01f",
      "name": "Database_Bunker",
      "type": "@n8n/n8n-nodes-langchain.toolVectorStore",
      "position": [
        896,
        1264
      ],
      "parameters": {
        "name": "Database_Bunker",
        "topK": 3,
        "description": "GUNAKAN HANYA JIKA penjaga bertanya spesifik tentang: nama blok, sektor, faksi, cuaca, harga, atau aturan. JANGAN GUNAKAN tool ini untuk pertanyaan basa-basi atau emosi (contoh: 'Kenapa kamu gugup?', 'Kamu monster ya?')."
      },
      "typeVersion": 1
    },
    {
      "id": "ee69dd6b-6f44-4ac9-b975-54bc58e4b4d2",
      "name": "Simple Vector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        -608,
        1040
      ],
      "parameters": {
        "mode": "insert",
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "BunkerGuard",
          "cachedResultName": "BunkerGuard"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "1cd9082f-29e0-4947-b080-4a12d46c627e",
      "name": "Embeddings Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        -608,
        1232
      ],
      "parameters": {},
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2bbb2d52-a658-4ae9-8fc5-2ee152624dff",
      "name": "Download File From Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -800,
        1040
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "url",
          "value": "=https://drive.google.com/file/d/1nT_ljZ8l4W4cF1K9vHJ4GrtTAh1pTvjX/view?usp=drive_link"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "869e8bb1-493f-478d-b58c-24016ca91045",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        688,
        1008
      ],
      "parameters": {
        "options": {
          "responseMode": "lastNode"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "72d496bc-e96d-4e8f-a8a9-4f54a99d5b32",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -976,
        1040
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "42828c0f-8df1-4c0b-b992-6cc754e91b7d",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        832,
        1008
      ],
      "parameters": {
        "text": "==Penjaga bertanya: \"{{ $json.chatInput }}\"\n\nTUGAS UTAMA AGEN (PENGGUNAAN TOOL):\n1. JIKA pertanyaan hanya basa-basi, menekan mental, atau pertanyaan emosi, LANGSUNG JAWAB SAJA TANPA TOOL agar respons cepat!\n2. JIKA pertanyaan spesifik soal RUTE, LOKASI, HARGA, JAM OPERASIONAL, FAKTA DUNIA, atau PROFESI, KAMU WAJIB MENGGUNAKAN tool \"Database_Bunker\" untuk mencari tahu faktanya terlebih dahulu sebelum merespons.",
        "options": {
          "systemMessage": "Kamu adalah Agen Penguji (Testing Bot) khusus untuk memeriksa fungsionalitas RAG (Database_Bunker) pada game \"Bunker Guard\".\n\nKARENA INI ADALAH MODE TESTING STANDALONE (Hanya menerima input chatInput):\n1. PENENTUAN STATUS (ROLE): Jika tester tidak menentukan peran di dalam teks chatInput, silakan kamu pilih secara acak (apakah menjadi MANUSIA ASLI atau DOPPELGANGER) lalu beraktinglah konsisten sesuai peran tersebut.\n2. TRIK COBA-COBA (FORCED ROLE): Tester bisa memaksa peranmu dengan memberikan tag di awal chat, seperti \"[MANUSIA]\" atau \"[DOPPELGANGER]\". Jika ada tag tersebut, kamu WAJIB mematuhinya untuk mempermudah testing!\n\nATURAN GAYA BAHASA & KONDISI:\n1. GUNAKAN BAHASA INDONESIA BAKU DAN FORMAL. Dilarang keras menggunakan bahasa daerah atau gaul. Nada bicaramu harus bernuansa sci-fi distopia (panik, dingin, lelah, atau memohon).\n2. KESADARAN RUANG: Kamu berada di LUAR GERBANG BUNKER (kaca kedap udara, tidak bisa menyerahkan dokumen fisik). Tujuanmu adalah meyakinkan penjaga agar diizinkan masuk. Jangan pernah berkata kamu sudah di dalam bunker.\n3. CARA MENYEBUT TEMPAT: Pisahkan profesi dan tempat tinggal (Contoh BENAR: \"Saya kasir di Pasar, kebetulan tinggal di Blok B\", bukan \"Saya kasir dari Blok B\").\n\nPENGGUNAAN FAKTA & LOGIKA AKTING (UNTUK VALIDASI DATA RAG):\n[JIKA KAMU BERPERAN SEBAGAI MANUSIA ASLI]:\n- Jawab SEMUA pertanyaan fakta dengan 100% AKURAT sesuai hasil pencarian dari tool \"Database_Bunker\".\n- KAMU DILARANG KERAS BERBOHONG. Jika ditanya hal/ruangan fiktif yang tidak tertera di data hasil tool, tolak dengan tegas dan jujur bahwa tempat/aturan itu tidak ada!\n\n[JIKA KAMU BERPERAN SEBAGAI DOPPELGANGER]:\n- JADILAH PEMBOHONG CERDAS: Gunakan tool \"Database_Bunker\" untuk mengintip data asli, lalu lakukan \"salah tipis\" pada angka/harga/lantai. Jika ditanya rute, sebutkan nama gedung dari tool tapi acak urutannya agar salah namun terdengar logis.\n- TAKTIK MENGHINDAR: Jika ditanya detail yang terlalu rumit, mengeluhlah kedinginan atau minta segera dibuka gerbangnya agar teralihkan.\n- KENA JEBAKAN FIKTIF: Jika ditanya hal/ruangan fiktif yang tidak ada di database, kamu WAJIB TERJEBAK dan mengiyakannya seolah-olah hal itu nyata ada!\n- JANGAN PERNAH MENGAKU bahwa kamu adalah Doppelganger.\n\nATURAN KRITIS (Format JSON wajib 1 baris, TANPA markdown ```json):\n{\n  \"reply\": \"Jawaban aktingmu di sini (Maksimal 100 karakter)\"\n}"
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "4e6d6f93-59c6-49ca-a1ba-a6c7c9d719d0",
      "name": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        928,
        1152
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "550a8c45-d66a-47c7-8509-414751a77a62",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1552,
        528
      ],
      "parameters": {
        "width": 512,
        "height": 1024,
        "content": "### **AI-Driven Game Backend: Bunker Guard RAG & NPC Engine**\n\nThis workflow is a comprehensive AI backend system designed to manage dynamic NPC interactions, a Retrieval-Augmented Generation (RAG) system for lore validation, and daily briefing logic for a dystopian investigation game.\n\n### **How it works**\n1. **Game State Trigger:** The webhook receives a structured payload from the game engine (containing data such as the current day, security level, morale, and player chat input).\n2. **Action Routing:** The **Switch** node routes the logic based on the `action` parameter (`init` for spawning NPCs, `chat` for interrogation, or `briefing` for daily intel).\n3. **Dynamic Knowledge Base:** Fetches lore documents from Google Drive, processes them via Embeddings, and stores them in a Vector Store so the AI has absolute factual references.\n4. **AI Roleplay & Intelligence:** **Google Gemini** acts as the game director, NPC creator, and actor. The AI is strictly programmed to follow rules for *Doppelgangers* (subtle lying) vs. Real Humans (truthful according to lore).\n5. **Strict JSON Delivery:** The system ensures responses are returned to the game client in pure JSON format, ready to be parsed by the gameplay scripts.\n\n### **Setup steps**\n1. **API Keys:** Enter your **Google Gemini API Key** in the credentials of the LLM and Embeddings nodes.\n2. **Knowledge Base:** Authenticate **Google Drive OAuth2** and ensure the lore PDF File ID is correct and accessible.\n3. **Webhook Setup:** Copy the n8n Webhook URL (Production/Test) and integrate it into the HTTP Request script in your game engine.\n4. **Data Ingestion:** Click \"Execute workflow\" on the Manual Trigger (bottom left) ONCE to download the PDF and load it into the Vector Store before starting to play.\n\n### **Requirements**\n- n8n instance (Local/Cloud).\n- Google Gemini API Key.\n- Google Drive API credentials (for RAG document ingestion)."
      },
      "typeVersion": 1
    },
    {
      "id": "716a22fd-605b-415d-9318-757e1182ded5",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        608
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 896,
        "content": "### **Section 1: Document Ingestion & RAG System**\n\nThis section is the foundation of the AI's memory. It feeds the AI with the game's world facts (e.g., block names, item prices, route status) to ensure NPC answers are consistent and free from hallucinations.\n\n### **How it works**\n1. **File Retrieval:** The **Google Drive** node directly downloads the reference lore document in PDF format.\n2. **Data Processing:** The **Default Data Loader** and **Recursive Character Text Splitter** nodes work together to break down the large document into smaller chunks (500 characters). This is crucial so the AI is not overwhelmed by long texts.\n3. **Embeddings & Vector Store:** The text chunks are converted into vectors using **Gemini Embeddings** and saved into the **In-Memory Vector Store**. This data is later retrieved by the **Database_Bunker** tool when the NPC is asked about specific facts."
      },
      "typeVersion": 1
    },
    {
      "id": "9e77da8c-0dc8-440e-887f-c2513adc563d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        480
      ],
      "parameters": {
        "color": 7,
        "width": 816,
        "height": 1216,
        "content": "### **Section 2: Main Game API & Logic Core**\n\nThis central section acts as the primary API endpoint for the game. It handles all incoming requests, routes them to the correct AI agent, and returns structured data to the game engine.\n\n### **How it works**\n1. **Webhook & Switch:** The **Webhook** receives the JSON payload from the game. The **Switch** node then routes the flow based on the `action` parameter (`briefing`, `init`, or `chat`).\n2. **Specialized Agents:** \n   - **DayClue creator:** Generates daily intel (weather, blocked routes, discounts) based on the player's morale stat.\n   - **npc creator:** Uses RNG to spawn an NPC profile (Real Human or Doppelganger) and generates their opening dialogue.\n   - **Chat Generator:** Handles the ongoing interrogation, following strict rules to either lie subtly (Doppelganger) or tell the exact truth (Human).\n3. **Context & LLM:** Powered by the **Google Gemini Chat Model**, utilizing **Simple Memory** to retain the interrogation context across multiple turns.\n4. **Respond to Webhook:** Ensures all AI outputs are cleanly formatted into pure JSON before being sent back to the game client."
      },
      "typeVersion": 1
    },
    {
      "id": "43753520-6a84-4412-84b1-19dbf3ae3e21",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        656,
        480
      ],
      "parameters": {
        "color": 7,
        "width": 528,
        "height": 1072,
        "content": "### **Section 3: RAG Testing & Database Tool**\n\nThis section contains the standalone testing environment and the vector store tool that the AI agents use to retrieve world facts dynamically.\n\n### **How it works**\n1. **Database_Bunker Tool:** This is the core RAG tool connected to the Vector Store. The agents in Section 2 use this tool to fact-check locations, prices, and rules before answering player questions.\n2. **Standalone Chat Testing:** The **When chat message received** trigger allows developers to interact with the AI directly via a chat interface, bypassing the game engine.\n3. **AI Agent (Testing Bot):** A dedicated agent configured to test the functionality of the `Database_Bunker` tool. It validates whether the AI can successfully retrieve and format data from the ingested lore document.\n4. **Window Buffer Memory:** Keeps track of the chat history specifically for this standalone testing interface."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "9a1196a3-1c9e-4964-8311-46bb58b3b403",
  "nodeGroups": [],
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "DayClue creator",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "npc creator",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Chat Generator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "npc creator": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Chat Generator",
            "type": "ai_memory",
            "index": 0
          },
          {
            "node": "npc creator",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Chat Generator": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Database_Bunker": {
      "ai_tool": [
        [
          {
            "node": "DayClue creator",
            "type": "ai_tool",
            "index": 0
          },
          {
            "node": "Chat Generator",
            "type": "ai_tool",
            "index": 0
          },
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "DayClue creator": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Simple Vector Store1",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Simple Vector Store": {
      "ai_vectorStore": [
        [
          {
            "node": "Database_Bunker",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini": {
      "ai_embedding": [
        [
          {
            "node": "Simple Vector Store1",
            "type": "ai_embedding",
            "index": 0
          },
          {
            "node": "Simple Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "npc creator",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "DayClue creator",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Chat Generator",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Database_Bunker",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File From Google Drive": {
      "main": [
        [
          {
            "node": "Simple Vector Store1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Download File From Google Drive",
            "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

This workflow powers dynamic character interactions for investigative games. It ingests lore from Google Drive into a vector database, using Google Gemini agents to generate daily briefings, spawn NPCs, and roleplay interrogations via a webhook. Runs on a manual trigger to…

Source: https://n8n.io/workflows/16885/ — 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

Camila IA. Uses postgres, crypto, redis, agent. Webhook trigger; 92 nodes.

Postgres, Crypto, Redis +13
AI & RAG

This workflow implements a complete Voice AI Chatbot system for Wordress that integrates speech recognition, guardrails for safety, retrieval-augmented generation (RAG), Qdrant vector search, and audi

OpenAI Chat, Memory Buffer Window, Tool Calculator +10
AI & RAG

This comprehensive n8n workflow template creates an intelligent AI chatbot that automatically transforms your Google Drive documents into a searchable knowledge base. The chatbot uses OpenAI's GPT mod

Text Splitter Recursive Character Text Splitter, Document Default Data Loader, In-Memory Vector Store +8
AI & RAG

RAG AI Agent. Uses lmChatOpenAi, memoryBufferWindow, googleDrive, documentDefaultDataLoader. Webhook trigger; 20 nodes.

OpenAI Chat, Memory Buffer Window, Google Drive +8
AI & RAG

Rag Workflow. Uses googleDrive, vectorStorePinecone, embeddingsGoogleGemini, documentDefaultDataLoader. Webhook trigger; 17 nodes.

Google Drive, Pinecone Vector Store, Google Gemini Embeddings +8