{
  "name": "🤖Email Agent",
  "nodes": [
    {
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "id": "c98bcc4d-20a9-4b29-a4aa-f6b6e7bb1f1b",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        560,
        680
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "7ab380a2-a8d3-421c-ab4e-748ea8fb7904",
              "name": "response",
              "value": "Unable to perform task. Please try again.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "0505c1f0-53d1-4988-843f-eb9eac2d7856",
      "name": "Try Again",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1640,
        500
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "39c2f302-03be-4464-a17a-d7cc481d6d44",
              "name": "=response",
              "value": "={{$json.output}}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "97393469-bde9-4a13-8d89-68ac6a4305db",
      "name": "Success",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1640,
        320
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.query }}",
        "options": {
          "systemMessage": "=# Overview\nYou are an email management assistant. All emails must be formatted professionally in HTML and signed off as \"Nate.\" \n\n**Email Management Tools**   \n   - Use \"Send Email\" to send emails.  \n   - Use \"Create Draft\" if the user asks for a draft.  \n   - Use \"Get Emails\" to retrieve emails when requested.\n   - Use \"Get Labels\" to retrieve labels.\n   - Use \"Mark Unread\" to mark an email as unread. You must use \"Get Emails\" first so you have the message ID of the email to flag.\n   - Use \"Label Email\" to flag an email. You must use \"Get Emails\" first so you have the message ID of the email to flag. Then you must use \"Get Labels\" so you have the label ID.\n   - Use \"Email Reply\" to reply to an email. You must use \"Get Emails\" first so you have the message ID of the email to reply to.\n\n## Final Notes\n- Here is the current date/time: {{ $now }}"
        }
      },
      "id": "0f7ba4a7-44b1-41ce-8904-9a78e8e03be4",
      "name": "Email Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.6,
      "position": [
        1040,
        400
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "sendTo": "={{ $fromAI(\"emailAddress\") }}",
        "subject": "={{ $fromAI(\"subject\") }}",
        "message": "={{ $fromAI(\"emailBody\") }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        720,
        760
      ],
      "id": "9e043f46-3e1a-431a-9495-b34e251de785",
      "name": "Send Email"
    },
    {
      "parameters": {
        "operation": "getAll",
        "limit": "={{ $fromAI(\"limit\",\"how many emails the user wants\") }}",
        "simple": false,
        "filters": {
          "sender": "={{ $fromAI(\"sender\",\"who the emails are from\") }}"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        1360,
        860
      ],
      "id": "fc850981-86fa-4714-a47a-27d5ed2f4944",
      "name": "Get Emails"
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "={{ $fromAI(\"subject\") }}",
        "emailType": "html",
        "message": "={{ $fromAI(\"emailBody\") }}",
        "options": {
          "sendTo": "={{ $fromAI(\"emailAddress\") }}"
        }
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        1200,
        880
      ],
      "id": "c460b943-04a8-4598-9e70-be4f5d4d2303",
      "name": "Create Draft"
    },
    {
      "parameters": {
        "operation": "reply",
        "messageId": "={{ $fromAI(\"ID\",\"the message ID\") }}",
        "message": "={{ $fromAI(\"emailBody\") }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        880,
        820
      ],
      "id": "500202a6-a9be-45ac-be3d-33e0928fb830",
      "name": "Email Reply"
    },
    {
      "parameters": {
        "resource": "label",
        "returnAll": true
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        1480,
        800
      ],
      "id": "b05ce6a1-ae44-4d46-a32b-c6d2250794b1",
      "name": "Get Labels"
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $fromAI(\"ID\",\"the ID of the message\") }}",
        "labelIds": "={{ $fromAI(\"labelID\") }}"
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        1040,
        860
      ],
      "id": "88c2635f-5088-4f0c-b5f8-c4a5f73ffc79",
      "name": "Label Emails"
    },
    {
      "parameters": {
        "operation": "markAsUnread",
        "messageId": "={{ $fromAI(\"messageID\") }}"
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        1620,
        740
      ],
      "id": "8f3771c3-cf3d-4481-8a6d-4ead60291649",
      "name": "Mark Unread"
    },
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        800,
        400
      ],
      "id": "053be115-2ecf-4d22-8f7f-93ad7271bf80",
      "name": "When Executed by Another Workflow"
    },
    {
      "id": "03ef7196-1655-5d00-a4a7-e558581e4084",
      "name": "Publication · Overview and setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -800,
        0
      ],
      "parameters": {
        "content": "# 🤖Email Agent\n\n## Purpose and structure\nThis folder contains the **🤖Email Agent** workflow. Its executable nodes use `agent`, `executeWorkflowTrigger`, `gmailTool`, `lmChatOpenAi`, `set`. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.\n\n## Setup\nImport inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.\n\n## Entry points\nWhen Executed by Another Workflow\n\n## Verification\nSanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.\n\n## Attribution\nhttps://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Gmailtool/1795_Gmailtool_Executeworkflow_Send_Triggered.json\nMIT; preserve source notices.",
        "width": 700,
        "height": 800,
        "color": 1
      }
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Email Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Email Agent": {
      "main": [
        [
          {
            "node": "Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Try Again",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Email Reply": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Emails": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create Draft": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Labels": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Label Emails": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Mark Unread": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Email Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  }
}
