{
  "name": "Sub Workflow Mails",
  "nodes": [
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -700,
        380
      ],
      "id": "8f5b1bb3-8c65-488e-920f-03acce8e1a23",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "mto8GpgTDXNCXksO",
          "name": "YT Test"
        }
      }
    },
    {
      "parameters": {
        "operation": "markAsRead",
        "messageId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message_ID', `Die Message-ID der Email.`, 'string') }}"
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        260,
        480
      ],
      "id": "5b9635a0-a67f-4fc2-99e2-4525296c3cd9",
      "name": "markRead",
      "webhookId": "c0ae7f4e-31be-41cd-a899-883b4f5685f6",
      "credentials": {
        "gmailOAuth2": {
          "id": "BefzfszAZ9biUPaV",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', `Der Betreff der Email.`, 'string') }}",
        "emailType": "html",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', `Die Nachricht der Email.`, 'string') }}",
        "options": {
          "threadId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Thread_ID', `Die Thread ID der Email, auf die du antworten sollst.`, 'string') }}"
        }
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        100,
        480
      ],
      "id": "bc319bd0-12bc-4ded-8e4f-8228ed10909a",
      "name": "saveReplyDraft",
      "webhookId": "0d64fe08-acf1-4900-99f5-0a34c3b86dbf",
      "credentials": {
        "gmailOAuth2": {
          "id": "BefzfszAZ9biUPaV",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "simple": false,
        "filters": {
          "labelIds": [
            "UNREAD",
            "INBOX"
          ],
          "sender": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Sender', `Der Sender der Email.`, 'string') }}"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        -460,
        480
      ],
      "id": "a8f6683d-29ed-496f-aa14-6b5a8d684149",
      "name": "getEmails",
      "webhookId": "312f5bbf-7614-4d1a-befc-7592c0367f92",
      "credentials": {
        "gmailOAuth2": {
          "id": "BefzfszAZ9biUPaV",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "reply",
        "messageId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message_ID', `Die Thread ID der Email, auf die du antworten sollst.`, 'string') }}",
        "emailType": "text",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', `Der Inhalt der Email.`, 'string') }}",
        "options": {
          "appendAttribution": false,
          "senderName": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Sender_Name', ``, 'string') }}"
        }
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        -40,
        480
      ],
      "id": "f54adecc-feab-459f-9c8e-57dd333731b6",
      "name": "sendReply",
      "webhookId": "bc2509c0-b19d-497e-b0ca-e22aa4c362f2",
      "credentials": {
        "gmailOAuth2": {
          "id": "BefzfszAZ9biUPaV",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('To', `Die Email Adresse des Empfängers.`, 'string') }}",
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', `Der Betreff der Email.`, 'string') }}",
        "emailType": "text",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', `Den Inhalt der Email.`, 'string') }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        -320,
        480
      ],
      "id": "571f49ab-1bd7-42d5-be62-34834ac33e82",
      "name": "sendEmail",
      "webhookId": "180e0df0-cd79-4ee1-a3b7-660825b2a686",
      "credentials": {
        "gmailOAuth2": {
          "id": "BefzfszAZ9biUPaV",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', `Der Betreff der Email.`, 'string') }}",
        "emailType": "html",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', `Die Nachricht der Email.`, 'string') }}",
        "options": {
          "sendTo": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('To_Email', `Die Email des Empfängers.`, 'string') }}"
        }
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        -180,
        480
      ],
      "id": "aa8e29e6-98bf-4140-9b9e-f7272ccdaf6c",
      "name": "saveEmailDraft",
      "webhookId": "82eec91a-c9a1-40ed-bfc8-556c153390f7",
      "credentials": {
        "gmailOAuth2": {
          "id": "BefzfszAZ9biUPaV",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "markAsUnread",
        "messageId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message_ID', `Die Message-ID der Email.`, 'string') }}"
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        420,
        480
      ],
      "id": "3bbbde0f-29a3-46ec-91e0-c9b04ae93996",
      "name": "markUnread",
      "webhookId": "438ce016-c775-4f22-943e-619915336683",
      "credentials": {
        "gmailOAuth2": {
          "id": "BefzfszAZ9biUPaV",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message_ID', `Die ID der Nachricht.`, 'string') }}",
        "labelIds": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Label_Names_or_IDs', `Die ID des Labels.`, 'string') }}"
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        720,
        480
      ],
      "id": "cad2d785-9d53-49fb-bbb4-1fe60c5f3934",
      "name": "labelEmails",
      "webhookId": "9af105a2-4f93-4089-8908-ffb714bf1740",
      "credentials": {
        "gmailOAuth2": {
          "id": "BefzfszAZ9biUPaV",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "resource": "label"
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        580,
        480
      ],
      "id": "af8d813e-df4b-4c8d-8a4e-274ff06af6df",
      "name": "getLabels",
      "webhookId": "39cedbc5-7f7a-4900-889d-51d32f38d69b",
      "credentials": {
        "gmailOAuth2": {
          "id": "BefzfszAZ9biUPaV",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -760,
        60
      ],
      "id": "f4d7d47b-1723-4067-b5e6-3cd300b37d5f",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4f360190-a717-4a93-8336-d03ea65975d5",
              "name": "response",
              "value": "={{ $json.output }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -20,
        -100
      ],
      "id": "f4b393a5-6110-4344-b83f-4e9ffdb7c15f",
      "name": "Response"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4f360190-a717-4a93-8336-d03ea65975d5",
              "name": "response",
              "value": "An error occurred. Please try again.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -20,
        60
      ],
      "id": "8145f175-5a77-4f3d-87ec-da8737381f49",
      "name": "Try Again"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.query }}",
        "options": {
          "systemMessage": "=# Role  \nYour task is to manage, read, and write Arnie`s emails. Make sure to use the correct tool based on the request.  \n\n# INFORMATION  \n- date and time: **{{ $now }}**  \n- You format emails professionally, following standard email writing conventions. \n- The name at the end of the email, after the closing, is always **\"Arnie\"**.  \n\n# Examples:  \n*\"Send an email to...\"* → Use the **sendEmail** tool  \n*\"Reply to this email with a draft...\"* → Use the **saveReplyDraft** tool  \n\n# TOOLS  \n\n## getEmails  \nUse this tool to retrieve unread emails.  \n\n## saveEmailDraft  \nUse this tool to create a draft of an email.  \n\n## sendEmail  \nUse this tool to send an email.  \n\n## saveReplyDraft  \nUse this tool to save a draft for an email reply. You must first use **\"getEmails\"** to retrieve the thread ID of the email you need to reply to with a draft.  \n\n## sendReply  \nUse this tool to send an email reply. You must first use **\"getEmails\"** to retrieve the message ID of the email you want to reply to.  \n\n## getLabels  \nUse this tool to retrieve available labels.  \n\n## labelEmails  \nUse this tool to label an email. First, use **\"getEmails\"** to get the message ID of the email you want to label. Then, use **\"getLabels\"** to obtain the label ID.  \n\n## markRead  \nUse this tool to mark an email as read. You must first use **\"getEmails\"** to get the message ID of the email to be marked.  \n\n## markUnread  \nUse this tool to mark an email as unread. You must first use **\"getEmails\"** to get the message ID of the email you want to mark as unread.  \n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        -460,
        80
      ],
      "id": "9d527e56-7c95-443d-886d-49e48ff870b8",
      "name": "Email Agent",
      "onError": "continueErrorOutput"
    }
  ],
  "pinData": {},
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Email Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "markRead": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "saveReplyDraft": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "getEmails": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "sendReply": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "sendEmail": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "saveEmailDraft": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "markUnread": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "labelEmails": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "getLabels": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Email Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Agent": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Try Again",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6bfd9acc-4b11-4af5-a9fe-bfb4b91421c2",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "89d6b5241e3d0c6b62682a09a72213abeeffd34a6110f442c15fc0b560f12919"
  },
  "id": "S6lTQ0uQgIayczlt",
  "tags": [
    {
      "name": "Maybe to Big.",
      "id": "90k6tkk9Q4GqCMXM",
      "createdAt": "2025-03-01T23:16:34.333Z",
      "updatedAt": "2025-03-01T23:16:34.333Z"
    }
  ]
}