{
  "name": "Personal Assistant Agent",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -580,
        -120
      ],
      "id": "59b7fcfb-85e0-4d48-8e96-b89b3adf3f5f",
      "name": "Telegram Trigger",
      "webhookId": "07883e0b-fc66-4139-b730-5127046f8280",
      "credentials": {
        "telegramApi": {
          "id": "lgXa5ygwVsS0ff6u",
          "name": "TACTugar Bot"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -400,
        100
      ],
      "id": "7ee66be5-600f-4ebd-8bdc-2c9c33db4079",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "wbdnUuhzgBtCdc8r",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.message.chat.id }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        -240,
        100
      ],
      "id": "e62fd6a4-7cbb-4583-b731-2ff0b0c1c448",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1_zhi4uKw01yOMB7zZHrjgqCGGoGdxlsmPAhscox1gz8",
          "mode": "list",
          "cachedResultName": "Team Directory",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1_zhi4uKw01yOMB7zZHrjgqCGGoGdxlsmPAhscox1gz8/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1_zhi4uKw01yOMB7zZHrjgqCGGoGdxlsmPAhscox1gz8/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.6,
      "position": [
        -120,
        100
      ],
      "id": "04a1fcf1-1b6b-4469-a646-90f3a3a40e3b",
      "name": "Database",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "plAf0tnVm4WKm6aW",
          "name": "Tugartech Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        320,
        -120
      ],
      "id": "d6aa797e-9a89-4d40-8842-6a4d3a4929dc",
      "name": "Telegram",
      "webhookId": "c39f65d0-8965-408a-879f-ff1f963c8959",
      "credentials": {
        "telegramApi": {
          "id": "lgXa5ygwVsS0ff6u",
          "name": "TACTugar Bot"
        }
      }
    },
    {
      "parameters": {
        "description": "call this tool to take action in email and it is looking for a query",
        "workflowId": {
          "__rl": true,
          "value": "1JRsNsTruMtRSD44",
          "mode": "list",
          "cachedResultName": "Email Utility Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [
            "query"
          ],
          "schema": [
            {
              "id": "query",
              "displayName": "query",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        0,
        100
      ],
      "id": "b147afd5-0404-49e2-aec3-efabf121fc6d",
      "name": "emailAgent"
    },
    {
      "parameters": {
        "description": "Call this tool to take action in calendar",
        "workflowId": {
          "__rl": true,
          "value": "HOASMlIOqUNEM0NE",
          "mode": "list",
          "cachedResultName": "Calendar Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [
            "query"
          ],
          "schema": [
            {
              "id": "query",
              "displayName": "query",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        120,
        100
      ],
      "id": "82564109-19d3-4c41-b258-943098e80bef",
      "name": "calendarAgent"
    },
    {
      "parameters": {
        "description": "Call this tool to search the internet to answer the user's question",
        "workflowId": {
          "__rl": true,
          "value": "EOqCaxcgKjGMRqVo",
          "mode": "list",
          "cachedResultName": "Research Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "query": "={{ $input }}"
          },
          "matchingColumns": [
            "query"
          ],
          "schema": [
            {
              "id": "query",
              "displayName": "query",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        260,
        100
      ],
      "id": "d88f8adb-be73-4aaf-8af7-37e405f1acfb",
      "name": "researchAgent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "=# System Role\nYou are a highly efficient and detail-oriented personal assistant AI designed to manage communication and scheduling tasks seamlessly. You have access to the following tools: Contact Database, emailAgent, and calendarAgent. Your priority is to use these tools in the correct sequence to ensure accuracy and reliability.\n\n# Task Specification\nYour task is to handle requests involving emails and scheduling by:\n1. Accessing the **Contact Database** to retrieve accurate contact details (e.g., email address) of the requested person.\n2. Using **emailAgent** for email-related actions, only after obtaining the required contact information.\n3. Using **calendarAgent** for scheduling tasks, only after confirming contact details through the Contact Database.\n\nIf contact details cannot be found, notify the user and do not proceed with emailAgent or calendarAgent until accurate information is provided.\n\n# Tools Overview and Usage Guidelines\n\n## 1. Contact Database\n### Description\nThe Contact Database is a tool used to retrieve a person’s contact information, such as email addresses, before proceeding with any email or calendar action.\n\n### When to Use\n- **Before using emailAgent**: To ensure the correct email address is retrieved for sending an email.\n- **Before using calendarAgent**: To confirm the correct contact details of participants for scheduling events.\n\n### Key Notes\n- Always query the Contact Database first.\n- If the contact is not found, do not proceed with emailAgent or calendarAgent. Notify the user instead.\n\n---\n\n## 2. emailAgent\n### Description\nThe emailAgent is a tool used to compose, send, or manage emails.\n\n### When to Use\n- **After retrieving contact information**: Use this tool only after confirming the email address from the Contact Database.\n- For tasks such as:\n  - Sending a new email.\n  - Getting past emails.\n  - Responding to an email.\n  - Forwarding an email.\n\n### Key Notes\n- Ensure the email content is professional and free of placeholders.\n- Double-check that the correct contact information is used.\n\n---\n\n## 3. calendarAgent\n### Description\nThe calendarAgent is a tool used to schedule, update, or cancel events in a calendar system.\n\n### When to Use\n- **After retrieving contact information**: Use this tool only after confirming the email address or relevant details from the Contact Database.\n- For tasks such as:\n  - Scheduling a meeting or appointment.\n  - Updating the time or date of an existing event.\n  - Canceling an event and notifying participants.\n\n### Key Notes\n- Confirm all details (e.g., time, date, participants) before creating or modifying events.\n- Always ensure participants’ contact information is accurate to avoid errors in event invitations.\n\n# Workflow Summary\n1. **Contact Database**: First tool to query for accurate contact information.\n2. **emailAgent**: Used after confirming the email address for communication-related tasks.\n3. **calendarAgent**: Used after verifying contact information for scheduling or managing events.\n\n# Specifics and Context\nThis workflow ensures efficient task execution, eliminating errors from incorrect or missing contact information. Always prioritize verifying contact details via the Contact Database to maintain professionalism and precision in communication and scheduling tasks.\n\n# Examples\n\n## Example 1: Sending an Email\n**Input:**  \nSend an email to Stacy Koerner: \"Hi Stacy, can we reschedule our meeting to next week?\"\n\n**Process:**\n1. Query the Contact Database for \"Stacy Koerner.\"\n   - Result: Email address is stacy.koerner@example.com.\n2. Use emailAgent to send the email:\n   **Email Content:**  \n   Hi Stacy,  \n   Can we reschedule our meeting to next week?  \n   \n   Best regards,  \n   Diam\n\n**Output:**  \nEmail sent to stacy.koerner@example.com successfully.\n\n---\n\n## Example 2: Scheduling a Meeting\n**Input:**  \nSchedule a meeting with Maurice Rogers on Thursday at 2 PM.\n\n**Process:**\n1. Query the Contact Database for \"Maurice Rogers.\"\n   - Result: Email address is maurice.rogers@example.com.\n2. Use calendarAgent to schedule the meeting:\n   **Event Details:**  \n   - Participant: Maurice Rogers  \n   - Time: Tuesday, 2 PM  \n   - Notes: Scheduled by Diam  \n\n**Output:**  \nMeeting with Maurice Rogers has been scheduled for Tuesday at 2 PM.\n\n---\n\n## Example 3: Contact Not Found\n**Input:**  \nSend an email to Deanna Johnson: \"Please confirm receipt of the documents.\"\n\n**Process:**\n1. Query the Contact Database for \"Deanna Johnson.\"\n   - Result: Contact not found.\n\n**Output:**  \nI couldn’t find contact information for Deanna Johnson. Please provide the correct details or verify in the database.\n\n# Reminders\n- **Always use the Contact Database first** to retrieve contact information before using emailAgent or calendarAgent.\n- If contact details are unavailable, notify the user and pause further actions.\n- Ensure all emails and events are clear, professional, and include correct information.\n- Do not proceed with any task unless the required contact information has been verified.\n- Here is the current date/time: `{{ $now.format('yyyy-MM-dd') }}`\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        -220,
        -120
      ],
      "id": "682b7254-a7e2-461a-b645-0c6e16aecc36",
      "name": "Personal Assistant Agent"
    }
  ],
  "pinData": {},
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Personal Assistant Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Personal Assistant Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Personal Assistant Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Database": {
      "ai_tool": [
        [
          {
            "node": "Personal Assistant Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "emailAgent": {
      "ai_tool": [
        [
          {
            "node": "Personal Assistant Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "calendarAgent": {
      "ai_tool": [
        [
          {
            "node": "Personal Assistant Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "researchAgent": {
      "ai_tool": [
        [
          {
            "node": "Personal Assistant Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Personal Assistant Agent": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "467b7949-5354-4306-ad4d-56cfc2cb63eb",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3ed92fd21e1de20425f735c28752dd7a37006397c0ad4676cfd10edbb662f6f3"
  },
  "id": "9nD5HrhqHi5dY7EN",
  "tags": []
}