{
  "name": "MultiAgentes",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -288,
        -80
      ],
      "id": "c1101b0d-56c5-49c2-92c5-6c77ff11cdc0",
      "name": "Telegram Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "c7696f5f-6421-433e-8afa-d735308fbaea",
              "leftValue": "={{ $json.message.text }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        -64,
        -80
      ],
      "id": "21baee33-1781-445c-bcaa-a8fa10592a28",
      "name": "If"
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $json.message.voice.file_id }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        304,
        304
      ],
      "id": "63f6e4ba-4e78-4ca3-ba64-abee055c4304",
      "name": "Get a file",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=# Identidade\nVoc\u00ea \u00e9 a Sofia, Gerente de Atendimento da Hashtag Capital, um escrit\u00f3rio de assessoria de investimentos de alta performance.\n\nSua fun\u00e7\u00e3o \u00e9 EXCLUSIVAMENTE:\n1. Classificar a inten\u00e7\u00e3o do cliente com base na mensagem.\n2. Acionar a ferramenta (especialista) correspondente.\n3. Atuar como um espelho: A ferramenta vai gerar uma resposta. O seu trabalho \u00e9 pegar essa resposta e entreg\u00e1-la ao usu\u00e1rio exatamente como ela veio, sem tirar nem por.\n\n# Regra de Ouro (CR\u00cdTICO - Roteador Invis\u00edvel)\n- NUNCA responda com frases pr\u00f3prias como \"Vou verificar com o setor...\" ou \"Aguarde um momento\".\n- NUNCA narre o que voc\u00ea est\u00e1 fazendo.\n- NUNCA tente resolver o problema sozinho (exceto em sauda\u00e7\u00f5es simples).\n\nO cliente deve sentir que foi atendido imediatamente pelo especialista da \u00e1rea.\n\n# Seus Especialistas (Tools)\n1. AgenteFinanceiro:\n   - Assuntos: Financeiro, 2\u00aa via de boleto, pagamentos pendentes.\n   - A\u00e7\u00e3o: Use para quest\u00f5es operacionais e burocr\u00e1ticas (pagamentos).\n\n2. AgenteSuporte:\n   - Assuntos: D\u00favidas T\u00c9CNICAS e TE\u00d3RICAS de mercado financeiro. \"O que \u00e9 Selic?\", \"Como funciona FII?\", \"Diferen\u00e7a de CDB e LCI\", etc\n   - A\u00e7\u00e3o: Use para educa\u00e7\u00e3o financeira, tirar d\u00favidas de conceitos.\n\n3. AgenteCS:\n   - Assuntos: RELACIONAMENTO e AGENDAMENTO. \"Quero investir\", \"Marcar reuni\u00e3o\", \"Revisar carteira\", \"Falar com assessor\", \"Perfil de investidor\".\n   - A\u00e7\u00e3o: Use quando o cliente demonstra inten\u00e7\u00e3o de agir, investir ou quer contato humano.\n\n# Procedimento de Resposta\n1. Sauda\u00e7\u00e3o (Apenas \"Oi/Ol\u00e1\"): Se o usu\u00e1rio disser APENAS uma sauda\u00e7\u00e3o, responda: \"Ol\u00e1! Sou a Sofia, Gerente de Atendimento da Hashtag Capital. Posso te direcionar pra Assuntos Financeiros, D\u00favidas de Mercado (Suporte) ou Agendamento com Assessor. Como posso te ajudar hoje?\"\n\n2. Solicita\u00e7\u00e3o Espec\u00edfica: Se o usu\u00e1rio j\u00e1 enviou a d\u00favida, acione a ferramenta correspondente imediatamente.\n   - IMPORTANTE: O seu output final deve ser estritamente o texto retornado pela ferramenta.\n\n3. D\u00favida: Se n\u00e3o souber classificar, chame o `AgenteCS`.\n\n# TRATAMENTO DE ERRO (IMPORTANTE) Se a ferramenta (sub-agente) retornar a mensagem exata `##RESET##`, isso significa que ela n\u00e3o conseguiu resolver o pedido. NESSE CASO, N\u00c3O ENVIE `##RESET##` PARA O USU\u00c1RIO. Em vez disso, assuma o controle e responda: \"Desculpe, poderia explicar melhor sua d\u00favida?\"\n",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        1392,
        -96
      ],
      "id": "ebd4ec81-bbec-4922-b6b9-7a4034d77e14",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        592,
        304
      ],
      "id": "fd21a372-d8fb-4156-a9f2-cc5962b25ef7",
      "name": "Transcribe a recording",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "VOZ",
        "height": 320,
        "width": 816,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        192
      ],
      "typeVersion": 1,
      "id": "0aa5ca54-7ef4-45b8-a497-bbdc5e481e13",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "TEXTO\n",
        "height": 176,
        "width": 816
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        -112
      ],
      "typeVersion": 1,
      "id": "1382dd27-cf71-42d3-8be5-9adb20bdb3db",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1856,
        -96
      ],
      "id": "56bbe094-3765-422a-b4c1-4db311391b90",
      "name": "Send a text message",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "73164afa-813c-433b-9e0b-cb8bb2162b23",
              "name": "mensagem",
              "value": "={{ $json.content.parts[0].text }}{{ $json.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        880,
        304
      ],
      "id": "bdfe80ce-1526-44aa-961d-6255c25aba95",
      "name": "VOZ"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9c051b1b-d2fd-494c-82fe-b36937cfced2",
              "name": "mensagem",
              "value": "={{ $json.message.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        416,
        -96
      ],
      "id": "7b62c379-73b1-4ddf-bdb4-7e31d194db35",
      "name": "TEXTO"
    },
    {
      "parameters": {
        "description": "Especialista T\u00e9cnico e Tutor. Use para d\u00favidas t\u00e9cnicas",
        "workflowId": {
          "__rl": true,
          "value": "rEtAJbyUgzRJUdg5",
          "mode": "list",
          "cachedResultUrl": "/workflow/rEtAJbyUgzRJUdg5",
          "cachedResultName": "Suporte"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "Mensagem": "={{ $json.mensagem }}",
            "chatID": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Mensagem",
              "displayName": "Mensagem",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "chatID",
              "displayName": "chatID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        1552,
        -368
      ],
      "id": "b0fbdf76-f8bb-4114-a3e5-91192853931f",
      "name": "suporte"
    },
    {
      "parameters": {
        "description": "Especialista em Financeiro. Use para boletos, 2a via, regulariza\u00e7\u00e3o de pagamento",
        "workflowId": {
          "__rl": true,
          "value": "ldae735ArP01bg9v",
          "mode": "list",
          "cachedResultUrl": "/workflow/ldae735ArP01bg9v",
          "cachedResultName": "Financeiro"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "Mensagem": "={{ $json.mensagem }}",
            "chatID": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Mensagem",
              "displayName": "Mensagem",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "chatID",
              "displayName": "chatID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        1392,
        -368
      ],
      "id": "0f8522f9-127b-43e4-bd6a-328b3edecabb",
      "name": "Financeiro"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        1264,
        112
      ],
      "id": "b6accd9f-c25d-4359-81dd-83a78590ba1d",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "contextWindowLength": 30
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        1408,
        112
      ],
      "id": "cf66d16a-b0cc-405a-a8cf-146445633b61",
      "name": "Simple Memory"
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "TEXTO",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a file": {
      "main": [
        [
          {
            "node": "Transcribe a recording",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe a recording": {
      "main": [
        [
          {
            "node": "VOZ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "VOZ": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TEXTO": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "suporte": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Financeiro": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f7723d28-be3f-4173-a768-e303477bdcb1",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "hfZ9zs3f2YnnG2oA",
  "tags": []
}