{
  "name": "Agente de IA do Zero | IA Rev (Backup)",
  "nodes": [
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "=## Função Principal\nVocê é um assistente de IA especializado em redigir e enviar e-mails via Gmail e Outlook.\n\n## Processo de Interação\n1. Ao iniciar ou quando solicitado a enviar um e-mail, pergunte qual serviço o usuário utilizará (Gmail e Outlook).\n\n2. Solicite as seguintes informações:\n   \n   Para: [e-mail do destinatário]\n   Assunto: [linha de assunto]\n   Conteúdo: [corpo da mensagem]\n   \n\n3. Se o usuário responder linha por linha sem especificar campos, interprete em ordem lógica:\n   - Primeiro input = destinatário\n   - Segundo input = assunto\n   - Terceiro input (e subsequentes) = conteúdo\n\n4. Apresente a prévia do e-mail formatado claramente.\n\n5. Pergunte se o usuário deseja fazer alterações:\n   - Se sim, aplique as mudanças e apresente novamente\n   - Se não, confirme o envio\n\n6. Use a ferramenta correspondente (Gmail ou Outlook) conforme escolha do usuário.\n\n7. Confirme o envio com mensagem simples.\n\n## Tratamento de Exceções\n- Se faltar informação obrigatória, solicite especificamente.\n- Para múltiplos destinatários, oriente sobre separação por vírgula.\n\n## Processo de Pesquisa Web\n1. Ao usar a ferramenta Perplexity para pesquisas:\n   - Sempre inclua a data atual: {{ $now }}\n   - Sempre responda em português do Brasil, mesmo que as fontes utilizadas sejam em inglês.\n\n2. Após a pesquisa:\n   - Compartilhe todos os links de referência fornecidos pela ferramenta Perplexity\n   - Apresente as informações de forma organizada e relevante\n\nData atual para referência: {{ $now }}"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        180,
        20
      ],
      "id": "2a60e0e0-a9e0-4ca5-94e3-fe8eb785d8a5",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        120,
        240
      ],
      "id": "1bc8da26-8a36-4d60-87cb-de850d9a6fe8",
      "name": "Modelo OpenAI",
      "credentials": {
        "openAiApi": {
          "id": "5uEtXrW5XESNC9aI",
          "name": "OpenAI - Sancler Miranda"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Recebe Mensagem').item.json.message.chat.id }}",
        "contextWindowLength": 10
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        260,
        240
      ],
      "id": "b5f5e764-e39e-4265-88ae-71d30ac9a46f",
      "name": "Memória"
    },
    {
      "parameters": {
        "sendTo": "={{ $fromAI('To', ``, 'string') }}",
        "subject": "={{ $fromAI('Subject', ``, 'string') }}",
        "message": "={{ $fromAI('Message', ``, 'string') }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        520,
        520
      ],
      "id": "e2df4767-f0ba-454e-b0ab-4ddbe31ca211",
      "name": "Gmail",
      "webhookId": "1451b510-5c07-4890-a018-40a08b7b4cf8",
      "credentials": {
        "gmailOAuth2": {
          "id": "d207yhaaRNK5qHu7",
          "name": "Gmail - Agentes Cyborgs"
        }
      }
    },
    {
      "parameters": {
        "toRecipients": "={{ $fromAI('To', ``, 'string') }}",
        "subject": "={{ $fromAI('Subject', ``, 'string') }}",
        "bodyContent": "={{ $fromAI('Message', ``, 'string') }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.microsoftOutlookTool",
      "typeVersion": 2,
      "position": [
        620,
        420
      ],
      "id": "5fefd367-8f90-4c46-a6d7-1b1bdd40c9aa",
      "name": "Microsoft Outlook",
      "webhookId": "507b5f6f-1caf-482c-a60d-c82cf7971773",
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "Lj099YNRrsRlAp1k",
          "name": "Microsoft Outlook - Sancler Miranda "
        }
      }
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.1,
      "position": [
        -960,
        0
      ],
      "id": "02fedb35-579a-4f16-8704-f5c1c32e6940",
      "name": "Recebe Mensagem",
      "webhookId": "f4f41ac6-ee00-4df9-a4e5-31de8858c39f",
      "credentials": {
        "telegramApi": {
          "id": "PzOfC7QCmGjx5nPa",
          "name": "Telegram - Cyborgs Agents"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Recebe Mensagem').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        540,
        20
      ],
      "id": "63182c90-566a-478d-bfa0-b9a1958147b8",
      "name": "Envia Mensagem",
      "webhookId": "1f220ae1-4726-48ab-baaa-d291c4413c81",
      "credentials": {
        "telegramApi": {
          "id": "PzOfC7QCmGjx5nPa",
          "name": "Telegram - Cyborgs Agents"
        }
      }
    },
    {
      "parameters": {
        "toolDescription": "Use essa tool Sonar do Perplexity para fazer pesquisas na internet. Sempre forneça ao usuário, os links de fontes fornecidos pela tool Sonar do Perplexity.",
        "method": "POST",
        "url": "https://api.perplexity.ai/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {
              "name": "Content-Type",
              "valueProvider": "fieldValue",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"sonar\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"Para sua referência, essa é a data de hoje {{ $now }}. Quando o usuário disser \\\"hoje\\\", basei-se nesta data. Sempre forneça o link das fontes em suas respostas.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"{{ $('Recebe Mensagem').item.json.message.text }}.\"\n    }\n  ],\n  \"max_tokens\": 800,\n  \"temperature\": 0.2,\n  \"stream\": false\n}\n"
      },
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [
        720,
        280
      ],
      "id": "08415a23-9b88-494b-a72d-91acb757a499",
      "name": "Perplexity",
      "credentials": {
        "httpHeaderAuth": {
          "id": "L1Uxf9QdbBBJhe8O",
          "name": "API Sonar Perplexity"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "a47df76a-3bd1-4a5b-8d2b-d45b2947d3fd",
                    "leftValue": "={{ $json.message.voice.file_id }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Áudio"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "id": "51600a81-20ae-42a7-97cf-ad6d2f65a933"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Texto"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -740,
        0
      ],
      "id": "bcf1f758-e654-46bf-b692-3490781ddee5",
      "name": "Áudio ou Texto"
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $json.message.voice.file_id }}"
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -520,
        -100
      ],
      "id": "47523d29-7159-4f51-bca2-a872456c9979",
      "name": "Baixar Áudio",
      "webhookId": "a60df967-4751-4ee8-9de7-e70375b33929",
      "credentials": {
        "telegramApi": {
          "id": "PzOfC7QCmGjx5nPa",
          "name": "Telegram - Cyborgs Agents"
        }
      }
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        -300,
        -100
      ],
      "id": "021cd521-10c7-44ca-b157-212419d9cb48",
      "name": "OpenAI",
      "credentials": {
        "openAiApi": {
          "id": "5uEtXrW5XESNC9aI",
          "name": "OpenAI - Sancler Miranda"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        -80,
        20
      ],
      "id": "4dac83ef-9128-49fd-b011-f3db01958997",
      "name": "Unir Mensagens"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "dd5832c4-93fb-428c-acde-85196eb059b3",
              "name": "text",
              "value": "={{ $json.message.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -420,
        140
      ],
      "id": "41090675-81f8-4fce-b857-405dec70ae1c",
      "name": "Texto"
    }
  ],
  "pinData": {},
  "connections": {
    "Modelo OpenAI": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Memória": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Envia Mensagem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Microsoft Outlook": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Recebe Mensagem": {
      "main": [
        [
          {
            "node": "Áudio ou Texto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Perplexity": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Áudio ou Texto": {
      "main": [
        [
          {
            "node": "Baixar Áudio",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Texto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Baixar Áudio": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "Unir Mensagens",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Texto": {
      "main": [
        [
          {
            "node": "Unir Mensagens",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Unir Mensagens": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "3e29e3fc-f8b0-42a6-b154-8037715e13ae",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "c384906a27df3f5421a5aa958710d4b2d448e96f4cf38ed9743f0326d7e50765"
  },
  "id": "386uYpmRvkfVNSN9",
  "tags": []
}