{
  "id": "1MSUwpnR1sroIquE",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Stock Sentiment Analysis",
  "tags": [],
  "nodes": [
    {
      "id": "3a8dc8ac-01fb-4619-9193-238b44502f6f",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        100,
        -40
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "524ce176-1dfd-49ab-9141-ef5f23ac4823",
      "name": "get_current_date",
      "type": "n8n-nodes-base.dateTimeTool",
      "position": [
        720,
        220
      ],
      "parameters": {
        "options": {},
        "descriptionType": "manual",
        "toolDescription": "use this tool to find out the current date and time."
      },
      "typeVersion": 2
    },
    {
      "id": "b34db507-28b6-4336-8d49-19c5d9677596",
      "name": "web_search",
      "type": "@n8n/n8n-nodes-langchain.toolSearXng",
      "position": [
        540,
        220
      ],
      "parameters": {
        "options": {
          "language": "en"
        }
      },
      "credentials": {
        "searXngApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7dcc25ea-62dc-4e9b-a3ca-3261c3bb2e82",
      "name": "Research Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        360,
        -40
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are a financial research assistant. Your task is to find and summarize the latest news for a given company name or stock ticker.\n\nInstructions:\n\nFirst, use the get_current_date tool to determine the date range for the last 7 days.\nPerform two separate web searches using the web_search tool: one with the company's full name and one with its stock ticker. Use the date range in your search queries to filter for news from the last week only.\n\nAfter reviewing the search results, provide a summary of each news article. The summary should cover the key events, announcements, and market sentiment discussed in the articles.\n"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "955e2558-50e8-4619-87fd-f63c2a6d4171",
      "name": "Sentiment Analysis Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        760,
        -40
      ],
      "parameters": {
        "text": "=User asked about: {{ $('When chat message received').item.json.chatInput }}\n\nLatest news:\n {{ $json.output }}\n",
        "options": {
          "systemMessage": "You are a Financial Sentiment Analyst. You will be provided with a news summary. Your task is to analyze this summary and categorize its sentiment from an investor's perspective.\n\nInstructions:\n1. Read all the news.\n2. Determine the overall sentiment (Positive, Negative, or Neutral) based on the potential impact on the company's financial performance, stock price, or market reputation.\n3. Write a justification that references specific points from the news summaries.\n\nOutput Format:\nSentiment: {sentiment_category}\nJustification: {Your detailed justification}"
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "1f875bfc-5a26-4a40-974f-56991ce695f4",
      "name": "Gemini 2.5 Flash",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        340,
        220
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4cb25891-5df9-4949-b46c-116b17918148",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        -160
      ],
      "parameters": {
        "width": 380,
        "height": 520,
        "content": "## **Set up steps**\n\n1.  **Select the Language Model (LLM):** This workflow is pre-configured with Google Gemini. You can select a different model for the agents as needed.\n2.  **Configure LLM Credentials:** Ensure that valid credentials for your chosen LLM are correctly set up within your n8n instance.\n3.  **Set Up the SearXNG Connection:** Configure the node to connect to your self-hosted SearXNG instance. This enables the agent's web search capabilities.\n4.  **Define the Research Agent's Task:** Customize the system prompt for the \"Research Agent\" to define its role, instructions, and how it should conduct its research.\n5.  **Define the Sentiment Analysis Agent's Task:** Adjust the system prompt for the \"Sentiment Analysis Agent\" to specify how it should analyze the information provided by the Research Agent.\n6.  **Test the Workflow:** Use the built-in chat interface in the n8n canvas to send a message and verify that the agents are functioning correctly."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "51d9d96d-7aa1-4202-875c-05b52ca675a5",
  "connections": {
    "web_search": {
      "ai_tool": [
        [
          {
            "node": "Research Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Research Agent": {
      "main": [
        [
          {
            "node": "Sentiment Analysis Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini 2.5 Flash": {
      "ai_languageModel": [
        [
          {
            "node": "Sentiment Analysis Agent",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Research Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "get_current_date": {
      "ai_tool": [
        [
          {
            "node": "Research Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Research Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}