{
  "id": "DXwxxzb6moG4hO8x",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Calendar workflow TEMPLATE",
  "tags": [],
  "nodes": [
    {
      "id": "e0fabc85-febd-41bc-b87f-b5ac181b75aa",
      "name": "Set Error Response",
      "type": "n8n-nodes-base.set",
      "position": [
        1008,
        240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7ab380a2-a8d3-421c-ab4e-748ea8fb7904",
              "name": "response",
              "type": "string",
              "value": "Unable to perform task. Please try again."
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "1179a3bf-829c-4a63-8258-6fdd3483a4cf",
      "name": "Set Success Response",
      "type": "n8n-nodes-base.set",
      "position": [
        1008,
        80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "39c2f302-03be-4464-a17a-d7cc481d6d44",
              "name": "=response",
              "type": "string",
              "value": "={{$json.output}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9e1324f8-2f92-4d85-a238-3621aad1a1d6",
      "name": "Manage Calendar with AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueErrorOutput",
      "position": [
        624,
        80
      ],
      "parameters": {
        "text": "=={{ $json.query }}",
        "options": {
          "systemMessage": "=# Calendar Assistant System\n\n## Core Profile\nYou are a calendar assistant managing events through creation, retrieval, and modifications. All events default to one hour duration if unspecified.\n\nCurrent Time Context: {{ $now }}\n\n## Tools & Operations\n\n### Creation Tools\n- \"Create Event with Attendee\"\n  \u2192 Use for events with participants\n  \u2192 Requires: eventStart, eventEnd, eventTitle, eventAttendeeEmail\n\n- \"Create Event\"\n  \u2192 Use for solo events\n  \u2192 Requires: eventStart, eventEnd, eventTitle\n\n### Management Tools\n- \"Get Events\"\n  \u2192 Required before any modification/deletion\n  \u2192 Parameters: dayBefore, dayAfter\n\n- \"Update Event\"\n  \u2192 Modify existing events (requires Get Events first)\n  \u2192 Parameters: eventID, startTime, endTime\n\n- \"Delete Event\"\n  \u2192 Remove events (requires Get Events first)\n  \u2192 Parameters: eventID\n\n## Key Rules\n- Always retrieve events before updating or deleting\n- Verify event details before modifications\n- Default to one-hour duration when unspecified\n\n\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.6
    },
    {
      "id": "a46ed702-dca7-4858-bd2e-1cf8290091f4",
      "name": "Create Calendar Event with Attendee",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1056,
        512
      ],
      "parameters": {
        "end": "={{ $fromAI(\"eventEnd\") }}",
        "start": "={{ $fromAI(\"eventStart\") }}",
        "calendar": {
          "__rl": true,
          "mode": "id",
          "value": "user@example.com"
        },
        "additionalFields": {
          "summary": "={{ $fromAI(\"eventTitle\") }} with {{ $fromAI(\"eventAttendeeEmail\") }}",
          "attendees": [
            "={{ $fromAI(\"eventAttendeeEmail\") }}"
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "ca988e4c-2ee3-4018-a2b5-483ba45dba0f",
      "name": "Create Calendar Event",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        896,
        512
      ],
      "parameters": {
        "end": "={{ $fromAI(\"eventEnd\") }}",
        "start": "={{ $fromAI(\"eventStart\") }}",
        "calendar": {
          "__rl": true,
          "mode": "id",
          "value": "user@example.com"
        },
        "additionalFields": {
          "summary": "={{ $fromAI(\"eventTitle\") }}",
          "attendees": []
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "fe7c894c-42ae-4d3a-9e68-5ba02209d448",
      "name": "Get Calendar Events",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        576,
        512
      ],
      "parameters": {
        "options": {},
        "timeMax": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Before', `the day after the date the user requested`, 'string') }}",
        "timeMin": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('After', `the day before the date the user requested`, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "id",
          "value": "=ankitraitalks@gmail.com"
        },
        "operation": "getAll"
      },
      "typeVersion": 1.3
    },
    {
      "id": "57e3b327-ac97-442a-bf10-a15ec2771991",
      "name": "Delete Calendar Event",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        416,
        512
      ],
      "parameters": {
        "eventId": "={{ $fromAI(\"eventID\") }}",
        "options": {},
        "calendar": {
          "__rl": true,
          "mode": "id",
          "value": "user@example.com"
        },
        "operation": "delete"
      },
      "typeVersion": 1.3
    },
    {
      "id": "6198f0c1-c5ee-4d74-ad0e-b76ae6e4a3ea",
      "name": "Update Calendar Event",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        736,
        512
      ],
      "parameters": {
        "eventId": "={{ $fromAI(\"eventID\") }}",
        "calendar": {
          "__rl": true,
          "mode": "id",
          "value": "user@example.com"
        },
        "operation": "update",
        "updateFields": {
          "end": "={{ $fromAI(\"endTime\") }}",
          "start": "={{ $fromAI(\"startTime\") }}"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "867bf61d-bfda-4c77-9ec9-17f45e09f58b",
      "name": "Receive Calendar Query",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        384,
        64
      ],
      "parameters": {
        "inputSource": "jsonExample",
        "jsonExample": "{\n  \"query\": \"string\"\n}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "b03e6e02-620c-4566-8968-40dae8b1f822",
      "name": "OpenAI GPT-4.1 Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        624,
        240
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "gpt-4.1"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "84c0043b-d65b-437e-b780-0f329150d6b7",
      "name": "Intro Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        -96
      ],
      "parameters": {
        "width": 384,
        "height": 784,
        "content": "## Google Calendar AI Assistant\n\n### **What it does:**\nAI-powered calendar management sub-workflow that creates, retrieves, updates, and deletes Google Calendar events via natural language queries.\n\n### **Why it matters:**\nEliminates manual calendar management \u2014 users interact in plain English and the AI agent handles all Google Calendar operations automatically.\n\n### **How it works:**\n1. Parent workflow sends a natural language query (e.g., \"Schedule a meeting tomorrow at 2pm\")\n2. AI Agent (GPT-4.1) interprets the request and selects the right calendar tool\n3. Google Calendar tools execute the operation (create, read, update, or delete)\n4. Response is returned to the parent workflow (success or error)\n\n### **Setup steps:**\n1. Connect your **Google Calendar OAuth2** credentials\n2. Update the calendar ID (`milo.bravo@gmail.com`) to your own\n3. Connect your **OpenAI API** credentials\n4. Call this workflow from a parent workflow passing `{ \"query\": \"your request\" }`"
      },
      "typeVersion": 1
    },
    {
      "id": "fd80754c-febe-427d-989e-a04784adfc0e",
      "name": "Section 1 Trigger",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        -96
      ],
      "parameters": {
        "color": 6,
        "width": 260,
        "height": 468,
        "content": "## 1. Receive Query\n\nSub-workflow trigger accepts a `query` string from the parent workflow containing the user's natural language calendar request."
      },
      "typeVersion": 1
    },
    {
      "id": "6e951093-6175-4e37-8bcf-bb8d6ac2c541",
      "name": "Section 2 AI Agent",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        592,
        -96
      ],
      "parameters": {
        "color": 2,
        "width": 320,
        "height": 466,
        "content": "## 2. AI Calendar Agent\n\nGPT-4.1 interprets the natural language query, selects the appropriate Google Calendar tool, and executes the operation. Defaults to 1-hour events when duration is unspecified."
      },
      "typeVersion": 1
    },
    {
      "id": "7d861538-61e1-4ce6-8345-1dd838fb40c2",
      "name": "Section 3 Calendar Tools",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        400
      ],
      "parameters": {
        "color": 5,
        "width": 920,
        "height": 288,
        "content": "## 3. Google Calendar Tools\n\nFive calendar operations available to the AI agent: **Delete**, **Get**, **Update**, **Create**, and **Create with Attendee**. Agent must retrieve events before updating or deleting."
      },
      "typeVersion": 1
    },
    {
      "id": "0a0c2cb3-4ede-457f-a797-075da2535df6",
      "name": "Section 4 Response",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        944,
        -96
      ],
      "parameters": {
        "color": 4,
        "width": 280,
        "height": 480,
        "content": "## 4. Return Response\n\nRoutes the agent output back to the parent workflow. **Success** returns the AI agent's output. **Error** returns a fallback message prompting the user to try again."
      },
      "typeVersion": 1
    },
    {
      "id": "4bd2b674-172f-4df0-9a54-d0a9451b0c50",
      "name": "Contact & Attribution",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        -96
      ],
      "parameters": {
        "width": 700,
        "height": 1284,
        "content": "## Was this helpful? Get in touch!\n\nI really hope this automation helped you. Your feedback is incredibly valuable and helps me create better resources for business and the n8n community.\n\n### **Have Feedback, a Question, or a Project Idea?**\n\nI've streamlined the way we connect. It all starts with one simple form that takes less than 10 seconds. After that, you'll chat with my AI assistant who will gather the key details and pass them directly on to me.\n\n####  **[Start the conversation here](https://tally.so/r/EkKGgB)**\n\n*   **Give Feedback:** Share your thoughts on this template\u2014whether you found a typo, encountered an unexpected error, have a suggestion, or just want to say thanks!\n\n*   **n8n Consulting:** Have a complex business challenge or need a custom workflow built from scratch? Let's partner on a powerful automation solution tailored to your specific needs.\n\n*   **Join your team:** We can work together to get you launched with confidence.\n\n---\n\nHappy Automating!\n[Milo Bravo](https://linkedin.com/in/MiloBravo/) | BRaiA Labs | Automation & BI Systems + AI Integration\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b099f55f-5b6d-4025-8be1-3a759067163d",
  "connections": {
    "Get Calendar Events": {
      "ai_tool": [
        [
          {
            "node": "Manage Calendar with AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create Calendar Event": {
      "ai_tool": [
        [
          {
            "node": "Manage Calendar with AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Delete Calendar Event": {
      "ai_tool": [
        [
          {
            "node": "Manage Calendar with AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update Calendar Event": {
      "ai_tool": [
        [
          {
            "node": "Manage Calendar with AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Receive Calendar Query": {
      "main": [
        [
          {
            "node": "Manage Calendar with AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4.1 Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Manage Calendar with AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Manage Calendar with AI Agent": {
      "main": [
        [
          {
            "node": "Set Success Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Error Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Calendar Event with Attendee": {
      "ai_tool": [
        [
          {
            "node": "Manage Calendar with AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}