{
  "nodes": [
    {
      "id": "2ea0c49a-6706-4272-8990-06f578c5c5a7",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -360,
        1080
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "a889197b-b78d-4808-948c-6d57883ee34f",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        920,
        1060
      ],
      "parameters": {
        "text": "=posts: {{ $json.text }}",
        "options": {
          "systemMessage": "=I'm looking for ideas for posts about  {{ $('Create Search Term').item.json.Search_Term }}\n\nHere's the last 5 posts on instagram about the topic. Use those to help me generate a list of relevent captions to post on my instagram. \n\ndo not make up ideas that are not like the others in the list. \n\noutput like this. \n\n{\n\t\"Post Idea\": [\"Idea1\", \"Idea2\"], \n  \"Most Common Post\":  [\"common post 1\", \"common post 2\"]\n}"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2
    },
    {
      "id": "47f4b1cb-9361-4aff-a439-2c8979fe93f4",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        960,
        1280
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2b0f574d-7976-469a-bf84-00a37ef15def",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1140,
        1280
      ],
      "parameters": {
        "jsonSchemaExample": "{\n\t\"Post Idea\": [\"Idea1\", \"Idea2\"], \n  \"Most Common Post\":  [\"common post 1\", \"common post 2\"]\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "00910de9-80ba-41c9-8200-81fcb6d15f45",
      "name": "Find Recent Posts",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        140,
        1120
      ],
      "parameters": {
        "url": "=https://api.apify.com/v2/acts/apify~instagram-hashtag-scraper/run-sync-get-dataset-items\n",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"hashtags\": [\n        \"{{ $json.Search_Term }}\"\n    ],\n    \"resultsLimit\": 20,\n    \"resultsType\": \"posts\"\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth"
      },
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5a62f897-74a6-4899-a8c9-a51a6d011373",
      "name": "Create Search Term",
      "type": "n8n-nodes-base.set",
      "position": [
        -140,
        1000
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ad5c9a23-7fe0-4ed4-b1e7-d3da417bcb86",
              "name": "Search_Term",
              "type": "string",
              "value": "n8n"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "33a01e12-8820-4184-92fb-6682470940b1",
      "name": "Set bio and follower count",
      "type": "n8n-nodes-base.set",
      "position": [
        440,
        920
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ac638d8c-fa83-4cf6-92af-e0489d7349dd",
              "name": "caption",
              "type": "string",
              "value": "={{ $json.caption }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "7275daae-bf7a-4c06-928a-16f0bfdc0a3b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        100
      ],
      "parameters": {
        "color": 3,
        "width": 780,
        "height": 1380,
        "content": "### 1\ufe0f\u20e3 Manual Trigger\n\n#### \ud83e\udde9 Node: `When clicking \u2018Execute workflow\u2019`\n- Manually starts the workflow for testing or single-run execution.\n\n---\n\n### 2\ufe0f\u20e3 Define the Hashtag\n\n#### \ud83e\udde9 Node: `Create Search Term`\n- Sets the value of the hashtag you'd like to scan.\n- Default is `n8n`, but you can modify it to anything.\n\n```json\n{\n  \"Search_Term\": \"yourCustomHashtag\"\n}\n```\n\n---\n\n### 3\ufe0f\u20e3 Scrape Instagram Posts\n\n#### \ud83e\udde9 Node: `Find Recent Posts`\n- **API**: [Apify Instagram Hashtag Scraper](https://console.apify.com/actors/apify/instagram-hashtag-scraper)\n- **Setup**:\n  - Visit [Apify Console](https://console.apify.com/)\n  - Create an API token\n  - In n8n, go to Credentials and add `HTTP Query Auth`\n  - Use `?token=yourTokenHere` as the query string\n\n**JSON Body:**\n```json\n{\n  \"hashtags\": [\"{{ $json.Search_Term }}\"],\n  \"resultsLimit\": 20,\n  \"resultsType\": \"posts\"\n}\n```\n\n---\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "09a04fbd-a16b-4166-a623-555770c81605",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        100
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 1380,
        "content": "\n### 4\ufe0f\u20e3 Extract Captions\n\n#### \ud83e\udde9 Node: `Set bio and follower count`\n- Extracts just the `caption` from each post and stores it in a clean variable for the AI agent to use.\n\n---\n\n### 5\ufe0f\u20e3 Aggregate Captions\n\n#### \ud83e\udde9 Node: `Aggregate`\n- Gathers all captions into one list before processing.\n- Useful for passing a large text block into the AI.\n\n---\n\n### 6\ufe0f\u20e3 Convert to Single Text Block\n\n#### \ud83e\udde9 Node: `Convert table names and columns into single text for agent`\n- Uses a `Code` node to combine all captions into a single string for OpenAI to read:\n```javascript\nreturn [\n  {\n    json: {\n      text: items\n        .map(item => `- ${JSON.stringify(item.json)}`)\n        .join('\\n\\n'),\n    },\n  },\n];\n```\n\n---"
      },
      "typeVersion": 1
    },
    {
      "id": "6a88d748-9563-49b8-9398-9d2032413f94",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        860,
        100
      ],
      "parameters": {
        "color": 6,
        "width": 420,
        "height": 1380,
        "content": "### 7\ufe0f\u20e3 Generate Caption Ideas with AI\n\n#### \ud83e\udde9 Node: `AI Agent`\n- Takes the combined post text and sends it to GPT-4o-mini.\n- Includes this system message:\n```text\nI'm looking for ideas for posts about {{ $('Create Search Term').item.json.Search_Term }}.\nHere\u2019s the last 5 posts on Instagram about the topic. Use those to help me generate a list of relevant captions.\n\nDo not make up ideas that are not like the others in the list.\n\nOutput like this:\n{\n  \"Post Idea\": [\"Idea1\", \"Idea2\"],\n  \"Most Common Post\": [\"common post 1\", \"common post 2\"]\n}\n```\n\n---\n\n### 8\ufe0f\u20e3 Choose Language Model\n\n#### \ud83e\udde9 Node: `OpenAI Chat Model`\n- **Model**: `gpt-4o-mini`\n- **Credential**: Use your OpenAI API key.\n  - Get it from: [OpenAI API Keys](https://platform.openai.com/account/api-keys)\n  - Add it in n8n under OpenAI credentials.\n\n---\n\n### 9\ufe0f\u20e3 Parse the AI Output\n\n#### \ud83e\udde9 Node: `Structured Output Parser`\n- Parses the GPT response into structured JSON:\n```json\n{\n  \"Post Idea\": [\"Idea1\", \"Idea2\"],\n  \"Most Common Post\": [\"common post 1\", \"common post 2\"]\n}\n```\n\n---\n"
      },
      "typeVersion": 1
    },
    {
      "id": "812c1007-ba56-4934-b88f-fcfe1f0bcf01",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        -80
      ],
      "parameters": {
        "width": 2320,
        "content": "## \ud83d\udcec Need More Help?\n\n**\ud83d\udc64 Robert Breen**  \nAutomation Consultant | AI Workflow Designer | n8n Expert  \n\ud83d\udce7 [robert@ynteractive.com](mailto:robert@ynteractive.com)  \n\ud83d\udd17 [LinkedIn](https://www.linkedin.com/in/robert-breen-29429625/)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "5fee94d6-f796-4785-a806-07714c2f0d64",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        600,
        1100
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "caption"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0381aa63-dfa9-4e94-9991-6b266325d8ad",
      "name": "Convert table names and columns into single text for agent",
      "type": "n8n-nodes-base.code",
      "position": [
        700,
        880
      ],
      "parameters": {
        "jsCode": "return [\n  {\n    json: {\n      text: items\n        .map(item => `- ${JSON.stringify(item.json)}`)\n        .join('\\n\\n'),\n    },\n  },\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "1d2af5fa-b9ef-401d-8b29-b0376d1317b4",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1400,
        1020
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "output['Post Idea']"
      },
      "typeVersion": 1
    },
    {
      "id": "12b8c5e9-3448-4459-ad9b-d6e1af7a7c84",
      "name": "Split Out1",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1420,
        1260
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "output['Most Common Post']"
      },
      "typeVersion": 1
    },
    {
      "id": "73fd8217-6eae-4ce5-a2b5-f0325ea9154e",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        1660,
        1140
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "a25480f7-c832-4f8c-80e7-5e1ebd486305",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1300,
        100
      ],
      "parameters": {
        "width": 620,
        "height": 1380,
        "content": "### \ud83d\udd1f Split the Outputs\n\n#### \ud83e\udde9 Nodes: `Split Out`, `Split Out1`\n- Separates the `Post Idea` list and `Most Common Post` list into individual items.\n\n---\n\n### \ud83d\udd01 Merge for Final Output\n\n#### \ud83e\udde9 Node: `Merge`\n- Combines the two split lists into one output stream.\n\n---"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split Out1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Convert table names and columns into single text for agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Find Recent Posts": {
      "main": [
        [
          {
            "node": "Set bio and follower count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Create Search Term": {
      "main": [
        [
          {
            "node": "Find Recent Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Set bio and follower count": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Create Search Term",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert table names and columns into single text for agent": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}