{
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "=https://dev.api.hybridtrader.ai/v1/webhooks/live-activity/ingest",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "activities",
              "value": "={{ $json.activities }}"
            }
          ]
        },
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1
            }
          }
        }
      },
      "id": "7d714a9b-c241-44d4-a261-a5a86d955733",
      "name": "POST to BFF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -816,
        240
      ]
    },
    {
      "parameters": {
        "jsCode": "// Parse the AI agent's output\nlet output = $input.first().json.output;\n\n// Remove any markdown code blocks if present\noutput = output.replace(/\\n?/g, '').replace(/```\\n?/g, '');\noutput = output.trim();\n\n// Parse the JSON array\nconst activities = JSON.parse(output);\n\n// Return each activity as a separate item (n8n requires json to be an object, not array)\nreturn activities.map(activity => ({ json: activity }));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1264,
        240
      ],
      "id": "7418f0e8-549f-4754-bb83-b64a397871c9",
      "name": "Parse JSON"
    },
    {
      "parameters": {
        "jsCode": "// Collect all activities from all items\nconst activities = $input.all().map(item => item.json);\n\n// Return single item with activities array\nreturn [{\n  json: {\n    activities: activities\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1040,
        240
      ],
      "id": "5537f21b-ee5a-4639-b0d6-09993874d894",
      "name": "Format Payload"
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "options": {
          "maxTokens": 4000,
          "temperature": 0.3
        }
      },
      "id": "d20efba8-7203-45cb-9967-28e13fd5b839",
      "name": "OpenAI Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        -1552,
        464
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Prepare Search Query').item.json.searchQuery }}",
        "options": {
          "systemMessage": "=Current Time: {{ $now.toISO() }}\n\n{{ $json.promptInput }}\n\nYou are a financial markets analyst. Curate a list of no more than 10 market-moving events that were published or posted within the last 12 hours from the input data. Do not use any new posts that were posted more than 12 hours ago\n\nBase events on typical market patterns:\n- Central bank announcements (Fed, ECB, BoE)\n- Economic data releases (inflation, employment, GDP)\n- Commodity movements (Gold, Oil, Silver)\n- Forex majors (EUR/USD, GBP/USD, USD/JPY)\n- Stock indices (S&P 500, NASDAQ, Dow)\n- Cryptocurrency (Bitcoin, Ethereum)\n- Geopolitical events\n\nFor each event:\n- Title: max 60 characters\n- Description: 100-200 characters\n- Type: NEWS, PRICE_ALERT, VOLATILITY_ALERT, EVENT_UPCOMING, or INSIGHT_UPDATE\n- Sentiment: BULLISH, BEARISH, NEUTRAL, or NONE\n- Timestamp: use times close to {{ $now.toISO() }}\n\nReturn ONLY a valid JSON array. No markdown, no code blocks:\n\n[\n  {\n    \"type\": \"NEWS\",\n    \"title\": \"Fed Rate-Cut Odds Surge\",\n    \"description\": \"Markets price in ~90% chance of 25 bps rate cut by the Federal Reserve next week\",\n    \"sentiment\": \"NEUTRAL\",\n    \"timestamp\": \"2025-12-05T14:30:00Z\"\n  }\n]"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        -1616,
        240
      ],
      "id": "f376b69c-e171-43b8-9484-dafc63e8433f",
      "name": "AI Agent"
    }
  ],
  "connections": {
    "POST to BFF": {
      "main": [
        []
      ]
    },
    "Parse JSON": {
      "main": [
        [
          {
            "node": "Format Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Payload": {
      "main": [
        [
          {
            "node": "POST to BFF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Parse JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}