{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ec0ab7b1-7f50-45d0-aeb8-147f525aa40c",
      "name": "Think",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        1264,
        464
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "631a10cf-d3d5-4f0d-9831-3b3775c76e38",
      "name": "Supabase Vector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        992,
        464
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 5,
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "danelfin",
          "cachedResultName": "danelfin"
        },
        "useReranker": true,
        "toolDescription": "Work with data in supabase to understand danelfin scoring and strategy",
        "includeDocumentMetadata": false
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "0295201f-5b30-4bb4-bacd-f5ed57a76ab2",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        960,
        624
      ],
      "parameters": {
        "options": {
          "dimensions": 1536
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "21b0a10e-69cf-4ba7-b1b8-7581900f242e",
      "name": "Reranker Cohere",
      "type": "@n8n/n8n-nodes-langchain.rerankerCohere",
      "position": [
        1120,
        640
      ],
      "parameters": {
        "modelName": "rerank-english-v3.0"
      },
      "credentials": {
        "cohereApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "879e5393-01ac-4f28-bb89-d57164a49d2e",
      "name": "Danelfin request",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        624,
        144
      ],
      "parameters": {
        "text": "=Manage it with the strategy Agent",
        "options": {
          "systemMessage": "=# You are an expert of making request to an api that retrieves you financial data, YOU ARE NOT A CHATBOT, YOUR ANSWERS HAVE ALWAYS TO BE CONCLUSIVE\n\n\n# Danelfin REST API Reference\n\n## Authentication\n- Header: `x-api-key: {API_KEY}`\n- Base URL: `https://apirest.danelfin.com`\n\n## Endpoints\n- `/ranking` - GET ticker scores/rankings\n- `/sectors` - GET sector list\n- `/sectors/{slug}` - GET sector history\n- `/industries` - GET industry list  \n- `/industries/{slug}` - GET industry history\n\n## /ranking Parameters\n**Required:** At least one of `ticker` OR `date`\n\n- `date` - YYYY-MM-DD format\n- `ticker` - Symbol (e.g. AAPL)\n- `market` - Exchange filter (NYSE, NASDAQ)\n- `aiscore`, `fundamental`, `technical`, `sentiment`, `low_risk` - Exact score 1-10\n- `*_min` versions - Minimum thresholds 1-10\n- `buy_track_record`, `sell_track_record` - 1/0 boolean\n- `sector` - Sector slug\n- `industry` - Industry slug\n- `asset` - stock/etf\n- `fields` - Comma-separated field list\n\n## Response Formats\n- With ticker: `{date: {scores}}`\n- Without ticker: `{date: {ticker: {scores}}}`\n- Score filter: `{ticker: {scores}}`\n\n## Score Fields\n- `aiscore` - AI Score 1-10\n- `technical` - Technical Score 1-10\n- `fundamental` - Fundamental Score 1-10\n- `sentiment` - Sentiment Score 1-10\n- `low_risk` - Low-Risk Score 1-10\n- `buy_track_record` - Boolean\n- `sell_track_record` - Boolean\n\n## Processing Rules\n1. Parse user intent \u2192 extract date, ticker, filters\n2. Validate ticker OR date present (default to today if neither)\n3. Build query string\n4. Send GET request with API key header\n5. Handle errors: 400 = bad params, 403 = auth fail\n6. Convert string scores to integers\n7. Sort by aiscore descending unless specified\n8. Return formatted results\n\n## Query Examples\n- Ticker history: `?ticker=AAPL`\n- Top 100 today: `?date={{ new Date().toISOString().split('T')[0] }}`\n- Score filter: `?date={{ new Date().toISOString().split('T')[0] }}&aiscore=10`\n- Sector filter: `?date={{ new Date().toISOString().split('T')[0] }}&sector=utilities&low_risk_min=5`\n\n## Error Codes\n- 200: Success\n- 400: Bad request - fix params\n- 403: Auth failed - abort\n\n## The http tool gives you acces to all 3 different endpoints\n\n## You must call the supabase RAG tool that gives you knowledge of Danelfin technology and strategy\n\n## Your current timestamp is {{ $now }}, by default always make queries from yesterday or the previous days where the market was opened. \n\n## If you have an error by consulting a stock scores, d'ont consult the one from the previous year, consult the one from the past day\n\n# Output: You always have to make a full deep report on the user query\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "5111ce59-f32a-47d8-a16d-eff54cdc0d4a",
      "name": "ranking",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        336,
        464
      ],
      "parameters": {
        "url": "https://apirest.danelfin.com/ranking",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Name', ``, 'string') }}",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Name', ``, 'string') }}",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', ``, 'string') }}"
            },
            {
              "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters2_Name', ``, 'string') }}",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters2_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "ranking endpoint"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "2b8207dd-aa9c-4032-a4d0-fc98bfa59370",
      "name": "sectors",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        448,
        464
      ],
      "parameters": {
        "url": "https://apirest.danelfin.com/sectors",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Name', ``, 'string') }}",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Name', ``, 'string') }}",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', ``, 'string') }}"
            },
            {
              "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters2_Name', ``, 'string') }}",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters2_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "sectors endpoint"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "baf0f5de-3629-4f26-8a2e-3195f4928c78",
      "name": "industries",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        544,
        464
      ],
      "parameters": {
        "url": "https://apirest.danelfin.com/industries",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Name', ``, 'string') }}",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Name', ``, 'string') }}",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "industries endpoint"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "b3ff8d0f-1298-4dd9-ac16-e1221a43bd17",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -48
      ],
      "parameters": {
        "color": 4,
        "width": 1352,
        "height": 792,
        "content": "# Main Agent /danelfin scoring"
      },
      "typeVersion": 1
    },
    {
      "id": "a15112eb-32ba-4d73-a2ee-8f1d388052d8",
      "name": "Send report",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1200,
        144
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "={{ $json.data }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "Report"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "21e95e0c-2774-481b-a546-8313d841c848",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        48,
        144
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "99a81cec-74ff-4962-ab52-9f22b9d89713",
      "name": "Postgres Chat Memory1",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        192,
        416
      ],
      "parameters": {},
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "875650d8-6399-46d2-b1e3-a63ee762ad2b",
      "name": "Set a reasoning model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        80,
        416
      ],
      "parameters": {
        "model": "x-ai/grok-4",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9ef4549b-449c-41bd-8a3d-b79fe4b8cbd0",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        80
      ],
      "parameters": {
        "color": 5,
        "width": 288,
        "height": 208,
        "content": "### Ask about any stock, industries, sectors, potential trade, etc"
      },
      "typeVersion": 1
    },
    {
      "id": "b492be0c-f316-4c1f-af73-2cde40a7efcb",
      "name": "Markdown to HTML",
      "type": "n8n-nodes-base.markdown",
      "position": [
        1008,
        144
      ],
      "parameters": {
        "mode": "markdownToHtml",
        "options": {},
        "markdown": "={{ $json.output }}"
      },
      "typeVersion": 1
    },
    {
      "id": "862c2311-fd44-43cd-b288-460a3595ee8b",
      "name": "Supabase Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        496,
        896
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "danelfin",
          "cachedResultName": "danelfin"
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "0d2987bc-01ec-4c6a-b263-48f4f495323a",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        640,
        1120
      ],
      "parameters": {
        "options": {
          "metadata": {
            "metadataValues": [
              {}
            ]
          }
        },
        "dataType": "binary",
        "textSplittingMode": "custom"
      },
      "typeVersion": 1.1
    },
    {
      "id": "f70e3c0a-e4e6-4c44-a24e-49e0f4fcd854",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        688,
        1280
      ],
      "parameters": {
        "options": {
          "splitCode": "markdown"
        },
        "chunkSize": 700
      },
      "typeVersion": 1
    },
    {
      "id": "e3689a2b-5c64-473c-869a-45dae5997cb6",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        368,
        1136
      ],
      "parameters": {
        "options": {
          "dimensions": 1536
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "56b19f7f-8451-4c39-9349-737ce968bd4c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        800
      ],
      "parameters": {
        "color": 7,
        "width": 1136,
        "height": 660,
        "content": "## Load sata to vector database"
      },
      "typeVersion": 1
    },
    {
      "id": "514b7f03-e91c-49a3-bc46-da2f4ab75a73",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        896
      ],
      "parameters": {
        "width": 416,
        "height": 272,
        "content": "## Load a pdf with the following information\n\nhttps://docs.google.com/document/d/1wxnTMb4ZwBq1X25QXkvh49WhWz3-DYT2IdbEa8K6opw/edit?usp=sharing\n\nhttps://docs.google.com/document/d/1U6pkrK6sIXuQ9plLHum6puTVVEv-p6ZvP0NGqKlSS5s/edit?usp=sharing"
      },
      "typeVersion": 1
    },
    {
      "id": "8bca3f8f-0309-446b-9e84-41855e0075f9",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        -48
      ],
      "parameters": {
        "color": 6,
        "width": 640,
        "height": 2240,
        "content": "# Workflow Description and Setup Guide\n\nThis workflow provides comprehensive AI-driven stock analysis, generating detailed deep reports by leveraging advanced vector-based data retrieval and API integrations for precise financial analytics using Danelfin scoring and strategy.\n\n---\n\n## Overview\n\nThis workflow automates stock analysis utilizing:\n\n* **AI-driven scoring and sector insights** (Danelfin configuration)\n* **Vector-based data retrieval** (Supabase)\n* **Deep analytical reports**\n\n---\n\n## Key Components and API Integrations\n\n### 1. Danelfin AI Stock Analysis API\n\nProvides advanced stock scores, rankings, and sector insights.\n\n* **Endpoints:**\n\n  * `/ranking`: Stock rankings and scores\n  * `/sectors`: Sector information\n  * `/industries`: Industry details\n\n### 2. Supabase Vector Store\n\nVector embedding storage and quick data retrieval.\n\n---\n\n## Workflow Steps\n\n### Initialization\n\n1. **Chat Trigger**: Activates when a message requesting stock analysis is received.\n\n### Stock Analysis and Deep Reporting\n\n2. **Main AI Agent**: Processes the query, retrieves relevant data from Danelfin, and generates deep analytical reports.\n\n3. **Supabase Vector Store**: Facilitates efficient data retrieval using embeddings.\n\n### Reporting\n\n4. **Markdown Conversion**: Transforms analysis into a readable HTML format.\n\n5. **Email Reporting**: Sends detailed reports via Gmail.\n\n---\n\n## Setup Instructions\n\n### Prerequisites\n\n* Obtain API Keys for Supabase and Danelfin.\n\n### Configuration Steps\n\n1. **Set API Keys**:\n\n   * Supabase API credentials for vector storage.\n   * Danelfin API credentials for stock analysis.\n\n2. **Gmail API Credentials**:\n\n   * Configure Gmail node for sending reports.\n\n### Running the Workflow\n\n* Triggered automatically by chat messages requesting analysis.\n* Reports sent directly via email.\n\n---\n\nThis setup ensures precise, AI-driven stock analysis delivered clearly through automated deep reporting.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "5cd42ade-bb36-49d9-b2c1-29cf96b581d8",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1456,
        16
      ],
      "parameters": {
        "color": 3,
        "width": 576,
        "height": 560,
        "content": "## Need a tailor-made workflow? Tell me about your business and get a free proposal:\n\n**[Start here \u2192 Custom Automation Form](https://taskmorphr.com/contact)**\n\n---\n## \ud83d\udcc8 Cost-Savings Snapshot  \nCurious what automation could save you?  \nRun the 60-second calculator:\n\n**[ROI / Cost Comparison](https://taskmorphr.com/cost-comparison)**\n\n---\n### \u2709\ufe0f Reach me directly  \n`paul@taskmorphr.com`"
      },
      "typeVersion": 1
    },
    {
      "id": "2405dbd4-f266-466f-aab3-8bff9f72871f",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1712,
        416
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 128,
        "content": "### \ud83d\udee0\ufe0f Build it yourself  \nBrowse every ready-made workflow:  \n[Full Template Pack \u2014 coming soon](https://n8n.io/creators/diagopl/)\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Think": {
      "ai_tool": [
        [
          {
            "node": "Danelfin request",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "ranking": {
      "ai_tool": [
        [
          {
            "node": "Danelfin request",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "sectors": {
      "ai_tool": [
        [
          {
            "node": "Danelfin request",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "industries": {
      "ai_tool": [
        [
          {
            "node": "Danelfin request",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Reranker Cohere": {
      "ai_reranker": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_reranker",
            "index": 0
          }
        ]
      ]
    },
    "Danelfin request": {
      "main": [
        [
          {
            "node": "Markdown to HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Markdown to HTML": {
      "main": [
        [
          {
            "node": "Send report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory1": {
      "ai_memory": [
        [
          {
            "node": "Danelfin request",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Set a reasoning model": {
      "ai_languageModel": [
        [
          {
            "node": "Danelfin request",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store1": {
      "ai_tool": [
        [
          {
            "node": "Danelfin request",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Danelfin request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}