{
  "name": "Perplexity-style iterative research with Gemini and Google Search",
  "nodes": [
    {
      "id": "c350704e-408a-48a5-8cca-0f3000fd9964",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1580,
        -280
      ],
      "parameters": {
        "width": 440,
        "height": 620,
        "content": "### generate_query()\n- generates a search queries based on the User's question.\n- uses Gemini 2.0 Flash \n"
      }
    },
    {
      "id": "81280c83-b194-441b-98cc-0a1e3b32a3a7",
      "name": "Configs",
      "type": "n8n-nodes-base.set",
      "position": [
        -1880,
        -60
      ]
    },
    {
      "id": "ab01402a-5ae8-46e1-93f0-1297626ac61b",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1980,
        -280
      ],
      "parameters": {
        "width": 340,
        "height": 400,
        "content": "### Configs\n- `number_of_initial_queries` (*The number of initial search queries to generate.*): 3\n- `max_research_loops` (*The maximum number of research loops to perform*): 3\n\n### variables:\n- `curr"
      }
    },
    {
      "id": "200465bd-6af2-41dc-9a83-7726b8ea64eb",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -1540,
        200
      ]
    },
    {
      "id": "a124695f-cdd3-4990-bb03-df8ba0efaf9e",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -1260,
        180
      ]
    },
    {
      "id": "9f6dca8b-0ecd-4957-860e-bd2fd3757804",
      "name": "generate_query",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -1480,
        -60
      ]
    },
    {
      "id": "444dc185-c6eb-4bb8-910b-6be5425d6e8a",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -720,
        -60
      ]
    },
    {
      "id": "9a4f9f01-625b-4ae9-8204-39ce085f3a5d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -760,
        -420
      ],
      "parameters": {
        "width": 2120,
        "height": 560,
        "content": "## web_research()\n\nExecutes a web search using the native Google Search API tool in combination with Gemini 2.0 Flash.\n\n- use `HTTP Reqeust` node to send raw Gemini google_search query\n"
      }
    },
    {
      "id": "dd18d2e1-b134-41b4-acd8-04eb18fa0216",
      "name": "attach index as id",
      "type": "n8n-nodes-base.code",
      "position": [
        -120,
        -60
      ]
    },
    {
      "id": "89711398-353a-4183-98a3-0cd706331971",
      "name": "web_search",
      "type": "n8n-nodes-base.code",
      "position": [
        280,
        -60
      ]
    },
    {
      "id": "60608a5b-c516-489f-a349-d30d91679f8b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1680,
        -440
      ],
      "parameters": {
        "width": 1620,
        "height": 800,
        "content": "## reflection()\n\nIdentifies knowledge gaps and generates potential follow-up queries. \nAnalyzes the current summary to identify areas for further research \nand generates potential follow-up queries. \n"
      }
    },
    {
      "id": "b72e5a88-6843-40a5-bee0-12aa781006d7",
      "name": "merge web_search_result",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        480,
        -60
      ]
    },
    {
      "id": "d7adf3a8-8d06-4e9e-80fa-e4a39b80476c",
      "name": "history_web_research_result",
      "type": "n8n-nodes-base.redis",
      "position": [
        800,
        -60
      ]
    },
    {
      "id": "5914fadd-6916-4946-84d7-fd8bf4f4a816",
      "name": "history_web_research_result1",
      "type": "n8n-nodes-base.redis",
      "position": [
        1020,
        -60
      ]
    },
    {
      "id": "44ce8a55-9871-4135-bf0e-8321e003dc50",
      "name": "history_sources_gathered",
      "type": "n8n-nodes-base.redis",
      "position": [
        920,
        -220
      ]
    },
    {
      "id": "28cb4f10-7ebe-4ad6-a026-6a758964bd01",
      "name": "research_loop_count",
      "type": "n8n-nodes-base.redis",
      "position": [
        2400,
        -180
      ]
    },
    {
      "id": "01225071-cd0d-4a3b-a31b-fa888fc174b5",
      "name": "retrieve value",
      "type": "n8n-nodes-base.code",
      "position": [
        2700,
        -180
      ]
    },
    {
      "id": "b2ba1a2b-bb80-4f63-9b9c-bd5c48a71b26",
      "name": "If finish",
      "type": "n8n-nodes-base.if",
      "position": [
        3080,
        120
      ]
    },
    {
      "id": "2cefd8b8-bedc-4648-82cd-dd2d5c587645",
      "name": "search_query",
      "type": "n8n-nodes-base.set",
      "position": [
        -500,
        -60
      ]
    },
    {
      "id": "8b9eac0b-790b-4d81-bd03-fe246ec08d12",
      "name": "number_of_ran_queries",
      "type": "n8n-nodes-base.redis",
      "position": [
        -300,
        -60
      ]
    },
    {
      "id": "ede02fed-da90-46f2-b975-8a1dc4f03157",
      "name": "GeminiSearch",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        80,
        -60
      ]
    },
    {
      "id": "62514275-53d3-4dee-803f-138d79a23bbe",
      "name": "Build reflection request body",
      "type": "n8n-nodes-base.code",
      "position": [
        1760,
        -180
      ]
    },
    {
      "id": "5e9e6aa7-48fc-49bb-adac-fbaa81aac7fe",
      "name": "reflection",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1940,
        -180
      ]
    },
    {
      "id": "01399baa-cce0-451c-8880-d00ada86b06e",
      "name": "reflection_output_parse",
      "type": "n8n-nodes-base.code",
      "position": [
        2140,
        -180
      ]
    },
    {
      "id": "bca8cd04-3203-4fbe-a848-b87ad4bbb2b8",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3380,
        -440
      ],
      "parameters": {
        "width": 1160,
        "height": 800,
        "content": "## finalize_answer()\nPrepares the final output by deduplicating and formatting sources, then\n    combining them with the running summary to create a well-structured\n    research report with proper cit"
      }
    },
    {
      "id": "2813a76e-10ed-4c8d-91f8-0d76a10aa60e",
      "name": "Google Gemini Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        3440,
        160
      ]
    },
    {
      "id": "7c2a30b1-2d4a-4302-9584-24bb58d5baea",
      "name": "finalize_answer",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        3500,
        -80
      ]
    },
    {
      "id": "52106115-e901-461f-ae7b-0207ea8e7ac2",
      "name": "get:history_sources_gathered",
      "type": "n8n-nodes-base.redis",
      "position": [
        3880,
        -60
      ]
    },
    {
      "id": "beeedb7e-1c37-416b-9535-4a1c78bb871d",
      "name": "format answer",
      "type": "n8n-nodes-base.code",
      "position": [
        4340,
        -140
      ]
    },
    {
      "id": "08544dfa-830e-44cf-b1ed-a8767c10b7ab",
      "name": "web_search step record",
      "type": "n8n-nodes-base.code",
      "position": [
        520,
        -340
      ]
    },
    {
      "id": "7f6a3582-9102-43fb-8e83-1a30979f3c19",
      "name": "push web_search step record",
      "type": "n8n-nodes-base.redis",
      "position": [
        720,
        -340
      ]
    },
    {
      "id": "71962197-cf8d-45c9-877e-128f16b72ab9",
      "name": "push reflection step",
      "type": "n8n-nodes-base.redis",
      "position": [
        2960,
        -220
      ]
    },
    {
      "id": "9da14360-e877-4be9-a17d-7a19532886b8",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        4140,
        -140
      ]
    },
    {
      "id": "a3b73cfb-274c-4d1c-bcb2-7c2b74c9e8d0",
      "name": "get:steps",
      "type": "n8n-nodes-base.redis",
      "position": [
        3860,
        -260
      ]
    },
    {
      "id": "eb254b2b-1fd0-4bde-ad3b-7364e787bdd7",
      "name": "set search_query",
      "type": "n8n-nodes-base.set",
      "position": [
        -960,
        -60
      ]
    },
    {
      "id": "cf181d8a-aad9-4851-9510-acb6c5d85b03",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -2220,
        -60
      ]
    },
    {
      "id": "ab4f6234-eff9-4621-86fd-7ad3a2d23244",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1980,
        -540
      ],
      "parameters": {
        "width": 800,
        "height": 220,
        "content": "# gemini-fullstack-langgraph-quickstart-n8n\n\nThis is a reproduction of `gemini-fullstack-langgraph-quickstart` in **N8N**, nearly 1:1\n\nThe [`gemini‑fullstack‑langgraph‑quickstart`](https://github.com/"
      }
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "format answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configs": {
      "main": [
        [
          {
            "node": "generate_query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If finish": {
      "main": [
        [
          {
            "node": "finalize_answer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "set search_query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "search_query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get:steps": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "reflection": {
      "main": [
        [
          {
            "node": "reflection_output_parse",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "web_search": {
      "main": [
        [
          {
            "node": "merge web_search_result",
            "type": "main",
            "index": 0
          },
          {
            "node": "web_search step record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GeminiSearch": {
      "main": [
        [
          {
            "node": "web_search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "search_query": {
      "main": [
        [
          {
            "node": "number_of_ran_queries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "generate_query": {
      "main": [
        [
          {
            "node": "set search_query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "retrieve value": {
      "main": [
        [
          {
            "node": "If finish",
            "type": "main",
            "index": 0
          },
          {
            "node": "push reflection step",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "finalize_answer": {
      "main": [
        [
          {
            "node": "get:history_sources_gathered",
            "type": "main",
            "index": 0
          },
          {
            "node": "get:steps",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set search_query": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "attach index as id": {
      "main": [
        [
          {
            "node": "GeminiSearch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "research_loop_count": {
      "main": [
        [
          {
            "node": "retrieve value",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "number_of_ran_queries": {
      "main": [
        [
          {
            "node": "attach index as id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "web_search step record": {
      "main": [
        [
          {
            "node": "push web_search step record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "merge web_search_result": {
      "main": [
        [
          {
            "node": "history_web_research_result",
            "type": "main",
            "index": 0
          },
          {
            "node": "history_sources_gathered",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "reflection_output_parse": {
      "main": [
        [
          {
            "node": "research_loop_count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "generate_query",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "generate_query",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "finalize_answer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Configs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "history_web_research_result": {
      "main": [
        [
          {
            "node": "history_web_research_result1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get:history_sources_gathered": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "history_web_research_result1": {
      "main": [
        [
          {
            "node": "Build reflection request body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build reflection request body": {
      "main": [
        [
          {
            "node": "reflection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}