{
  "name": "Vorlux AI | Agent Collaboration",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "agent-collab",
        "options": { "responseMode": "lastNode" }
      },
      "id": "webhook-trigger",
      "name": "Collaboration Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [220, 300]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const data = $input.first().json.body || $input.first().json;\nconst task = data.task || {};\nconst agents = data.agents || [];\nconst mode = data.mode || 'sequential'; // sequential | parallel | review-chain\n\nconst steps = agents.map((agentId, i) => ({\n  step: i + 1,\n  agentId,\n  status: 'pending',\n  input: i === 0 ? task : null,\n  output: null\n}));\n\nreturn [{ json: { taskId: task.id || 'collab-' + Date.now(), task, mode, steps, totalAgents: agents.length, startedAt: new Date().toISOString() } }];"
      },
      "id": "plan-collaboration",
      "name": "Plan Collaboration Steps",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/agents/dispatch-multi",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ taskId: $json.taskId, steps: $json.steps, mode: $json.mode }) }}",
        "options": { "timeout": 60000 }
      },
      "id": "dispatch-multi",
      "name": "Dispatch Multi-Agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [700, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/memory/log",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ type: 'collaboration', taskId: $('Plan Collaboration Steps').first().json.taskId, agents: $('Plan Collaboration Steps').first().json.steps.map(s => s.agentId), mode: $('Plan Collaboration Steps').first().json.mode }) }}",
        "options": { "timeout": 10000 }
      },
      "id": "log-collaboration",
      "name": "Log Collaboration",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [940, 200]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ content: '🤝 **Multi-Agent Collaboration Started**\\nTask: ' + $('Plan Collaboration Steps').first().json.taskId + '\\nMode: ' + $('Plan Collaboration Steps').first().json.mode + '\\nAgents: ' + $('Plan Collaboration Steps').first().json.steps.map(s => s.agentId).join(' → ') }) }}"
      },
      "id": "discord-notify",
      "name": "Discord Notify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [940, 400]
    }
  ],
  "connections": {
    "Collaboration Webhook": { "main": [[{ "node": "Plan Collaboration Steps", "type": "main", "index": 0 }]] },
    "Plan Collaboration Steps": { "main": [[{ "node": "Dispatch Multi-Agent", "type": "main", "index": 0 }]] },
    "Dispatch Multi-Agent": { "main": [[{ "node": "Log Collaboration", "type": "main", "index": 0 }, { "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
