{
  "id": "QrV3NmOnfJYqmw1W",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Template 2: Content Pipeline - Research Agent",
  "tags": [],
  "nodes": [
    {
      "id": "d10fe179-0dc2-4b44-b0f0-170ec285614d",
      "name": "When Executed by Parent",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        208,
        304
      ],
      "parameters": {
        "inputSource": "passthrough"
      },
      "typeVersion": 1.1
    },
    {
      "id": "6182b41e-4148-4832-97a5-7c7528556988",
      "name": "Research Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        448,
        304
      ],
      "parameters": {
        "text": "=Topic: {{ $json.topic }}\nBrief: {{ $json.brief }}",
        "options": {
          "systemMessage": "You are a research assistant for a content pipeline. Given a topic and a brief, produce structured research notes that a downstream writer agent will use to draft an article.\n\nIn production, this agent would have real research tools (web search, vector store over internal docs, knowledge base retrieval). For this template, use your training knowledge to produce high-quality notes so readers can see the full pipeline flow without any external integrations.\n\nKeep research concise and high signal. Avoid filler. Focus on facts the writer can actually use.\n\nReturn ONLY valid JSON in this exact shape:\n{\n  \"topic\": \"the topic verbatim\",\n  \"keyFacts\": [\"4 to 8 important facts relevant to the brief\"],\n  \"angles\": [\"2 to 3 angles or framings worth exploring\"],\n  \"sourcesMentioned\": [\"notable sources, concepts, or references the writer should cite or allude to\"],\n  \"researchNotes\": \"2 to 3 paragraphs synthesizing the research into a usable brief for the writer\"\n}"
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "581ac102-b4c1-4142-a03b-d16e1f6dd94e",
      "name": "Parse Research Output",
      "type": "n8n-nodes-base.code",
      "position": [
        720,
        304
      ],
      "parameters": {
        "jsCode": "// Parse research agent output, merge with trigger input so full pipeline state flows through\nconst raw = $input.first().json;\nconst triggerIn = $('When Executed by Parent').first().json;\nlet research;\ntry {\n  const text = typeof raw.output === 'string' ? raw.output : JSON.stringify(raw.output);\n  const m = text.match(/\\{[\\s\\S]*\\}/);\n  research = JSON.parse(m ? m[0] : text);\n  if (!research.researchNotes) throw new Error('Missing researchNotes');\n} catch(e) {\n  research = {\n    topic: triggerIn.topic || '',\n    keyFacts: [],\n    angles: [],\n    sourcesMentioned: [],\n    researchNotes: '',\n    researchParseError: e.message\n  };\n}\n\nreturn {\n  json: {\n    ...triggerIn,\n    research: research\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "2332131f-2b38-42c7-8d6b-f4f8f0d70f9a",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -448,
        0
      ],
      "parameters": {
        "width": 620,
        "height": 820,
        "content": "## Research Subworkflow (for Content Pipeline)\n\n### How it works\nStandalone subworkflow called by the Content Pipeline parent. Gathers background notes on a topic:\n1. **Execute Workflow Trigger** (Passthrough): Receives the full pipeline state from the parent (topic, brief, loop counters).\n2. **Research Agent** (AI): Generates structured background notes on the topic.\n3. **Parse + Merge**: Parses the agent output and returns `{...triggerInput, research: {...}}` so the parent keeps the full state plus the new research field.\n\n### Setup\n- Must be saved and (for calls from an active parent) activated before the parent can reference it\n- Attach your **LLM credentials** to the Chat Model sub-node\n- Triggered by the parent via Execute Workflow; not called directly\n\n### Customization\n- Swap in a search-tool-equipped agent if you want real web retrieval instead of model recall\n- Tighten the prompt to produce shorter, more focused research notes\n- Replace with a simpler LLM chain if you don't need agent reasoning\n\nThis template is a learning companion to the Production AI Playbook, a series that explores strategies, shares best practices, and provides practical examples for building reliable AI systems in n8n."
      },
      "typeVersion": 1
    },
    {
      "id": "2fbd4fe7-c8de-4937-b79d-077ddb06db80",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        320,
        512
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "56cc8056-c98a-4bfb-b33e-76f2c12660e3",
  "connections": {
    "Research Agent": {
      "main": [
        [
          {
            "node": "Parse Research Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Research Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Parent": {
      "main": [
        [
          {
            "node": "Research Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}