{
  "name": "MAIN 2",
  "nodes": [
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        280,
        400
      ],
      "id": "282e1615-4d1a-4d2f-b46d-10dbc4acab7d",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "name": "emailAgent",
        "description": "Call this tool for any email actions.",
        "workflowId": {
          "__rl": true,
          "value": "HZTRjHtpqwBeGIcW",
          "mode": "list",
          "cachedResultName": "EMAIL 2"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2,
      "position": [
        760,
        520
      ],
      "id": "b7fa5466-a15a-48d5-bbc7-e112fa16f689",
      "name": "Email Agent"
    },
    {
      "parameters": {
        "name": "contactAgent",
        "description": "Use this tool to search the internet.",
        "workflowId": {
          "__rl": true,
          "value": "ALjwaKH3mVbgUcZL",
          "mode": "list",
          "cachedResultName": "CONTACT 2"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2,
      "position": [
        760,
        660
      ],
      "id": "78007de4-a3d6-48fd-8b67-d84e7a2d6dbd",
      "name": "Contact Agent"
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        440,
        400
      ],
      "id": "59b923d4-b423-4ec6-9ee4-62f3964e823b",
      "name": "Window Buffer Memory"
    },
    {
      "parameters": {
        "toolDescription": "Use this tool to search the internet.",
        "method": "POST",
        "url": "https://api.tavily.com/search",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\n    \"api_key\": \"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\",\n    \"query\": \"{searchTerm}\",\n    \"search_depth\": \"basic\",\n    \"include_answer\": true,\n    \"topic\": \"news\",\n    \"include_raw_content\": true,\n    \"max_results\": 3\n} ",
        "placeholderDefinitions": {
          "values": [
            {
              "name": "searchTerm",
              "description": "What the user has requested to search the internet for",
              "type": "string"
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [
        900,
        520
      ],
      "id": "e2cbd554-0882-4376-affc-464d9998cf3b",
      "name": "Tavily"
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "typeVersion": 1,
      "position": [
        620,
        660
      ],
      "id": "f3869cd6-30e9-4d84-9800-98e9f0817ead",
      "name": "Calculator"
    },
    {
      "parameters": {
        "name": "calendarAgent",
        "description": "Call this tool for any calendar action.",
        "workflowId": {
          "__rl": true,
          "value": "nHFLnMz7CdNgUWdk",
          "mode": "list",
          "cachedResultName": "CALENDAR 2"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2,
      "position": [
        620,
        520
      ],
      "id": "164dc97f-4042-40b1-a0eb-8bd51841e642",
      "name": "Calendar Agent"
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "id": "baf0efd2-ef46-4212-84f9-28f6ce3900af",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.1,
      "position": [
        -380,
        180
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fe7ecc99-e1e8-4a5e-bdd6-6fce9757b234",
              "name": "text",
              "value": "={{ $json.message.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "fd30967a-3f47-4541-b6ba-d76bcf701e82",
      "name": "Set 'Text'",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        0,
        180
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.message.voice.file_id }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Voice"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "8c844924-b2ed-48b0-935c-c66a8fd0c778",
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Text"
            }
          ]
        },
        "options": {}
      },
      "id": "6047139e-69df-48f4-99c3-44c5ff8a0fc9",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -180,
        180
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "b37c024a-9e73-47cf-9795-7656910dce56",
      "name": "Response",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1040,
        200
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $json.message.voice.file_id }}"
      },
      "id": "472b91de-bc21-416c-849e-5bc8be66a062",
      "name": "Download File",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "options": {}
      },
      "id": "392c765e-8794-4250-a5f7-0520e7e3abe0",
      "name": "Transcribe",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.6,
      "position": [
        140,
        0
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "=# Overview\nYou are the ultimate personal assistant. Your job is to send the user's query to the correct tool. You should never be writing emails, or creating even summaries, you just need to call the correct tool. \n\n## Tools\n- emailAgent: Use this tool to take action in email\n- calendarAgent: Use this tool to take action in calendar\n- contactAgent: Use this tool to get, update, or add contacts\n- Tavily: Use this tool to search the web\n\n## Rules\n- Some actions require you to look up contact information first. For the following actions, you must get contact information and send that to the agent who needs it:\n  - sending emails\n  - drafting emails\n  - creating calendar event with attendee\n\n## Examples\n1) \n- Input: send an email to tom crocodile asking him what time he wants to leave\n  - Action: Use contactAgent to get tom crocodile's email\n  - Action: Use emailAgent to send the email. You will pass the tool a query like \"send tom crocodile an email to ask what time he wants to leave. here is his email: [email address]\n- Output: The email has been sent to Tom Crocodile. Anything else I can help you with?\n\n\n## Final Reminders\n- Here is the current date/time: {{ $now }}"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        320,
        200
      ],
      "id": "6803a23e-1184-424a-9a92-5e19d2820ad9",
      "name": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422"
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Email Agent": {
      "ai_tool": [
        [
          {
            "node": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Contact Agent": {
      "ai_tool": [
        [
          {
            "node": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Tavily": {
      "ai_tool": [
        [
          {
            "node": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Calendar Agent": {
      "ai_tool": [
        [
          {
            "node": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set 'Text'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set 'Text'": {
      "main": [
        [
          {
            "node": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Transcribe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe": {
      "main": [
        [
          {
            "node": "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u0411\u0418\u0417\u041d\u0415\u0421 \u0410\u0421\u0421\u0418\u0421\u0422\u0415\u041d\u0422": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "35c1364c-1f87-4fd8-acac-46451b3e39e3",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "C6hX4NgkjTkx3vm9",
  "tags": []
}