{
  "name": "Tavily search agent",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.5,
      "position": [
        0,
        0
      ],
      "id": "d165283d-fb0c-4651-a6f3-03fd3357a9b7",
      "name": "Telegram Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "You are a Smart Research Agent equipped with the Tavily search tool. Your main responsibility is to search the web using Tavily whenever accurate, factual, or up-to-date information is needed.\n\n### SYSTEM INSTRUCTIONS & BEHAVIOR RULES:\n\n1. TOOL USAGE (Tavily):\n   - You MUST use the Tavily tool whenever the user asks a question that requires searching the web, looking up facts, fetching current news, or researching any topic.\n   - Do NOT try to answer from your internal knowledge if the prompt requires factual accuracy or recent information; always call Tavily first.\n\n2. CASUAL CONVERSATION:\n   - For simple greetings, standard pleasantries, or basic social chat that does NOT require research, respond directly without calling Tavily.\n\n3. OUT OF SCOPE / NO INFORMATION:\n   - If the user asks for personal advice, medical/legal opinions, illegal tasks, or if the Tavily search yields no useful results, respond politely indicating that you don't have this information or that it falls outside your role.\n\n4. LANGUAGE & TONE:\n   - You MUST respond strictly in Egyptian Colloquial Arabic (\u0627\u0644\u0639\u0627\u0645\u064a\u0629 \u0627\u0644\u0645\u0635\u0631\u064a\u0629).\n   - Maintain a friendly, polite, helpful, and professional tone at all times.\n\n5. OUTPUT FORMATTING & NO SOURCES:\n   - Do NOT mention sources, links, or where the information came from at the end of sentences or responses.\n   - Present the information clearly, concisely, and neatly.\n   - Use double line breaks (a blank line) between every sentence/point to ensure the output is well-spaced and easy to read."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        288,
        0
      ],
      "id": "05306f65-e8e1-404c-88c8-c6b310e88cc5",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        144,
        240
      ],
      "id": "320fdca1-c6c7-4e6f-945a-75ab54780f18",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.message.chat.id }}",
        "contextWindowLength": 10
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        368,
        240
      ],
      "id": "fe172bb5-1874-4d5b-8271-f25f87e3b116",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "chatId": "1780804448",
        "text": "={{ $json.output }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        688,
        0
      ],
      "id": "c835fa6d-9b4f-4488-aef9-35318f43c33b",
      "name": "Send a text message",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "query": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Query', ``, 'string') }}",
        "options": {}
      },
      "type": "@tavily/n8n-nodes-tavily.tavilyTool",
      "typeVersion": 1,
      "position": [
        608,
        256
      ],
      "id": "94aa601c-bd45-4c7d-8efb-c04c320dac91",
      "name": "Search in Tavily",
      "credentials": {
        "tavilyApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search in Tavily": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "0e1a3da9-c30f-4f05-b82e-6ad5469f3aa7",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodeGroups": [],
  "id": "BvegKi8mySdSKNCW",
  "tags": []
}