{
  "id": "ZemG6UGO2KVDib8r",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Personal productivity-Gmail/Calender",
  "tags": [],
  "nodes": [
    {
      "id": "3a5b8268-4355-4a8e-8710-0dff30e21bd8",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -304,
        0
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.4
    },
    {
      "id": "375580f3-89cb-47ff-9c61-75a744b2c6e9",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -16,
        112
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "cc51b3fc-3383-4091-8017-a7cc47692002",
      "name": "Read_Emails",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        0,
        528
      ],
      "parameters": {
        "filters": {},
        "operation": "getAll",
        "descriptionType": "manual",
        "toolDescription": "Fetches unread emails from the founder's Gmail inbox. Use this when asked to summarize emails, check for new messages, or retrieve the context of a specific conversation."
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "94bbb5d3-dcd4-4402-9ecc-5d449001a0f8",
      "name": "Draft_Email",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        112,
        544
      ],
      "parameters": {
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "options": {},
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', ``, 'string') }}",
        "resource": "draft",
        "descriptionType": "manual",
        "toolDescription": "Creates a draft in Gmail but does NOT send it. Use this to prepare an email response for the founder to review later in their Gmail app."
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "c2cdc222-789e-47b2-bf9a-72278b73bdee",
      "name": "Send_Email",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        224,
        528
      ],
      "parameters": {
        "sendTo": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('To', ``, 'string') }}",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "options": {
          "senderName": "Jitesh",
          "appendAttribution": false
        },
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', ``, 'string') }}",
        "emailType": "text",
        "descriptionType": "manual",
        "toolDescription": "Sends an email directly to a recipient. CRITICAL: Only use this tool if you have already shown the exact email content to the founder in the chat AND they have explicitly replied with a confirmation like 'yes', 'send it', or 'approved'."
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e0e6bfd8-2bd3-47a7-ad72-1c892c01c1ee",
      "name": "Check_Calendar",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        496,
        544
      ],
      "parameters": {
        "options": {},
        "timeMax": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Before', ``, 'string') }}",
        "timeMin": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('After', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "user@example.com",
          "cachedResultName": "user@example.com"
        },
        "operation": "getAll",
        "descriptionType": "manual",
        "toolDescription": "Retrieves events from the founder's Google Calendar for a specified date or time range. Use this to check availability before booking any meeting, or to find the details/ID of an existing meeting before canceling it."
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "9db192a2-a7ba-4778-81a6-9f3a22305e29",
      "name": "Book_Meeting",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        624,
        544
      ],
      "parameters": {
        "end": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('End', ``, 'string') }}",
        "start": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "user@example.com",
          "cachedResultName": "user@example.com"
        },
        "descriptionType": "manual",
        "toolDescription": "Creates a new event in Google Calendar. You MUST run the Check_Calendar tool first to ensure the time slot is free before using this tool.",
        "additionalFields": {}
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "0b9a02fa-039c-4061-bbb1-33f4b4508a01",
      "name": "Cancel_Meeting",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        752,
        544
      ],
      "parameters": {
        "eventId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Event_ID', ``, 'string') }}",
        "options": {},
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "user@example.com",
          "cachedResultName": "user@example.com"
        },
        "operation": "delete",
        "descriptionType": "manual",
        "toolDescription": "Deletes an event from Google Calendar. You MUST run the Check_Calendar tool first to locate the exact event and confirm it exists before using this tool."
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "6b36f0d8-edae-4c94-8d19-445d52f40639",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        96,
        160
      ],
      "parameters": {
        "sessionKey": "={{ $json.sessionId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 16
      },
      "typeVersion": 1.3
    },
    {
      "id": "5183cbcb-52f9-4460-afd1-fdadd0233dfd",
      "name": "Inbox_Agent",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        32,
        320
      ],
      "parameters": {
        "text": "=You are the Inbox Specialist Agent. You have access to Gmail tools.\n\nRules:\n1. Use Read_Emails to summarize unread messages.\n2. Use Draft_Email to prepare responses. \n3. CRITICAL: You must return the exact drafted text to the Supervisor so it can be approved. \n4. NEVER use the Send_Email tool unless your instructions explicitly state the Supervisor has acquired user approval.\n\n---\nINSTRUCTIONS FROM SUPERVISOR:\n{{ $fromAI('task', 'The specific email context, recipient, and tone you need to execute', 'string') }}",
        "options": {},
        "toolDescription": "Handles all email operations: reading, drafting, and sending. Call this agent for any inbox tasks."
      },
      "typeVersion": 3
    },
    {
      "id": "5e9403f8-70ff-40a0-b1dd-213f65969f44",
      "name": "Calendar_Agent",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        480,
        304
      ],
      "parameters": {
        "text": "=You are the Calendar Specialist Agent. You have access to Google Calendar tools. \n\nRules:\n1. You MUST run Check_Calendar before executing any booking or cancellation.\n2. If booking, verify the slot is free. If free, use Book_Meeting. If blocked, return the conflict details.\n3. If canceling, verify the event ID first.\n4. Return concise confirmations of all actions back to the Supervisor.\n\n---\nINSTRUCTIONS FROM SUPERVISOR:\n{{ $fromAI('task', 'The specific date, time, and action you need to perform on the calendar', 'string') }}",
        "options": {},
        "toolDescription": "Handles all scheduling operations: checking availability, booking, and canceling events."
      },
      "typeVersion": 3
    },
    {
      "id": "045d94af-0ac9-4b96-b418-16d5cd87b911",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -64,
        416
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "363ad001-5220-4b24-8331-4aa2fa469d65",
      "name": "OpenAI Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        432,
        432
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "557476f2-497a-46a8-ba0c-fd0dc59a14f8",
      "name": "SUPERVISOR",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        208,
        0
      ],
      "parameters": {
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "You are the Executive Supervisor AI. You interface directly with Jitesh. Your sole responsibility is to understand his commands and delegate the work to your specialized agents.\n\nRules:\n\nIf the request involves reading, drafting, or sending emails, pass the exact request to the Inbox_Agent.\n\nIf the request involves checking availability, booking, or canceling meetings, pass the exact request to the Calendar_Agent.\n\nIf a request involves both (e.g., \"Check my calendar and draft an email\"), sequence the tasks: call the Calendar_Agent first to get the time, then pass that information to the Inbox_Agent to draft the email.\n\nNever attempt to answer scheduling or email questions yourself. Always rely on your agents. Present their findings clearly and directly to Jitesh."
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "e9d609c2-7272-4381-87ae-c255f5006ca8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        -256
      ],
      "parameters": {
        "color": "#E0BEBE",
        "width": 368,
        "height": 416,
        "content": "# Chat Entry Point\n\nThis workflow starts when a user sends a message through the n8n Chat interface.\n\nThe chat input becomes the central command for the AI Supervisor Agent.  \nExamples:\n- \"Summarize my unread emails\"\n- \"Book a meeting tomorrow at 4 PM\"\n- \"Draft a reply to John\"\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9cdd8a37-e5de-4de6-b83e-99a2131de7b5",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        -192
      ],
      "parameters": {
        "color": "#CFB5D9",
        "width": 416,
        "height": 336,
        "content": "# Supervisor AI Agent\n\nThe Supervisor Agent:\n- Understands the user's intent\n- Decides which specialist agent should handle the task\n- Coordinates multi-step actions\n- Combines results into a clean final response\n\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d9404c29-452e-4c8b-9149-287dbedefe50",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        288
      ],
      "parameters": {
        "color": "#8CB9D9",
        "width": 480,
        "height": 384,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "19972343-faba-4f83-a512-2ca989bb77c9",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        560
      ],
      "parameters": {
        "color": "#ADC2D1",
        "width": 352,
        "height": 432,
        "content": "# Inbox Specialist Agent\n\nThis AI agent is dedicated to handling all Gmail-related operations.\n\nCapabilities:\n- Read unread emails\n- Summarize inbox activity\n- Draft professional replies\n- Send approved emails\n\nThe agent follows strict safety rules:\n- Never sends emails without explicit user approval\n- Always returns drafted content before sending\n\nThis creates a safe human-in-the-loop email assistant."
      },
      "typeVersion": 1
    },
    {
      "id": "4572dd20-170a-429a-b8ab-73747131645c",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        288
      ],
      "parameters": {
        "color": "#B1DB95",
        "width": 496,
        "height": 384,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "e288df9a-6ced-46fa-8526-1595b91843a4",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        768,
        96
      ],
      "parameters": {
        "color": "#C0DBAD",
        "width": 368,
        "height": 368,
        "content": "# Calendar Specialist Agent\n\nThis AI agent manages all Google Calendar operations.\n\nCapabilities:\n- Check availability\n- Book meetings\n- Cancel events\n- Handle scheduling requests\n\nThe agent always verifies calendar availability before booking or deleting events to avoid scheduling conflicts."
      },
      "typeVersion": 1
    },
    {
      "id": "fe670176-17b4-494c-a0b2-1a7dc2a485b2",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -736,
        256
      ],
      "parameters": {
        "color": "#ECDD93",
        "width": 512,
        "height": 256,
        "content": "#  Workflow Overview\n\nThis AI-powered workflow acts as a personal executive assistant using Gmail and Google Calendar inside n8n.  \nA central Supervisor Agent receives the user's chat request and intelligently delegates tasks to specialized Email or Calendar agents.  \nThe Inbox Agent can read emails, draft replies, and send approved messages, while the Calendar Agent checks availability, books meetings, and cancels events.  \nConversation memory allows the assistant to remember recent context for more natural interactions.  \n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "4ee5c269-ec03-4b01-b241-6665716ed1b9",
  "connections": {
    "Send_Email": {
      "ai_tool": [
        [
          {
            "node": "Inbox_Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Draft_Email": {
      "ai_tool": [
        [
          {
            "node": "Inbox_Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Inbox_Agent": {
      "ai_tool": [
        [
          {
            "node": "SUPERVISOR",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Read_Emails": {
      "ai_tool": [
        [
          {
            "node": "Inbox_Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Book_Meeting": {
      "ai_tool": [
        [
          {
            "node": "Calendar_Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "SUPERVISOR",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Calendar_Agent": {
      "ai_tool": [
        [
          {
            "node": "SUPERVISOR",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Cancel_Meeting": {
      "ai_tool": [
        [
          {
            "node": "Calendar_Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Check_Calendar": {
      "ai_tool": [
        [
          {
            "node": "Calendar_Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "SUPERVISOR",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Inbox_Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Calendar_Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "SUPERVISOR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}