{
  "name": "Email Agent PAT",
  "nodes": [
    {
      "parameters": {},
      "id": "1ad49f67-2503-4b9a-9790-902fbdeafec6",
      "name": "Execute Workflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1,
      "position": [
        -300,
        560
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "38a463f8-23c7-48fd-983d-1de7508f7ec0",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        -200,
        840
      ],
      "credentials": {
        "openAiApi": {
          "id": "VRTmeW2iB7lCT299",
          "name": "OpenAi account 2"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "7ab380a2-a8d3-421c-ab4e-748ea8fb7904",
              "name": "response",
              "value": "Unable to perform task. Please try again.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "003fce32-31c1-48b2-ab2b-1658a6b4fa3d",
      "name": "Try Again",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        460,
        720
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "limit": "={{$fromAI(\"limit\",\"how many emails the user asked for\")}}",
        "simple": false,
        "filters": {
          "sender": "={{$fromAI(\"senderEmail\",\"who the user is asking for emails from\")}}"
        },
        "options": {}
      },
      "id": "f99be6fd-ab4f-4d86-813e-c78c19e354d4",
      "name": "Get Messages",
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        180,
        840
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "PkLmCcoTbwCOkTx7",
          "name": "Gmail account 3"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "39c2f302-03be-4464-a17a-d7cc481d6d44",
              "name": "=response",
              "value": "={{$json.output}}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a2d189f1-53a4-4645-9661-8abdfd1c5658",
      "name": "Success",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        460,
        460
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $fromAI(\"email_address\",\"the recipient's email address (must be a valid email format)\") }}\n",
        "subject": "={{ $fromAI(\"subject\",\"the subject for the email\") }}",
        "emailType": "text",
        "message": "={{ $fromAI(\"email_body\",\"the body message of the email\") }}",
        "options": {
          "appendAttribution": "="
        }
      },
      "id": "c5cad8a5-b569-4b83-a40c-cb239b0f2bf3",
      "name": "Send Email",
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        40,
        840
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "asaRa4ht88j71aoJ",
          "name": "Gmail account 2"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{$json.query}}",
        "options": {
          "systemMessage": "=You are an email manager. You have access to multiple tools to take any action.\n\nSend an email to the recipient's name and email address with the following subject and message:\n\nSubject: Include the subject of the email.\nMessage: Include the body of the email.\n\nIf the number of emails isn't specified, and you are asked about unread emails, return all of the UNREAD emails.\n\nAlways sign emails as \"Damian\" and NEVER use placeholders like \"[Your Name].\"\n"
        }
      },
      "id": "c18c57e7-c16c-4ba2-aa06-f5483ae995f1",
      "name": "Email Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.6,
      "position": [
        -80,
        560
      ],
      "onError": "continueErrorOutput"
    }
  ],
  "pinData": {},
  "connections": {
    "Execute Workflow Trigger": {
      "main": [
        [
          {
            "node": "Email Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Email Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Messages": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Send Email": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Email Agent": {
      "main": [
        [
          {
            "node": "Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Try Again",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/London",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "versionId": "1ba60d2d-fd10-4015-9488-d6874071434a",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "d1853d6d92799d2de46a947c80ac9a5af91665397cc93a1b568769b332366e37"
  },
  "id": "rqpQ9Rb7mqEeubDP",
  "tags": []
}