{
  "name": "Deep Research YT",
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5c28393f-6e8b-425b-babb-22eac9ad7238",
              "name": "GOOGLE_API_KEY",
              "value": "",
              "type": "string"
            },
            {
              "id": "7f935132-6cb7-43a4-ae87-77336bd2cf82",
              "name": "GOOGLE_CUSTOM_SEARCH",
              "value": "",
              "type": "string"
            },
            {
              "id": "a848bf0c-0a5f-4acc-9412-aebd93c84380",
              "name": "top_results",
              "value": "={{ $json.top_results ?? 3 }}",
              "type": "number"
            },
            {
              "id": "c52bbef3-c0a6-4017-a403-abaaee216895",
              "name": "context",
              "value": "={{ $json.context }}",
              "type": "string"
            },
            {
              "id": "ae883a9e-7207-48ef-ad1f-9c86076e0308",
              "name": "num_search_terms",
              "value": "={{ $json.num_search_terms ?? 2 }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        40,
        440
      ],
      "id": "dd3f31d6-c74d-445f-8829-b483a5393584",
      "name": "configuration"
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n    \"type\": \"object\",\n    \"properties\": {\n        \"search_terms\": {\n            \"type\": \"array\",\n            \"description\": \"the google search terms\",\n            \"items\": {\n                \"type\": \"string\"\n            }\n        }\n    },\n    \"required\": [\n        \"search_terms\"\n    ]\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        480,
        600
      ],
      "id": "dd4d1a04-7592-45ee-ba25-90a34636c573",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "fieldToSplitOut": "output.search_terms",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        640,
        440
      ],
      "id": "e007bc3d-d939-4bc6-8f9d-a8868be36cee",
      "name": "Split Out"
    },
    {
      "parameters": {
        "fieldToSplitOut": "items",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -160,
        740
      ],
      "id": "a9b7bfd0-e38f-4b0a-bb99-a318e2a26365",
      "name": "Split Out1"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "data",
              "cssSelector": "body",
              "returnValue": "html"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        720,
        740
      ],
      "id": "c2a8feee-2fa8-4065-8dfc-9abccbc39124",
      "name": "HTML"
    },
    {
      "parameters": {
        "html": "={{ $json.data }}",
        "options": {}
      },
      "type": "n8n-nodes-base.markdown",
      "typeVersion": 1,
      "position": [
        920,
        740
      ],
      "id": "f31374c5-f744-401c-9619-fed492f8a747",
      "name": "Markdown"
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n    \"type\": \"object\",\n    \"properties\": {\n        \"summary\": {\n            \"type\": \"string\",\n            \"description\": \"the summary of the content\"\n        }\n    },\n    \"required\": [\n        \"summary\"\n    ]\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        520,
        1200
      ],
      "id": "5fa60b87-6f32-4da1-a8b8-f75c8764a2ce",
      "name": "Structured Output Parser1"
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n    \"type\": \"object\",\n    \"properties\": {\n        \"relevant_to_context\": {\n            \"type\": \"boolean\",\n            \"description\": \"whether the researched content is relevant to the context\"\n        }\n    },\n    \"required\": [\n        \"relevant_to_article\"\n    ]\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        900,
        1200
      ],
      "id": "ae594259-f40a-4da7-92b8-8162db0e6c1c",
      "name": "Structured Output Parser2"
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "research_results",
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        280,
        1300
      ],
      "id": "379c7c74-f3d1-4761-98af-51c15a3b3ba6",
      "name": "Aggregate"
    },
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "top_results",
              "type": "number"
            },
            {
              "name": "context"
            },
            {
              "name": "num_search_terms",
              "type": "number"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -180,
        440
      ],
      "id": "bed72d54-c63a-47d3-b338-9cabba093dde",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=<Context>\n{{ $json.context }}\n</Context>\n\n<Instructions>\nI want to run a research on Google on the context above. \nHelp me to come up with search terms I can use.\nI need exactly {{ $json.num_search_terms }} search term(s) - no more no less. \nMake sure to be creative, and give me different ones so I can get diverse search results.\n</Instructions>",
        "hasOutputParser": true
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.5,
      "position": [
        260,
        440
      ],
      "id": "16dbcf16-f07a-4e7f-ae34-060271c3b77c",
      "name": "create search terms"
    },
    {
      "parameters": {
        "url": "https://www.googleapis.com/customsearch/v1",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "={{ $('configuration').item.json.GOOGLE_API_KEY }}"
            },
            {
              "name": "cx",
              "value": "={{ $('configuration').item.json.GOOGLE_CUSTOM_SEARCH }}"
            },
            {
              "name": "q",
              "value": "={{ $json['output.search_terms'] }}"
            },
            {
              "name": "num",
              "value": "={{ $('configuration').item.json.top_results }}"
            },
            {
              "name": "siteSearch",
              "value": "reddit.com"
            },
            {
              "name": "siteSearchFilter",
              "value": "e"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        860,
        440
      ],
      "id": "7ab16dc2-f0a2-455b-a8ee-de2320382325",
      "name": "search on Google",
      "retryOnFail": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c18ff56b-39fa-477c-a48d-bc65ad0a510d",
              "leftValue": "={{ $json.mime }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        60,
        740
      ],
      "id": "7ba5d899-e85f-4b21-bbec-2fc412f36b6e",
      "name": "remove documents"
    },
    {
      "parameters": {
        "url": "={{ $json.link }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "user-agent",
              "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        280,
        740
      ],
      "id": "790ea8d6-6e67-4b3e-8cef-49f1b9696aa8",
      "name": "get the content of the link",
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "99cf6ac1-d77b-491c-86dc-44555032f5b0",
              "leftValue": "={{ $json.error }}",
              "rightValue": "",
              "operator": {
                "type": "object",
                "operation": "notExists",
                "singleValue": true
              }
            },
            {
              "id": "e6dd1301-acb8-4dc4-83d0-4d5b1a7f2036",
              "leftValue": "={{ $json.data }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        500,
        740
      ],
      "id": "f656c689-3344-4af7-9d10-58dafe5fe07c",
      "name": "filter out the errors"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "e70a34f7-b723-47fe-a62f-1a318c483959",
              "leftValue": "={{ $json.data }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        -160,
        1020
      ],
      "id": "5c6ea18b-7690-4df0-8fc6-8647be1460c7",
      "name": "filter empty results"
    },
    {
      "parameters": {
        "jsCode": "for (const item of $input.all()) {\n  item.json.data = item.json.data.replace(/!\\[[^\\]]+\\]\\([^\\)]+\\)/g, \"\") // remove images\n  item.json.data = item.json.data.replace(/\\[.*?\\]\\(.*?\\)/g, \"\") // remove links\n  item.json.data = item.json.data.replace(/\\n{2,}/g, \"\") // remove extra new line characters\n}\n\nreturn $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        80,
        1020
      ],
      "id": "4f69457e-45d3-475a-96c8-9ce52e9e4838",
      "name": "cleanup the markdown"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=I've collected research content using Google search.\n\nRead the research content, and analyze whether it is relevant to the context below.\nMake sure it's also useful, and contains relevant information for my context.\n\n<Context>\n{{ $('configuration').item.json.context }}\n</Context>\n\n<ResearchContentSummary>\n{{ $json.output.summary }}\n</ResearchContentSummary>",
        "hasOutputParser": true
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.5,
      "position": [
        660,
        1020
      ],
      "id": "7c443aaa-e5d2-444b-a08b-be66f591c396",
      "name": "is it relevant?",
      "retryOnFail": true
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Please summarize the following content for me. Make sure to capture all the information in a concise format. Don't miss anything important.\nIgnore generic website elements like cookie policies, etc.\n\n<Content>\n{{ $json.data }}\n</Content>",
        "hasOutputParser": true
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.5,
      "position": [
        300,
        1020
      ],
      "id": "f454d11e-9d6e-48cb-9a1b-10796fad0be7",
      "name": "summarize",
      "retryOnFail": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "a72e5161-9b19-45fb-bb4f-5ae28d3da266",
              "leftValue": "={{ $json.output.relevant_to_context }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        -160,
        1300
      ],
      "id": "8daaee4f-1171-44dc-90c3-a753830948ad",
      "name": "filter irrelevant"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "53e16d12-8a90-4cf8-85e2-6aa2ef2ae3af",
              "name": "summary",
              "value": "={{ $('summarize').item.json.output.summary }}",
              "type": "string"
            },
            {
              "id": "1ca9f5a5-0e9a-47e6-9fef-079367dc4769",
              "name": "title",
              "value": "={{ $('remove documents').item.json.title }}",
              "type": "string"
            },
            {
              "id": "11c33d6b-d23c-4bc6-9003-b8ca022b3ada",
              "name": "link",
              "value": "={{ $('remove documents').item.json.link }}",
              "type": "string"
            },
            {
              "id": "eea8547b-2e21-4b71-a9dc-74639d658485",
              "name": "snippet",
              "value": "={{ $('remove documents').item.json.snippet }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        60,
        1300
      ],
      "id": "7157d6b9-248a-45cd-9c45-fa469be248cd",
      "name": "set fields to return"
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.0-flash",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        -440,
        1200
      ],
      "id": "d0578336-65bb-4196-bc94-9209c84befff",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "id": "VXDe3FcCxPr5Bejy",
          "name": "Google Gemini(PaLM) Api account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "configuration": {
      "main": [
        [
          {
            "node": "create search terms",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "create search terms",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "search on Google",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out1": {
      "main": [
        [
          {
            "node": "remove documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML": {
      "main": [
        [
          {
            "node": "Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Markdown": {
      "main": [
        [
          {
            "node": "filter empty results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser1": {
      "ai_outputParser": [
        [
          {
            "node": "summarize",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser2": {
      "ai_outputParser": [
        [
          {
            "node": "is it relevant?",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "create search terms": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "search on Google": {
      "main": [
        [
          {
            "node": "Split Out1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "remove documents": {
      "main": [
        [
          {
            "node": "get the content of the link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get the content of the link": {
      "main": [
        [
          {
            "node": "filter out the errors",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "filter out the errors": {
      "main": [
        [
          {
            "node": "HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "filter empty results": {
      "main": [
        [
          {
            "node": "cleanup the markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "cleanup the markdown": {
      "main": [
        [
          {
            "node": "summarize",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "is it relevant?": {
      "main": [
        [
          {
            "node": "filter irrelevant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "summarize": {
      "main": [
        [
          {
            "node": "is it relevant?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "filter irrelevant": {
      "main": [
        [
          {
            "node": "set fields to return",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set fields to return": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "create search terms",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "summarize",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "is it relevant?",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "fc98ae6b-dc19-4898-a5d3-2a2d8151f088",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "a5b16ce024831bb1911ebbfad7ce2421d85e49ef3fd85f5747f69ca2d85feb56"
  },
  "id": "QUrsmSPIuExpnFu3",
  "tags": []
}