{
  "name": "\ud83e\udd16 Trigger CrewAI Agent",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "trigger-agent",
        "responseMode": "responseNode",
        "options": {}
      },
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        300,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "http://host.docker.internal:8010/crews/research",
        "jsonParameters": true,
        "options": {
          "timeout": 30000
        },
        "bodyParametersJson": "={{ JSON.stringify({ \"topic\": $json.body.topic || \"AI trends in 2024\", \"output_type\": $json.body.output_type || \"report\", \"llm_provider\": $json.body.llm_provider || null, \"llm_model\": $json.body.llm_model || null }) }}"
      },
      "name": "Start Research Crew",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        550,
        300
      ]
    },
    {
      "parameters": {
        "amount": 5,
        "unit": "seconds"
      },
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        800,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "GET",
        "url": "=http://host.docker.internal:8010/jobs/{{ $node['Start Research Crew'].json.job_id }}",
        "options": {
          "timeout": 10000
        }
      },
      "name": "Check Job Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.status }}",
              "operation": "equals",
              "value2": "completed"
            }
          ]
        }
      },
      "name": "Is Completed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1300,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.status }}",
              "operation": "equals",
              "value2": "failed"
            }
          ]
        }
      },
      "name": "Is Failed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1300,
        500
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ \"success\": true, \"job_id\": $node['Start Research Crew'].json.job_id, \"result\": $json.result }) }}"
      },
      "name": "Return Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1550,
        200
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ \"success\": false, \"job_id\": $node['Start Research Crew'].json.job_id, \"error\": $json.error }) }}",
        "options": {
          "responseCode": 500
        }
      },
      "name": "Return Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1550,
        500
      ]
    },
    {
      "parameters": {
        "loopCount": 60,
        "options": {}
      },
      "name": "Loop",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        1550,
        700
      ]
    },
    {
      "parameters": {
        "amount": 10,
        "unit": "seconds"
      },
      "name": "Wait More",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1800,
        700
      ]
    },
    {
      "parameters": {
        "requestMethod": "GET",
        "url": "=http://host.docker.internal:8010/jobs/{{ $node['Start Research Crew'].json.job_id }}",
        "options": {
          "timeout": 10000
        }
      },
      "name": "Poll Job Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        2050,
        700
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.status }}",
              "operation": "equals",
              "value2": "completed"
            }
          ]
        }
      },
      "name": "Poll Completed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        2300,
        700
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ \"success\": true, \"job_id\": $node['Start Research Crew'].json.job_id, \"result\": $json.result }) }}"
      },
      "name": "Return Poll Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        2550,
        600
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.status }}",
              "operation": "equals",
              "value2": "failed"
            }
          ]
        }
      },
      "name": "Poll Failed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        2550,
        800
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ \"success\": false, \"job_id\": $node['Start Research Crew'].json.job_id, \"error\": $json.error }) }}",
        "options": {
          "responseCode": 500
        }
      },
      "name": "Return Poll Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        2800,
        750
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Start Research Crew"
          }
        ]
      ]
    },
    "Start Research Crew": {
      "main": [
        [
          {
            "node": "Wait"
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Check Job Status"
          }
        ]
      ]
    },
    "Check Job Status": {
      "main": [
        [
          {
            "node": "Is Completed?"
          }
        ]
      ]
    },
    "Is Completed?": {
      "main": [
        [
          {
            "node": "Return Success"
          }
        ],
        [
          {
            "node": "Is Failed?"
          }
        ]
      ]
    },
    "Is Failed?": {
      "main": [
        [
          {
            "node": "Return Error"
          }
        ],
        [
          {
            "node": "Loop"
          }
        ]
      ]
    },
    "Loop": {
      "main": [
        [
          {
            "node": "Wait More"
          }
        ]
      ]
    },
    "Wait More": {
      "main": [
        [
          {
            "node": "Poll Job Status"
          }
        ]
      ]
    },
    "Poll Job Status": {
      "main": [
        [
          {
            "node": "Poll Completed?"
          }
        ]
      ]
    },
    "Poll Completed?": {
      "main": [
        [
          {
            "node": "Return Poll Success"
          }
        ],
        [
          {
            "node": "Poll Failed?"
          }
        ]
      ]
    },
    "Poll Failed?": {
      "main": [
        [
          {
            "node": "Return Poll Error"
          }
        ],
        [
          {
            "node": "Loop"
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionTimeout": 600
  }
}