{
  "name": "Multi-Agent Handbook Generator",
  "nodes": [
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000001",
      "name": "Webhook (New Topic)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [-680, 300],
      "parameters": { "path": "handbook-generate" },
      "webhookId": "wh-handbook-001"
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000002",
      "name": "Set Topic",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-480, 300],
      "parameters": { "values": { "string": [
        { "name": "topic", "value": "={{$json.body.topic}}" },
        { "name": "audience", "value": "={{$json.body.audience || 'general'}}" }
      ]} }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000003",
      "name": "Outline Agent",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [-280, 300],
      "parameters": {
        "options": { "model": "gpt-4o", "temperature": 0.4, "maxTokens": 2000 },
        "messages": { "values": [{ "role": "user", "message": "Create a JSON array of sections for a handbook about: {{$json.topic}}. Each: {title, description, keyPoints[], wordCount}" }] }
      },
      "credentials": { "openAiApi": { "id": null, "name": "OpenAI API" } }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000004",
      "name": "Parse Outline",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-80, 300],
      "parameters": {
        "jsCode": "const raw = $input.first().json;\nconst text = raw.output || raw.text || '[]';\nlet sections;\ntry { sections = JSON.parse(text); } catch (e) { sections = [{ title: 'Overview', wordCount: 500 }]; }\nreturn sections.map((s, i) => ({ json: { topic: $node['Set Topic'].json.topic, section: s, idx: i, total: sections.length } }));"
      }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000005",
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 2,
      "position": [120, 300],
      "parameters": { "batchSize": 1 }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000006",
      "name": "Content Writer Agent",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [320, 300],
      "parameters": {
        "options": { "model": "gpt-4o", "temperature": 0.7, "maxTokens": 3000 },
        "messages": { "values": [{ "role": "user", "message": "Write handbook section: {{$json.section.title}}. Topic: {{$json.topic}}. Write ~{{$json.section.wordCount || 500}} words." }] }
      },
      "credentials": { "openAiApi": { "id": null, "name": "OpenAI API" } }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000007",
      "name": "Human Review Gate",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [520, 300],
      "parameters": {}
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000008",
      "name": "IF Approved?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [720, 300],
      "parameters": { "conditions": { "string": [{ "value1": "={{$json.approved}}", "operation": "equal", "value2": "approved" }] } }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000009",
      "name": "Polisher Agent",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [920, 200],
      "parameters": {
        "options": { "model": "gpt-4o", "temperature": 0.3, "maxTokens": 2000 },
        "messages": { "values": [{ "role": "user", "message": "Polish this content: {{$json.output || $json.text}}" }] }
      },
      "credentials": { "openAiApi": { "id": null, "name": "OpenAI API" } }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000010",
      "name": "Return for Rewrite",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [920, 480],
      "parameters": { "jsCode": "return [{ json: $node['Parse Outline'].json }];" }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000011",
      "name": "Accumulate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1120, 300],
      "parameters": {
        "jsCode": "const data = $getWorkflowStaticData('global');\nif (!data.sections) data.sections = [];\ndata.sections.push({ title: $node['Parse Outline'].json.section.title, content: $json.output });\nreturn [{ json: { done: data.sections.length >= $node['Parse Outline'].json.total } }];"
      }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000012",
      "name": "IF All Done?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [1320, 300],
      "parameters": { "conditions": { "boolean": [{ "value1": "={{$json.done}}", "operation": "equal", "value2": true }] } }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000013",
      "name": "Assemble",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1520, 200],
      "parameters": { "jsCode": "const d = $getWorkflowStaticData('global');\nlet h = '# ' + $node['Set Topic'].json.topic + '\\n\\n';\n(d.sections || []).forEach(s => { h += '## ' + s.title + '\\n\\n' + s.content + '\\n\\n---\\n\\n'; });\nreturn [{ json: { handbook: h } }];" }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000014",
      "name": "Upload to Notion",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [1720, 200],
      "parameters": { "operation": "create", "resource": "page", "title": "={{'Handbook: ' + $node['Set Topic'].json.topic}}" },
      "credentials": { "notionApi": { "id": null, "name": "Notion API" } }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000015",
      "name": "Slack Notify",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [1720, 400],
      "parameters": { "operation": "post", "resource": "message", "channel": "C0XXXXXXX" },
      "credentials": { "slackApi": { "id": null, "name": "Slack API" } }
    },
    {
      "id": "a7b8c9d0-7777-4000-8000-000000000016",
      "name": "Loop Back",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [1520, 500],
      "parameters": {}
    }
  ],
  "connections": {
    "Webhook (New Topic)": { "main": [[{ "node": "Set Topic", "type": "main", "index": 0 }]] },
    "Set Topic": { "main": [[{ "node": "Outline Agent", "type": "main", "index": 0 }]] },
    "Outline Agent": { "main": [[{ "node": "Parse Outline", "type": "main", "index": 0 }]] },
    "Parse Outline": { "main": [[{ "node": "SplitInBatches", "type": "main", "index": 0 }]] },
    "SplitInBatches": {
      "main": [
        [{ "node": "Content Writer Agent", "type": "main", "index": 0 }],
        [{ "node": "Accumulate", "type": "main", "index": 0 }]
      ]
    },
    "Content Writer Agent": { "main": [[{ "node": "Human Review Gate", "type": "main", "index": 0 }]] },
    "Human Review Gate": { "main": [[{ "node": "IF Approved?", "type": "main", "index": 0 }]] },
    "IF Approved?": {
      "main": [
        [{ "node": "Polisher Agent", "type": "main", "index": 0 }],
        [{ "node": "Return for Rewrite", "type": "main", "index": 0 }]
      ]
    },
    "Polisher Agent": { "main": [[{ "node": "Accumulate", "type": "main", "index": 0 }]] },
    "Return for Rewrite": { "main": [[{ "node": "Content Writer Agent", "type": "main", "index": 0 }]] },
    "Accumulate": { "main": [[{ "node": "IF All Done?", "type": "main", "index": 0 }]] },
    "IF All Done?": {
      "main": [
        [{ "node": "Assemble", "type": "main", "index": 0 }],
        [{ "node": "Loop Back", "type": "main", "index": 0 }]
      ]
    },
    "Assemble": { "main": [[{ "node": "Upload to Notion", "type": "main", "index": 0 }]] },
    "Upload to Notion": { "main": [[{ "node": "Slack Notify", "type": "main", "index": 0 }]] },
    "Loop Back": { "main": [[{ "node": "SplitInBatches", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "staticData": null,
  "pinData": {},
  "triggerCount": 1,
  "meta": { "templateCredsSetupCompleted": true }
}
