{
  "name": "02-AI-Council",
  "nodes": [
    {
      "parameters": {},
      "id": "start",
      "name": "Start",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "message",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "messages": {
          "values": [
            {
              "content": "=You are a RESEARCH AGENT in an AI council for lead qualification.\n\nAnalyze this lead data and provide research insights:\n- Lead Score: {{ $json.leadScore }}\n- Qualification: {{ $json.qualification }}\n- Goal: {{ $json.leadData.goal || 'Not specified' }}\n- Budget: {{ $json.leadData.budget || 'Not specified' }}\n- Timeline: {{ $json.leadData.timeline || 'Not specified' }}\n- Industry: {{ $json.leadData.industry || 'Not specified' }}\n\nProvide:\n1. Industry trends relevant to this lead\n2. Potential pain points based on their goal\n3. Suggested approach for engagement\n4. Competitive landscape insights\n\nOutput as JSON with keys: research_summary, industry_trends, pain_points, suggested_approach, recommendations"
            }
          ]
        },
        "options": {
          "temperature": 0.6,
          "maxTokens": 800,
          "responseFormat": "json_object"
        }
      },
      "id": "research-agent",
      "name": "Research Agent",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.4,
      "position": [
        500,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const input = $input.all()[0].json;\nlet research = {};\n\ntry {\n  research = JSON.parse(input.output || '{}');\n} catch (e) {\n  research = {\n    research_summary: input.output,\n    recommendations: []\n  };\n}\n\nreturn [{\n  json: {\n    ...input,\n    research\n  }\n}];"
      },
      "id": "parse-research",
      "name": "Parse Research",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        750,
        300
      ]
    },
    {
      "parameters": {
        "operation": "message",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "messages": {
          "values": [
            {
              "content": "=You are a DECISION AGENT in an AI council.\n\nBased on the research provided, make strategic decisions for this lead.\n\nLead Data:\n- Score: {{ $json.leadScore }}\n- Qualification: {{ $json.qualification }}\n- Budget: {{ $json.leadData.budget || 'Unknown' }}\n\nResearch Summary:\n{{ JSON.stringify($json.research) }}\n\nDecide:\n1. Priority level (1-5, where 5 is highest)\n2. Next action: 'schedule_demo', 'send_case_study', 'nurture_sequence', 'assign_to_sales', or 'qualify_further'\n3. Personalization notes for outreach\n4. Urgency assessment\n5. Estimated deal value\n\nOutput as JSON with keys: priority, next_action, personalization_notes, urgency, estimated_value, reasoning"
            }
          ]
        },
        "options": {
          "temperature": 0.5,
          "maxTokens": 600,
          "responseFormat": "json_object"
        }
      },
      "id": "decision-agent",
      "name": "Decision Agent",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.4,
      "position": [
        1000,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const input = $input.all()[0].json;\nlet decision = {};\n\ntry {\n  decision = JSON.parse(input.output || '{}');\n} catch (e) {\n  decision = {\n    priority: 3,\n    next_action: 'nurture_sequence',\n    reasoning: input.output\n  };\n}\n\nreturn [{\n  json: {\n    ...input,\n    decision\n  }\n}];"
      },
      "id": "parse-decision",
      "name": "Parse Decision",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "message",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "messages": {
          "values": [
            {
              "content": "=You are an OPTIMIZER AGENT in an AI council.\n\nReview the research and decision made by other agents and provide optimization suggestions.\n\nCurrent Decision:\n{{ JSON.stringify($json.decision) }}\n\nResearch:\n{{ JSON.stringify($json.research) }}\n\nAnalyze and provide:\n1. Alternative approaches (if the current plan fails)\n2. Risk assessment (low/medium/high)\n3. Success probability (0-100%)\n4. A/B test suggestions for outreach\n5. Performance benchmarks to track\n\nOutput as JSON with keys: alternatives, risk_level, success_probability, ab_test_suggestions, benchmarks, optimization_notes"
            }
          ]
        },
        "options": {
          "temperature": 0.4,
          "maxTokens": 600,
          "responseFormat": "json_object"
        }
      },
      "id": "optimizer-agent",
      "name": "Optimizer Agent",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.4,
      "position": [
        1500,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const input = $input.all()[0].json;\nlet optimization = {};\n\ntry {\n  optimization = JSON.parse(input.output || '{}');\n} catch (e) {\n  optimization = {\n    success_probability: 50,\n    risk_level: 'medium',\n    notes: input.output\n  };\n}\n\n// Compile final council output\nconst councilOutput = {\n  leadData: input.leadData,\n  leadScore: input.leadScore,\n  qualification: input.qualification,\n  council: {\n    research: input.research,\n    decision: input.decision,\n    optimization\n  },\n  finalRecommendation: {\n    action: input.decision?.next_action || 'nurture_sequence',\n    priority: input.decision?.priority || 3,\n    successProbability: optimization.success_probability || 50,\n    riskLevel: optimization.risk_level || 'medium'\n  },\n  processedAt: new Date().toISOString()\n};\n\nreturn [{ json: councilOutput }];"
      },
      "id": "compile-output",
      "name": "Compile Council Output",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1750,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.finalRecommendation.action }}",
              "value2": "schedule_demo",
              "operation": "equals"
            }
          ]
        }
      },
      "id": "route-action",
      "name": "Route by Action",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 2,
      "position": [
        2000,
        300
      ]
    },
    {
      "parameters": {
        "workflowId": "={{ $env.CRM_WORKFLOW_ID }}",
        "options": {}
      },
      "id": "execute-crm",
      "name": "Create CRM Entry",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1,
      "position": [
        2250,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Research Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Research Agent": {
      "main": [
        [
          {
            "node": "Parse Research",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Research": {
      "main": [
        [
          {
            "node": "Decision Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decision Agent": {
      "main": [
        [
          {
            "node": "Parse Decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Decision": {
      "main": [
        [
          {
            "node": "Optimizer Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Optimizer Agent": {
      "main": [
        [
          {
            "node": "Compile Council Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compile Council Output": {
      "main": [
        [
          {
            "node": "Route by Action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Action": {
      "main": [
        [
          {
            "node": "Create CRM Entry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": [
    {
      "name": "ai-council",
      "createdAt": "2026-01-19T00:00:00.000Z"
    },
    {
      "name": "multi-agent",
      "createdAt": "2026-01-19T00:00:00.000Z"
    }
  ]
}