{
  "createdAt": "2025-02-22T10:28:17.398Z",
  "updatedAt": "2025-04-06T18:00:29.683Z",
  "id": "TOo4Busz8MkM0m5C",
  "name": "agendamento de horario",
  "active": false,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "public": true,
        "options": {}
      },
      "id": "cef6fe78-68b0-4a71-8e7b-ab0d7158f870",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        100,
        380
      ],
      "typeVersion": 1.1
    },
    {
      "parameters": {},
      "id": "7fae8971-4e78-4a91-bb57-ec7797e19a54",
      "name": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        960,
        1160
      ],
      "typeVersion": 1.3
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool when you\u2019re asked to retrieve events data.",
        "operation": "getAll",
        "calendar": {
          "__rl": true,
          "value": "63472a944e1619140bcf1d944ecb587692ecd925c1e08a6fd8d8076e1c3badde@group.calendar.google.com",
          "mode": "list",
          "cachedResultName": "faculdade_agendamentos"
        },
        "options": {
          "timeMin": "={{ $fromAI('start_date') }}",
          "timeMax": "={{ $fromAI('end_date') }}"
        }
      },
      "id": "c76d52e0-2687-42b2-8cea-3fe0cffb8cc5",
      "name": "Google Calendar - Get Events",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1340,
        1180
      ],
      "typeVersion": 1.2,
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Chat trigger - When a message is received\n\nThis node is the **entry point of the workflow**.  \nIt triggers the workflow whenever a message is sent to the **chat interface**.\n\nOptions with n8n:\n- **Embed the chat interface** anywhere you want.\n- Use a **webhook node** instead of this node to connect with interfaces like **[Streamlit](https://docs.streamlit.io/develop/tutorials/llms/build-conversational-apps)** or **[OpenWebUI](https://docs.openwebui.com/)**.\n- Use nodes for communication platforms (**Slack**, **Teams**, **Discord**, etc.) if you know how to configure them.\n",
        "height": 560,
        "width": 320,
        "color": 7
      },
      "id": "1ff3b09f-e2ed-4d46-b1b3-cc34054d0afe",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## Tools Agent - Calendar AI Agent\n\nThis **node** configures the **AI agent** for interaction with Google Calendar.  \nIt includes the following features:\n\n- A **prompt source**: This is the user message derived from the chat input of the preceding node (`When chat message is received`).\n- A **system message**: This defines the system prompt to guide the AI agent's behavior. It incorporates the variable `{{ DateTime.local().toFormat('cccc d LLLL yyyy') }`, allowing the AI agent to determine the current date and interact with Google Calendar accordingly. For example, the agent can understand a request like \"Create an event called 'n8n workflow review' for next Tuesday.\"\n\n\nn8n nodes come with built-in **guardrails**, ensuring that if the user requests tasks outside the AI agent's setup, it may not function as intended. (Feel free to test it!)\n",
        "height": 560,
        "width": 1520,
        "color": 7
      },
      "id": "83ed8297-4423-4d2b-bb86-a43e04666367",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        540,
        20
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## OpenAI chat model\n\nThis node specifies the chat model used by the agent.  \nIn the template, the **default LLM is gpt-4o** for its high relevance.\n\nOther options:\n- You can **try gpt-4o-mini**, which is more cost-effective.\n- You can also choose **other LLM providers besides OpenAI**, but make sure the LLM you select **supports tool-calling**.\n",
        "height": 720,
        "width": 320,
        "color": 5
      },
      "id": "00f60427-d1b6-4fde-98c0-3bee6f6e6112",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        440,
        620
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## Window buffer memory\n\nThis node manages the **memory** of the agent, specifically the **context window length** for chat history.  \nThe default is set to 5 messages.\n\nNote:  \nThe **memory** is **temporary**. If you want to **store conversations with the agent**, you should use other nodes like **Postgres chat memory**.  \nThis can be easily set up with services like **[Supabase](https://supabase.com/)**.\n",
        "height": 720,
        "width": 320,
        "color": 5
      },
      "id": "b5d9c1b2-4e2a-430b-b2e2-36eb1a82ea40",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        840,
        620
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## Google Calendar - Get Events\n\nThis sub-node is a tool used by the AI agent.  \nIts purpose is to **retrieve events based on the user input**.  \nFor example: *\"Can you give me the events from last week about internal process ?\"*\n\nThe AI agent is designed to **use this tool only** when it has a **date range**.  \nIf the user hasn\u2019t provided a date range, the **AI agent will ask the user** for it.\n\nThe **variables** `{{ $fromAI('start_date') }}` and `{{ $fromAI('end_date') }}` are **dynamically filled by the AI**.\n",
        "height": 720,
        "width": 320,
        "color": 5
      },
      "id": "e1d68597-f3db-487a-8a40-ea988d0e2692",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1240,
        620
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## Google Calendar - Create Events\n\nThis sub-node is a tool used by the AI agent.  \nIts purpose is to **create events based on the user input**.  \nFor example: \"Can you create an event 'Quarter revenue meeting' on [date] from [hour] to [hour] ?\"\n\nThe AI agent is designed to **use this tool only** when it has a **date range**.  \nIf the user hasn\u2019t provided a **date range**, the AI agent will **ask the user** for it.  \nThe variables `{{ $fromAI('start_date') }}` and `{{ $fromAI('end_date') }}` are dynamically filled by the AI.\n\nBefore creating the event, the AI agent will **confirm with the user** if the **title** and **description** of the event are correct.  \nThe variables used for this are:\n- `{{ $fromAI('event_title') }}`\n- `{{ $fromAI('event_description') }}`\n",
        "height": 720,
        "width": 320,
        "color": 5
      },
      "id": "3d9cb30f-846d-412c-a18c-f05ea1466bc8",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1640,
        620
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## Having fun with it ? Here\u2019s how to level up this AI agent !  \n\nThis workflow demonstrates **how easily you can set up an AI agent to call tools** for you using **n8n**.  \nThe tasks here are **useful but very basic**.  \n\nIf you want to **enhance the tool-calling capabilities**, consider the following:\n\n- Explore the **\"options\"** in the Google Calendar nodes to see additional features you can use.  \n  For example, let the AI agent add attendees to events it creates.\n\n- Implement the AI agent with your **teammates and link it to each calendar**.  \n  Use a `{{ $fromAI('') }}` variable for the calendar field and refine the prompts to suit your needs.\n\n- Add **more actions** for the AI agent to perform with the **Google Calendar API**, expanding its functionality.\n",
        "height": 380,
        "width": 720,
        "color": 4
      },
      "id": "b11ce74b-523d-4eee-9b27-6afa56ba3796",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1240,
        1380
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "model": "llama-3.2-90b-vision-preview",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "typeVersion": 1,
      "position": [
        540,
        1000
      ],
      "id": "f5802284-ca17-4e85-8e2b-14ab5365a52f",
      "name": "Groq Chat Model",
      "credentials": {
        "groqApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "=You are a Google Calendar assistant.\nYour primary goal is to assist the user in managing their calendar effectively using two tools: Event Creation and Event Retrieval. Always base your responses on the current date: \n{{ DateTime.local().toFormat('cccc d LLLL yyyy') }}.\nGeneral Guidelines:\nIf the user's initial message is vague (e.g., \"hello\" or a generic greeting) or does not specify a request, explain your capabilities clearly:\nExample: \"Hello! I can help you manage your Google Calendar. You can ask me to create an event or retrieve event data. What would you like me to do?\"\nIf the user specifies a request in their first message, begin preparing to use the appropriate tool:\nFor event creation, gather necessary details like start date, end date, title,email and description.\nFor event retrieval, ask for the date range or time period they want to query.\nTool: Event_Creation\nWhen asked to create an event:\n\nRequest the start and end dates/times from the user.\nDate format: YYYY-MM-DDTHH:mm:ss-03:00\nCollect the following information:\nstart_date: Exact start date and time of the event.\nend_date: Exact end date and time of the event.\nevent_title: Event title in uppercase. Suggest one if not provided.\nevent_description: Generate a brief description and present it for confirmation.\nTool: Event Retrieval\nWhen asked to retrieve events:\nAsk for the date range or period they are interested in. Examples:\nFor \"last week,\" retrieve events from Monday of the previous week to Friday of the same week.\nfor a especific date and time get the eventid from the response of the tool to use the update event tool.\nFor \"today,\" use the current date.\nFormat the date range:\nstart_date: Start date and time in YYYY-MM-DDTHH:mm:ss-03:00.\nend_date: End date and time in YYYY-MM-DDTHH:mm:ss-03:00.\n\nKey Behaviors:\nClarity: Provide a clear and helpful introduction when the user's request is unclear.\nValidation: Confirm details with the user before finalizing actions.\nAdaptation: Handle varying levels of detail in requests (e.g., \"Add a meeting for next Monday morning\" or \"Retrieve my events for this weekend\").\nProactivity: Offer suggestions to fill in missing details or clarify ambiguous inputs.\nLanguage Matching: Ensure all interactions, including event titles, descriptions, and messages, are in the user's language to provide a seamless experience.\nuse the folowing output format for creation and update :{\n    \"summary\": \"string\",\n    \"description\": \"string\",\n    \"start\": {\n      \"dateTime\": \"string\"\n    },\n    \"end\": {\n      \"dateTime\": \"string\"\n    },\n    \"attendees\": [\n      {\n        \"email\": \"string\"\n      }\n    ]\neventId:string\n  }"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        680,
        280
      ],
      "id": "5b9ce82e-429d-4b9d-9513-9ac377cc770b",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "calendar": {
          "__rl": true,
          "value": "63472a944e1619140bcf1d944ecb587692ecd925c1e08a6fd8d8076e1c3badde@group.calendar.google.com",
          "mode": "list",
          "cachedResultName": "faculdade_agendamentos"
        },
        "start": "={{ $json.start.dateTime }}",
        "end": "={{ $json.end.dateTime }}",
        "additionalFields": {
          "attendees": [
            "={{ $json.attendees[0].email }}"
          ],
          "description": "={{ $json.description }}",
          "summary": "={{ $json.summary }}"
        }
      },
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1.3,
      "position": [
        1300,
        1880
      ],
      "id": "8d6d0245-aefd-4533-bdbc-37efa787fcdc",
      "name": "Google Calendar",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "id": "58826ab8-94e7-4807-ae4f-35f1be300f68",
      "name": "Execute Workflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        280,
        2020
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={{ $json.query }}\n",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1000,
        1860
      ],
      "id": "c157c356-6479-4b55-8604-46c33dc2f10f",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "name": "Event_Creation",
        "description": "Use this Google Calendar tool when you are asked to create an event.",
        "workflowId": "={{ $workflow.id }}",
        "fields": {
          "values": [
            {
              "name": "create",
              "type": "booleanValue"
            }
          ]
        }
      },
      "id": "d8754739-8799-44f7-8836-69b1b54c313a",
      "name": "Google Calendar - Create events",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        1780,
        1200
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "name": "Update_event",
        "description": "Use this Google Calendar tool when you are asked to update an event.",
        "workflowId": "={{ $workflow.id }}",
        "fields": {
          "values": [
            {
              "name": "update",
              "type": "booleanValue"
            }
          ]
        }
      },
      "id": "5b7b455d-705e-4329-a799-1212a0df43c5",
      "name": "Google Calendar - Update events",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        2100,
        1220
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "8cf121f5-56ac-4f42-926d-b8d2b4237fe9",
              "leftValue": "={{ $json.create }}",
              "rightValue": "true",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        700,
        1900
      ],
      "id": "1b4d33e0-aa3c-4605-8f52-87fd9a910741",
      "name": "If"
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={{ $json.query }}\n",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1020,
        2160
      ],
      "id": "2fb978aa-9f87-4255-af64-541c2d11b8ea",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "8cf121f5-56ac-4f42-926d-b8d2b4237fe9",
              "leftValue": "={{ $json.update }}",
              "rightValue": "true",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        680,
        2160
      ],
      "id": "81cecc9e-97b9-4724-864b-be72e2438a4c",
      "name": "If1"
    },
    {
      "parameters": {
        "operation": "update",
        "calendar": {
          "__rl": true,
          "value": "63472a944e1619140bcf1d944ecb587692ecd925c1e08a6fd8d8076e1c3badde@group.calendar.google.com",
          "mode": "list",
          "cachedResultName": "faculdade_agendamentos"
        },
        "eventId": "={{ $json.eventId }}",
        "updateFields": {
          "end": "={{ $json.end.dateTime }}",
          "start": "={{ $json.start.dateTime }}"
        }
      },
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1.3,
      "position": [
        1260,
        2180
      ],
      "id": "775db7f2-c29c-4472-bc18-a5b45dbad69c",
      "name": "Google Calendar1",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "delete",
        "deleteMode": "all"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "typeVersion": 1.1,
      "position": [
        -80,
        940
      ],
      "id": "2991f803-3e6a-41a0-8cf4-f8e7795bc374",
      "name": "Chat Memory Manager"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -440,
        940
      ],
      "id": "bce672d9-0c35-4183-bb88-0bfba135264e",
      "name": "When clicking \u2018Test workflow\u2019"
    }
  ],
  "connections": {
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          },
          {
            "node": "Chat Memory Manager",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar - Get Events": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar": {
      "main": [
        []
      ]
    },
    "Execute Workflow Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          },
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Google Calendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar - Create events": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar - Update events": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Google Calendar1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar1": {
      "main": [
        []
      ]
    },
    "When clicking \u2018Test workflow\u2019": {
      "main": [
        [
          {
            "node": "Chat Memory Manager",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "versionId": "57462e6c-1849-4939-be01-3578177a69e0",
  "triggerCount": 2,
  "tags": []
}