{
  "id": "mHSoMMyypmRzfVZn",
  "name": "CFO forecasting Agent",
  "tags": [],
  "nodes": [
    {
      "id": "b946638e-ba68-4d73-816e-00f3a63d138f",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1420,
        220
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"forecast\": {\n    \"June 2025\": \"$X,XXX.XX\",\n    \"July 2025\": \"$X,XXX.XX\",\n    \"August 2025\": \"$X,XXX.XX\"\n  },\n  \"trend\": \"Increasing / Decreasing / Stable\",\n  \"confidence\": \"High / Medium / Low\",\n  \"insights\": \"Short explanation of why this trend is predicted.\"\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "d80c3670-e8c8-43ee-ba12-2e0e18b99862",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1180,
        220
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "bb75cafb-9dad-4952-89af-0658c4d88aa4",
      "name": "Pinecone Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        1200,
        400
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "options": {},
        "toolName": "Sales_data",
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "new",
          "cachedResultName": "new"
        },
        "toolDescription": "The data about stripe sales"
      },
      "credentials": {
        "pineconeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "7d370700-89d9-4163-8070-4a0c643531ca",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1140,
        600
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "81de1ecf-75de-44fd-9e62-c381e907c1e1",
      "name": "Run Daily Forecast",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9ce2e0e4-8784-4ed9-9499-b5f54241d04e",
      "name": "Fetch Stripe Charges",
      "type": "n8n-nodes-base.stripe",
      "position": [
        220,
        0
      ],
      "parameters": {
        "resource": "charge",
        "operation": "getAll",
        "returnAll": true
      },
      "typeVersion": 1
    },
    {
      "id": "c115eb0c-6877-46db-bf03-55e48527dbc5",
      "name": "Summarize Sales",
      "type": "n8n-nodes-base.code",
      "position": [
        440,
        0
      ],
      "parameters": {
        "jsCode": "const charges = items.map(item => item.json);\nconst summary = charges.reduce((acc, charge) => {\n  const date = new Date(charge.created * 1000).toISOString().split(\"T\")[0];\n  acc[date] = (acc[date] || 0) + charge.amount / 100;\n  return acc;\n}, {});\nreturn [{ json: { summary } }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "fb33581a-9f41-49d7-a722-a68dfe5bc265",
      "name": "Prepare data",
      "type": "n8n-nodes-base.set",
      "position": [
        660,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "6aa7f5d2-3aa4-4d4c-85df-0d56bb7b6c9e",
              "name": "summary",
              "type": "string",
              "value": "={{ $json.summary }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d3458681-2654-4e22-8b2d-1711b60ed592",
      "name": "Forecaster agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1240,
        0
      ],
      "parameters": {
        "text": "=You are a CFO AI Agent. Based on the following Stripe sales data:\n\n{{ $json.summary }}\n\nAnalyze the trends, identify any patterns (growth, decline, seasonality), and forecast expected daily or weekly revenue for the next 3 months.",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "325e4952-868c-460a-aa78-2e718477cc78",
      "name": "Save Forecast to Supabase",
      "type": "n8n-nodes-base.supabase",
      "position": [
        2100,
        -160
      ],
      "parameters": {
        "dataToSend": "autoMapInputData"
      },
      "typeVersion": 1
    },
    {
      "id": "9fd6efab-edc6-49be-9516-f2d36e1995b2",
      "name": "Log Forecast in Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2100,
        120
      ],
      "parameters": {
        "columns": {
          "value": {
            "trend": "={{ $json.output.trend }}",
            "forecast": "={{ $json.output.forecast }}",
            "insights": "={{ $json.output.insights }}",
            "confidence": "={{ $json.output.confidence }}"
          },
          "schema": [
            {
              "id": "forecast",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "forecast",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "trend",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "trend",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "confidence",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "confidence",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "insights",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "insights",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/108tyyL--yUCbDk4drB__eztLSwjlxcmoRkqYsFnMLrY/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "108tyyL--yUCbDk4drB__eztLSwjlxcmoRkqYsFnMLrY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/108tyyL--yUCbDk4drB__eztLSwjlxcmoRkqYsFnMLrY/edit?usp=drivesdk",
          "cachedResultName": "CFO Forecasting"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "241e625d-7019-4919-9f93-137461ad94bf",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -1820
      ],
      "parameters": {
        "color": 3,
        "width": 840,
        "height": 2120,
        "content": "## 1\ufe0f\u20e3 **\ud83d\udd01 Data Retrieval & Preprocessing**\n\n**Nodes:**\n\n* \ud83d\udd52 `Run Daily Forecast`\n* \ud83d\udfe6 `Fetch Stripe Charges`\n* \ud83e\udde9 `Summarize Daily Sales`\n* \u270f\ufe0f `Prepare Forecast Prompt`\n\n---\n\n### \ud83d\udd52 `Run Daily Forecast`\n\n**Type:** Cron Trigger\n**Purpose:**\nAutomatically runs the workflow every day to keep forecasts updated with the latest sales data.\n\n\ud83d\udd27 **Configuration:**\n\n* Schedule: Daily at 6 AM UTC (or as needed)\n\n---\n\n### \ud83d\udfe6 `Fetch Stripe Charges`\n\n**Type:** Stripe Node\n**Purpose:**\nRetrieves all successful transactions from Stripe in a defined timeframe.\n\n\ud83d\udce5 **Details:**\n\n* Resource: `Charges`\n* Operation: `Get Many`\n* Filters:\n\n  * `created[gte]` (e.g. last 30 days)\n  * `status: succeeded`\n* Expansion (optional): `data.customer` for customer context\n\n\u2705 **Output:** Raw Stripe sales data with timestamps and amounts\n\n---\n\n### \ud83e\udde9 `Summarize Daily Sales`\n\n**Type:** Code Node\n**Purpose:**\nProcesses Stripe charges and summarizes revenue per day.\n\n\ud83e\udde0 **Logic:**\n\n* Converts Unix timestamps to `YYYY-MM-DD`\n* Aggregates total revenue per day\n* Converts cents to dollars\n\n\ud83d\udce6 **Output Sample:**\n\n```json\n{\n  \"2025-05-01\": 1245.50,\n  \"2025-05-02\": 980.00\n}\n```\n\n---\n\n### \u270f\ufe0f `Prepare Forecast Prompt`\n\n**Type:** Edit Fields / Function\n**Purpose:**\nFormats the summary into a natural language prompt for OpenAI.\n\n\ud83e\udde0 **Example Prompt:**\n\n```txt\nGiven the following sales data:\n{ \"2025-05-01\": 1245.50, ... }\n\nPredict trends and forecast sales for the next 3 months.\n```\n\n\ud83e\uddfe **Output:** `prompt` (String) \u2192 sent to the AI Agent\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f60c6c15-8449-457a-aaad-2ebca8d75318",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        940,
        -1880
      ],
      "parameters": {
        "color": 6,
        "width": 840,
        "height": 2680,
        "content": "## 2\ufe0f\u20e3 **\ud83e\udd16 AI Agent Forecasting**\n\n**Nodes:**\n\n* \ud83e\udd16 `Forecast with OpenAI Agent`\n* \ud83e\udde0 `OpenAI GPT-4 Model`\n* \ud83d\udcc4 `Extract Forecast Output`\n* \ud83c\udf32 `Store Context in Pinecone` *(Optional)*\n* \ud83e\uddec `Generate Embeddings` *(Optional)*\n\n---\n\n### \ud83e\udd16 `Forecast with OpenAI Agent`\n\n**Type:** Tools Agent\n**Purpose:**\nActs as an intelligent agent that reads the sales summary and responds with forecasts and reasoning.\n\n\ud83e\udde0 **Prompt Input:**\nPassed from `Prepare Forecast Prompt`\n\n\ud83d\udcac **Uses:**\n\n* Model: `GPT-4`\n* Output Parser: Structured JSON format\n\n\ud83d\udcc8 **Forecast Intent:**\nPredicts next 3 months, identifies trends, and gives a confidence level\n\n---\n\n### \ud83e\udde0 `OpenAI GPT-4 Model`\n\n**Type:** OpenAI Node\n**Purpose:**\nHandles the natural language generation based on the supplied prompt.\n\n\ud83e\uddfe **Configuration:**\n\n* Model: `gpt-4` or `gpt-4-turbo`\n* Temperature: `0.2` (more deterministic)\n* Max Tokens: `1000`\n\n---\n\n### \ud83d\udcc4 `Extract Forecast Output`\n\n**Type:** Structured Output Parser\n**Purpose:**\nParses the GPT response into usable JSON format.\n\n\ud83d\udce6 **Expected Output:**\n\n```json\n{\n  \"forecast\": {\n    \"June\": \"$15,000.00\",\n    \"July\": \"$16,500.00\",\n    \"August\": \"$17,200.00\"\n  },\n  \"trend\": \"Increasing\",\n  \"confidence\": \"High\",\n  \"insights\": \"Sales show strong momentum...\"\n}\n```\n\n---\n\n### \ud83c\udf32 `Store Context in Pinecone` *(optional)*\n\n**Type:** Vector Store\n**Purpose:**\nIndexes past data for retrieval-based prompting (RAG). Useful for long-term memory.\n\n---\n\n### \ud83e\uddec `Generate Embeddings` *(optional)*\n\n**Type:** Embeddings Node\n**Purpose:**\nConverts text into vector format before inserting into Pinecone."
      },
      "typeVersion": 1
    },
    {
      "id": "8e9b2ea7-58bb-4f62-a69c-eed70032019c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1920,
        -1220
      ],
      "parameters": {
        "color": 5,
        "width": 460,
        "height": 1560,
        "content": "## 3\ufe0f\u20e3 **\ud83d\udce6 Storage & Reporting**\n\n**Nodes:**\n\n* \ud83d\udfe9 `Save Forecast to Supabase`\n* \ud83d\udcca `Log Forecast in Google Sheets`\n\n---\n\n### \ud83d\udfe9 `Save Forecast to Supabase`\n\n**Type:** Supabase Node\n**Purpose:**\nStores all forecast results for analytics, versioning, or historical comparisons.\n\n\ud83d\udee2\ufe0f **Table:** `forecasts`\n\ud83e\uddfe **Columns Example:**\n\n| timestamp  | raw\\_data | forecast\\_data |\n| ---------- | --------- | -------------- |\n| 2025-05-29 | {...}     | {...}          |\n\n---\n\n### \ud83d\udcca `Log Forecast in Google Sheets`\n\n**Type:** Google Sheets Node\n**Purpose:**\nPushes structured data into a visual format for reporting dashboards or human review.\n\n\ud83d\udccb **Column Format:**\n\n| Date       | Forecast (USD) | Trend      | Confidence | Insights                   |\n| ---------- | -------------- | ---------- | ---------- | -------------------------- |\n| 2025-05-29 | \\$15,000.00    | Increasing | High       | Sales rising at 10% weekly |\n\n---\n\n## \u2705 Summary Flow\n\n```txt\n\ud83d\udd01 Sales Data (Stripe) \n \u2192 \ud83e\udde0 Forecast Agent (OpenAI) \n \u2192 \ud83d\udce6 Stored in Supabase \n \u2192 \ud83d\udcca Reported in Google Sheets"
      },
      "typeVersion": 1
    },
    {
      "id": "7d1186c9-cba1-4876-a405-fa67773b8dad",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1840,
        -1800
      ],
      "parameters": {
        "color": 4,
        "width": 1300,
        "height": 320,
        "content": "=======================================\n            WORKFLOW ASSISTANCE\n=======================================\nFor any questions or support, please contact:\n    Yaron@nofluff.online\n\nExplore more tips and tutorials here:\n   - YouTube: https://www.youtube.com/@YaronBeen/videos\n   - LinkedIn: https://www.linkedin.com/in/yaronbeen/\n=======================================\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2b9e9108-8084-4e3f-a620-5bee07040bc3",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1840,
        -1460
      ],
      "parameters": {
        "color": 4,
        "width": 1289,
        "height": 4778,
        "content": "# \ud83d\udcca CFO Forecasting Agent \u2013 Workflow Documentation\n\n---\n\n## 1\ufe0f\u20e3 **\ud83d\udd01 Data Retrieval & Preprocessing**\n\n**Nodes:**\n\n* \ud83d\udd52 `Run Daily Forecast`\n* \ud83d\udfe6 `Fetch Stripe Charges`\n* \ud83e\udde9 `Summarize Daily Sales`\n* \u270f\ufe0f `Prepare Forecast Prompt`\n\n---\n\n### \ud83d\udd52 `Run Daily Forecast`\n\n**Type:** Cron Trigger\n**Purpose:**\nAutomatically runs the workflow every day to keep forecasts updated with the latest sales data.\n\n\ud83d\udd27 **Configuration:**\n\n* Schedule: Daily at 6 AM UTC (or as needed)\n\n---\n\n### \ud83d\udfe6 `Fetch Stripe Charges`\n\n**Type:** Stripe Node\n**Purpose:**\nRetrieves all successful transactions from Stripe in a defined timeframe.\n\n\ud83d\udce5 **Details:**\n\n* Resource: `Charges`\n* Operation: `Get Many`\n* Filters:\n\n  * `created[gte]` (e.g. last 30 days)\n  * `status: succeeded`\n* Expansion (optional): `data.customer` for customer context\n\n\u2705 **Output:** Raw Stripe sales data with timestamps and amounts\n\n---\n\n### \ud83e\udde9 `Summarize Daily Sales`\n\n**Type:** Code Node\n**Purpose:**\nProcesses Stripe charges and summarizes revenue per day.\n\n\ud83e\udde0 **Logic:**\n\n* Converts Unix timestamps to `YYYY-MM-DD`\n* Aggregates total revenue per day\n* Converts cents to dollars\n\n\ud83d\udce6 **Output Sample:**\n\n```json\n{\n  \"2025-05-01\": 1245.50,\n  \"2025-05-02\": 980.00\n}\n```\n\n---\n\n### \u270f\ufe0f `Prepare Forecast Prompt`\n\n**Type:** Edit Fields / Function\n**Purpose:**\nFormats the summary into a natural language prompt for OpenAI.\n\n\ud83e\udde0 **Example Prompt:**\n\n```txt\nGiven the following sales data:\n{ \"2025-05-01\": 1245.50, ... }\n\nPredict trends and forecast sales for the next 3 months.\n```\n\n\ud83e\uddfe **Output:** `prompt` (String) \u2192 sent to the AI Agent\n\n---\n\n## 2\ufe0f\u20e3 **\ud83e\udd16 AI Agent Forecasting**\n\n**Nodes:**\n\n* \ud83e\udd16 `Forecast with OpenAI Agent`\n* \ud83e\udde0 `OpenAI GPT-4 Model`\n* \ud83d\udcc4 `Extract Forecast Output`\n* \ud83c\udf32 `Store Context in Pinecone` *(Optional)*\n* \ud83e\uddec `Generate Embeddings` *(Optional)*\n\n---\n\n### \ud83e\udd16 `Forecast with OpenAI Agent`\n\n**Type:** Tools Agent\n**Purpose:**\nActs as an intelligent agent that reads the sales summary and responds with forecasts and reasoning.\n\n\ud83e\udde0 **Prompt Input:**\nPassed from `Prepare Forecast Prompt`\n\n\ud83d\udcac **Uses:**\n\n* Model: `GPT-4`\n* Output Parser: Structured JSON format\n\n\ud83d\udcc8 **Forecast Intent:**\nPredicts next 3 months, identifies trends, and gives a confidence level\n\n---\n\n### \ud83e\udde0 `OpenAI GPT-4 Model`\n\n**Type:** OpenAI Node\n**Purpose:**\nHandles the natural language generation based on the supplied prompt.\n\n\ud83e\uddfe **Configuration:**\n\n* Model: `gpt-4` or `gpt-4-turbo`\n* Temperature: `0.2` (more deterministic)\n* Max Tokens: `1000`\n\n---\n\n### \ud83d\udcc4 `Extract Forecast Output`\n\n**Type:** Structured Output Parser\n**Purpose:**\nParses the GPT response into usable JSON format.\n\n\ud83d\udce6 **Expected Output:**\n\n```json\n{\n  \"forecast\": {\n    \"June\": \"$15,000.00\",\n    \"July\": \"$16,500.00\",\n    \"August\": \"$17,200.00\"\n  },\n  \"trend\": \"Increasing\",\n  \"confidence\": \"High\",\n  \"insights\": \"Sales show strong momentum...\"\n}\n```\n\n---\n\n### \ud83c\udf32 `Store Context in Pinecone` *(optional)*\n\n**Type:** Vector Store\n**Purpose:**\nIndexes past data for retrieval-based prompting (RAG). Useful for long-term memory.\n\n---\n\n### \ud83e\uddec `Generate Embeddings` *(optional)*\n\n**Type:** Embeddings Node\n**Purpose:**\nConverts text into vector format before inserting into Pinecone.\n\n---\n\n## 3\ufe0f\u20e3 **\ud83d\udce6 Storage & Reporting**\n\n**Nodes:**\n\n* \ud83d\udfe9 `Save Forecast to Supabase`\n* \ud83d\udcca `Log Forecast in Google Sheets`\n\n---\n\n### \ud83d\udfe9 `Save Forecast to Supabase`\n\n**Type:** Supabase Node\n**Purpose:**\nStores all forecast results for analytics, versioning, or historical comparisons.\n\n\ud83d\udee2\ufe0f **Table:** `forecasts`\n\ud83e\uddfe **Columns Example:**\n\n| timestamp  | raw\\_data | forecast\\_data |\n| ---------- | --------- | -------------- |\n| 2025-05-29 | {...}     | {...}          |\n\n---\n\n### \ud83d\udcca `Log Forecast in Google Sheets`\n\n**Type:** Google Sheets Node\n**Purpose:**\nPushes structured data into a visual format for reporting dashboards or human review.\n\n\ud83d\udccb **Column Format:**\n\n| Date       | Forecast (USD) | Trend      | Confidence | Insights                   |\n| ---------- | -------------- | ---------- | ---------- | -------------------------- |\n| 2025-05-29 | \\$15,000.00    | Increasing | High       | Sales rising at 10% weekly |\n\n---\n\n## \u2705 Summary Flow\n\n```txt\n\ud83d\udd01 Sales Data (Stripe) \n \u2192 \ud83e\udde0 Forecast Agent (OpenAI) \n \u2192 \ud83d\udce6 Stored in Supabase \n \u2192 \ud83d\udcca Reported in Google Sheets\n```\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "56196260-ac1a-4ef1-87c1-d5a8e1eb438f",
  "connections": {
    "Prepare data": {
      "main": [
        [
          {
            "node": "Forecaster agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarize Sales": {
      "main": [
        [
          {
            "node": "Prepare data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Forecaster agent": {
      "main": [
        [
          {
            "node": "Save Forecast to Supabase",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Forecast in Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Forecaster agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Run Daily Forecast": {
      "main": [
        [
          {
            "node": "Fetch Stripe Charges",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Stripe Charges": {
      "main": [
        [
          {
            "node": "Summarize Sales",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store": {
      "ai_tool": [
        [
          {
            "node": "Forecaster agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Forecaster agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}