{
  "name": "Generic Deep-Dive Research Agent",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "deep-dive-research",
        "options": {}
      },
      "id": "1",
      "name": "Slack Command / Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [200, 300]
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "id": "10",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [200, 500]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "messages": {
          "messageValues": [
            {
              "role": "system",
              "message": "You are an elite research coordinator. Your job is to take a single user research query and expand it into 3 distinct, highly targeted search queries that cover different dimensions of the topic (e.g., background/definitions, competitor analysis/current landscape, technical specifications/challenges).\n\nOutput ONLY a JSON array of strings containing the 3 queries. Do not include markdown formatting or backticks. Example: [\"query 1\", \"query 2\", \"query 3\"]"
            },
            {
              "role": "user",
              "message": "={{ $json.body?.query || $json.body?.text || $json.message?.text?.replace('/research ', '') || \"AI Agentic Workflows in Enterprise\" }}"
            }
          ]
        },
        "options": {
          "responseFormat": "json_object"
        }
      },
      "id": "2",
      "name": "AI Query Expander",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [450, 400]
    },
    {
      "parameters": {
        "jsCode": "const output = JSON.parse($input.first().json.choices[0].message.content);\nreturn output.map(query => ({ query }));"
      },
      "id": "3",
      "name": "Parse Queries",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [650, 400]
    },
    {
      "parameters": {
        "fieldToSplitOut": "query",
        "options": {}
      },
      "id": "4",
      "name": "Split Queries",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [850, 400]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.perplexity.ai/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "Bearer your_perplexity_api_key_here"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"sonar-pro\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"value\": \"You are an elite research assistant. Provide an extremely detailed, fact-filled analysis of the query. Include stats, direct sources, and real-world examples. Be concise but highly rigorous.\"\n    },\n    {\n      \"role\": \"user\",\n      \"value\": \"{{ $json.query }}\"\n    }\n  ]\n}",
        "options": {}
      },
      "id": "5",
      "name": "Perplexity Search",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1050, 400]
    },
    {
      "parameters": {
        "aggregateBy": "all",
        "options": {
          "keepOnlyUnique": true
        }
      },
      "id": "6",
      "name": "Aggregate Results",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [1250, 400]
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "messages": {
          "messageValues": [
            {
              "role": "system",
              "message": "You are an elite technical research director. Your task is to synthesize multiple search reports into a single, comprehensive, and highly structured 1,000+ word Markdown document.\n\nStructure requirements:\n- **Title**: A professional, dynamic title.\n- **Executive Summary**: 3 bullet points with the most critical insights.\n- **Deep-Dive Sections**: Synthesize findings into 3 logical technical sections.\n- **Citations & Sources**: A bulleted list of all references and facts found.\n- **Next Actions/Recommendations**: Practical suggestions for founders based on the research.\n\nUse professional, analytical language. Avoid fluff or conversational commentary."
            },
            {
              "role": "user",
              "message": "Here is the raw research data collected by our agents:\n\n{{ JSON.stringify($json) }}"
            }
          ]
        },
        "options": {}
      },
      "id": "7",
      "name": "Research Synthesizer (AI)",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [1450, 400]
    },
    {
      "parameters": {
        "fileContent": "={{ $json[\"choices\"][0][\"message\"][\"content\"] }}",
        "filePath": "=~/obsidian-vault/Research/Research-Report-{{ $node[\"Slack Command / Webhook\"].json[\"body\"][\"query\"].replace(/[^a-zA-Z0-9]/g, '-') || $node[\"Telegram Trigger\"].json[\"message\"][\"text\"].replace(/[^a-zA-Z0-9]/g, '-') || 'Deep-Dive' }}.md",
        "options": {}
      },
      "id": "8",
      "name": "Save to Second Brain",
      "type": "n8n-nodes-base.readWriteFileFromDisk",
      "typeVersion": 1,
      "position": [1650, 300]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $('Telegram Trigger').item ? true : false }}",
              "value2": true
            }
          ]
        }
      },
      "id": "11",
      "name": "Is Telegram?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [1650, 500]
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item?.json?.message?.chat?.id }}",
        "text": "📊 *Deep-Dive Research Complete!*\n\n*Topic:* {{ $('Telegram Trigger').item?.json?.message?.text?.replace('/research ', '') || 'Deep-Dive' }}\n*Outcome:* Beautiful 1,000+ word markdown report compiled and synced to your Obsidian vault.\n\n*Executive Summary:* \n{{ $json[\"choices\"][0][\"message\"][\"content\"].split('\\n').slice(0, 8).join('\\n') }}...",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "id": "12",
      "name": "Telegram Send",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [1900, 450]
    },
    {
      "parameters": {
        "channel": "general",
        "text": "📊 *Deep-Dive Research Complete!*\n\n*Topic:* {{ $('Slack Command / Webhook').item?.json?.body?.query || 'Deep-Dive' }}\n*Outcome:* Beautiful 1,000+ word markdown report compiled and synced to your Obsidian vault via Syncthing.\n\n*Executive Summary:* \n{{ $json[\"choices\"][0][\"message\"][\"content\"].split('\\n').slice(0, 8).join('\\n') }}..."
      },
      "id": "9",
      "name": "Slack Notification",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [1900, 600]
    }
  ],
  "connections": {
    "Slack Command / Webhook": {
      "main": [
        [
          {
            "node": "AI Query Expander",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "AI Query Expander",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Query Expander": {
      "main": [
        [
          {
            "node": "Parse Queries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Queries": {
      "main": [
        [
          {
            "node": "Split Queries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Queries": {
      "main": [
        [
          {
            "node": "Perplexity Search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Perplexity Search": {
      "main": [
        [
          {
            "node": "Aggregate Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Results": {
      "main": [
        [
          {
            "node": "Research Synthesizer (AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Research Synthesizer (AI)": {
      "main": [
        [
          {
            "node": "Save to Second Brain",
            "type": "main",
            "index": 0
          },
          {
            "node": "Is Telegram?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Telegram?": {
      "main": [
        [
          {
            "node": "Telegram Send",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Slack Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
