{
  "name": "AI Deep Research Agent",
  "nodes": [
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000001",
      "name": "When webhook received",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [-480, 300],
      "parameters": {
        "path": "deep-research",
        "options": {}
      },
      "webhookId": "wh-deep-research-001"
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000002",
      "name": "Set Research Parameters",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-280, 300],
      "parameters": {
        "values": {
          "string": [
            { "name": "researchQuestion", "value": "={{$json.body.question || $json.body.query || 'Latest advances in AI agent frameworks 2026'}}" },
            { "name": "depth", "value": "={{$json.body.depth || 'comprehensive'}}" },
            { "name": "maxIterations", "value": "={{$json.body.maxIterations || '3'}}" }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000003",
      "name": "Generate SERP Queries",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-80, 300],
      "parameters": {
        "jsCode": "const question = $input.first().json.researchQuestion;\nconst queries = [\n  question,\n  `${question} 2025 2026 latest`,\n  `${question} trends analysis`,\n  `${question} case study examples`\n];\nreturn queries.map((q, i) => ({ json: { query: q, iteration: 0, index: i } }));"
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000004",
      "name": "Web Search (Apify)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [120, 300],
      "parameters": {
        "url": "https://api.apify.com/v2/acts/apify~web-scraper/runs",
        "options": {},
        "method": "POST",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            { "name": "startUrls", "value": "[{ \"url\": \"https://www.google.com/search?q={{$json.query}}\" }]" },
            { "name": "maxPagesPerQuery", "value": "5" },
            { "name": "maxResults", "value": "10" }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": { "id": null, "name": "Apify API Token" }
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000005",
      "name": "Top 10 Organic Results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [320, 300],
      "parameters": {
        "jsCode": "const results = $input.all();\nconst items = [];\nfor (const item of results) {\n  const data = item.json;\n  if (data.results) {\n    for (const r of data.results.slice(0, 10)) {\n      items.push({ json: { title: r.title, url: r.url, snippet: r.snippet || r.text, source: r.domain } });\n    }\n  }\n}\nreturn items.length ? items.slice(0, 10) : [{ json: { title: 'No results', url: '', snippet: 'Search returned no results', source: '' } }];"
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000006",
      "name": "Extract Page Content",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [520, 300],
      "parameters": {
        "url": "={{$json.url}}",
        "options": {},
        "method": "GET",
        "authentication": "none",
        "sendBody": false
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000007",
      "name": "Summarize with OpenAI o3",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [720, 300],
      "parameters": {
        "options": {
          "model": "o3-mini",
          "temperature": 0.3,
          "maxTokens": 4000
        },
        "messages": {
          "values": [
            { "role": "system", "message": "You are a deep research assistant. Synthesize the provided web content into a comprehensive analysis." },
            { "role": "user", "message": "Research Question: {{$node['Set Research Parameters'].json.researchQuestion}}\n\nWeb Content:\n{{$json.snippet || $json.body?.substring(0, 8000)}}" }
          ]
        }
      },
      "credentials": {
        "openAiApi": { "id": null, "name": "OpenAI API" }
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000008",
      "name": "Aggregate Research Findings",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [920, 300],
      "parameters": {
        "jsCode": "const findings = $input.all();\nconst allContent = findings.map(f => f.json.output || f.json.text || JSON.stringify(f.json)).join('\\n\\n---\\n\\n');\nreturn [{ json: { aggregatedContent: allContent, sourceCount: findings.length } }];"
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000009",
      "name": "Generate Final Report",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [1120, 300],
      "parameters": {
        "options": {
          "model": "o3-mini",
          "temperature": 0.4,
          "maxTokens": 8000
        },
        "messages": {
          "values": [
            { "role": "system", "message": "You are a research report writer. Produce a markdown research report." },
            { "role": "user", "message": "Write a report on:\n\n{{$node['Set Research Parameters'].json.researchQuestion}}\n\nData:\n{{$json.aggregatedContent}}" }
          ]
        }
      },
      "credentials": {
        "openAiApi": { "id": null, "name": "OpenAI API" }
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000010",
      "name": "Upload to Notion",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [1340, 300],
      "parameters": {
        "operation": "create",
        "resource": "page",
        "title": "={{'Deep Research: ' + $node['Set Research Parameters'].json.researchQuestion}}",
        "content": "={{$json.output || $json.text}}"
      },
      "credentials": {
        "notionApi": { "id": null, "name": "Notion API" }
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000011",
      "name": "Webhook Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [1560, 300],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}"
      }
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000012",
      "name": "Error Handler",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [720, 580],
      "parameters": {}
    },
    {
      "id": "a1b2c3d4-1111-4000-8000-000000000013",
      "name": "Slack Error Alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [920, 580],
      "parameters": {
        "operation": "post",
        "resource": "message",
        "channel": "C0XXXXXXX",
        "text": "={{'❌ Deep Research Agent failed: ' + $json.errorMessage}}"
      },
      "credentials": {
        "slackApi": { "id": null, "name": "Slack API" }
      }
    }
  ],
  "connections": {
    "When webhook received": { "main": [[{ "node": "Set Research Parameters", "type": "main", "index": 0 }]] },
    "Set Research Parameters": { "main": [[{ "node": "Generate SERP Queries", "type": "main", "index": 0 }]] },
    "Generate SERP Queries": { "main": [[{ "node": "Web Search (Apify)", "type": "main", "index": 0 }]] },
    "Web Search (Apify)": { "main": [[{ "node": "Top 10 Organic Results", "type": "main", "index": 0 }]] },
    "Top 10 Organic Results": { "main": [[{ "node": "Extract Page Content", "type": "main", "index": 0 }]] },
    "Extract Page Content": { "main": [[{ "node": "Summarize with OpenAI o3", "type": "main", "index": 0 }]] },
    "Summarize with OpenAI o3": { "main": [[{ "node": "Aggregate Research Findings", "type": "main", "index": 0 }]] },
    "Aggregate Research Findings": { "main": [[{ "node": "Generate Final Report", "type": "main", "index": 0 }]] },
    "Generate Final Report": { "main": [[{ "node": "Upload to Notion", "type": "main", "index": 0 }]] },
    "Upload to Notion": { "main": [[{ "node": "Webhook Response", "type": "main", "index": 0 }]] },
    "Error Handler": { "main": [[{ "node": "Slack Error Alert", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "staticData": null,
  "pinData": {},
  "triggerCount": 1,
  "meta": { "templateCredsSetupCompleted": true }
}
