{
  "name": "Web Research Agent Pipeline",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * 1-5"
            }
          ]
        }
      },
      "name": "Cron Trigger",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Generate topics from a predefined list or external source\nconst topics = [\n  'artificial intelligence trends 2024',\n  'quantum computing breakthroughs',\n  'climate technology solutions',\n];\nconst topic = topics[Math.floor(Math.random() * topics.length)];\nreturn [{ json: { topic, timestamp: new Date().toISOString() } }];"
      },
      "name": "Select Research Topic",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "command": "cd /opt/web-research-agent && python -m src.cli research \"{{ $json.topic }}\" --output /tmp/reports/{{ $json.topic | replace(' ', '_') }}.html --max-sources 8"
      },
      "name": "Run Research Agent",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const exitCode = $input.first().json.exitCode;\nif (exitCode !== 0) {\n  throw new Error('Research agent failed: ' + $input.first().json.stderr);\n}\nconst topic = $('Select Research Topic').first().json.topic;\nconst reportPath = '/tmp/reports/' + topic.replace(/ /g, '_') + '.html';\nreturn [{ json: { success: true, reportPath, topic } }];"
      },
      "name": "Check Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "filePath": "={{ $json.reportPath }}"
      },
      "name": "Read Report File",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        1120,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "research-agent@example.com",
        "toEmail": "team@example.com",
        "subject": "=Research Report: {{ $('Select Research Topic').first().json.topic }}",
        "html": "=<p>Your automated research report is attached.</p><p><strong>Topic:</strong> {{ $('Select Research Topic').first().json.topic }}</p><p>Report generated at {{ $('Select Research Topic').first().json.timestamp }}</p>",
        "attachments": "data"
      },
      "name": "Email Report",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        1340,
        300
      ]
    },
    {
      "parameters": {
        "content": "=## Research Report Ready\\n\\n**Topic:** {{ $('Select Research Topic').first().json.topic }}\\n**Time:** {{ $('Select Research Topic').first().json.timestamp }}\\n\\nReport saved to `{{ $('Check Result').first().json.reportPath }}`",
        "channel": "#research-reports"
      },
      "name": "Slack Notification",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [
        1340,
        460
      ]
    }
  ],
  "connections": {
    "Cron Trigger": {
      "main": [
        [
          {
            "node": "Select Research Topic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Research Topic": {
      "main": [
        [
          {
            "node": "Run Research Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Research Agent": {
      "main": [
        [
          {
            "node": "Check Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Result": {
      "main": [
        [
          {
            "node": "Read Report File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Report File": {
      "main": [
        [
          {
            "node": "Email Report",
            "type": "main",
            "index": 0
          },
          {
            "node": "Slack Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner"
  },
  "id": "web-research-agent-workflow",
  "tags": [
    {
      "name": "research"
    },
    {
      "name": "automation"
    },
    {
      "name": "ai"
    }
  ]
}