{ "meta": { "instanceId": "84ba6d895254e080ac2b4916d987aa66b000f88d4d919a6b9c76848f9b8a7616", "templateId": "2446" }, "nodes": [ { "id": "af0765f4-75b5-445c-80d7-51b0aa180fe5", "name": "OpenAI Chat Model2", "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "position": [ 820, 620 ], "parameters": { "model": "gpt-4o", "options": { "temperature": 0, "responseFormat": "text" } }, "typeVersion": 1 }, { "id": "497c534e-e117-4592-b76f-bef424a7fd5a", "name": "Respond to Webhook", "type": "n8n-nodes-base.respondToWebhook", "position": [ 1500, 400 ], "parameters": { "options": {} }, "typeVersion": 1.1 }, { "id": "5b358850-cbc3-4a8c-b2b8-12e3b7aa1e44", "name": "calendarAgent", "type": "@n8n/n8n-nodes-langchain.toolWorkflow", "position": [ 1060, 620 ], "parameters": { "name": "calendarAgent", "fields": { "values": [ { "name": "sessionId", "stringValue": "={{ $json.sessionId }}" }, { "name": "prompt", "stringValue": "={{ $json.chatInput }}" } ] }, "workflowId": { "__rl": true, "mode": "list", "value": "yPCMz4zxB291oM31", "cachedResultName": "Google Calendar Agent" }, "description": "Call this workflow to do handle every request regarding calendar management.", "responsePropertyName": "output" }, "typeVersion": 1.2 }, { "id": "8bcc4b27-59b9-4ce3-8525-34221c10f11a", "name": "When chat message received", "type": "@n8n/n8n-nodes-langchain.chatTrigger", "position": [ 460, 480 ], "webhookId": "96e410fe-ef91-4767-aa9a-bf95ba50f972", "parameters": { "public": true, "options": {} }, "typeVersion": 1.1 }, { "id": "0aa8e0ff-7ed3-4fef-9b7c-f2caa8f85612", "name": "taskAgent", "type": "@n8n/n8n-nodes-langchain.toolWorkflow", "position": [ 1180, 620 ], "parameters": { "name": "taskAgent", "fields": { "values": [ { "name": "sessionId", "stringValue": "={{ $json.sessionId }}" }, { "name": "prompt", "stringValue": "={{ $json.chatInput }}" } ] }, "workflowId": { "__rl": true, "mode": "list", "value": "ICTXOidW1oyJDYP7", "cachedResultName": "Notion Task Agent" }, "description": "Call this workflow to do handle every request regarding task management.", "responsePropertyName": "output" }, "typeVersion": 1.2 }, { "id": "b46f4ed0-6de6-44ab-8b91-521b011d7869", "name": "Window Buffer Memory", "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow", "position": [ 940, 620 ], "parameters": { "sessionKey": "={{ $json.sessionId }}", "sessionIdType": "customKey", "contextWindowLength": 15 }, "typeVersion": 1.2 }, { "id": "e778c2bf-1681-418d-a434-d1a0cdeaa5d7", "name": "Map Fields", "type": "n8n-nodes-base.set", "position": [ 680, 320 ], "parameters": { "options": {}, "assignments": { "assignments": [ { "id": "f8c5a03f-ea21-4877-a71b-32e8b4dd30fb", "name": "chatInput", "type": "string", "value": "={{ $json.body.prompt }}" }, { "id": "3d4fecc4-78a5-47ba-a239-5fdc9b224d82", "name": "sessionId", "type": "string", "value": "={{ $json.body.sessionID }}" } ] } }, "typeVersion": 3.4 }, { "id": "c54d0fab-b25c-48fc-b027-dcdf78dd2b09", "name": "Map Fields1", "type": "n8n-nodes-base.set", "position": [ 680, 480 ], "parameters": { "options": {}, "assignments": { "assignments": [ { "id": "36f24729-17ae-4d69-961f-424a1797b42c", "name": "chatInput", "type": "string", "value": "={{ $json.chatInput }}" }, { "id": "05ea359a-d82e-4917-9245-38016314ad10", "name": "sessionId", "type": "string", "value": "={{ $json.sessionId }}" } ] } }, "typeVersion": 3.4 }, { "id": "cefe6cc8-4a87-47c8-a518-c0bf06f96a2a", "name": "Exclude Previews from Speech", "type": "n8n-nodes-base.set", "position": [ 1280, 400 ], "parameters": { "options": {}, "assignments": { "assignments": [ { "id": "424b3c35-fd3d-4021-86e7-0d90529550b0", "name": "response.text", "type": "string", "value": "={{ $json.output }}" }, { "id": "0cbe6fd9-3464-4bd1-b9c0-365548dc232a", "name": "response.speech", "type": "string", "value": "={{ $if($json.output.search(/>\\s/) > -1, $json.output.substring(0, $json.output.search(/>\\s/)), $json.output) }}" } ] } }, "typeVersion": 3.4 }, { "id": "815eb1a4-ef2d-430d-8884-217164214440", "name": "Main Agent", "type": "@n8n/n8n-nodes-langchain.agent", "position": [ 900, 400 ], "parameters": { "text": "={{ $json.chatInput }}", "options": { "systemMessage": "=# Role:\nYou are a helpful assistant. Your sole responsibility is to determine which tool to forward the original chat input to. Do not process, modify, or interpret the input or output in any way. Only route it to the correct tool.\n\n# Behavior:\nBe clear, very concise, and accurate in tool routing. Do not modify, interpret, or analyze the incoming input or the tool's response. If the request is ambiguous, ask for clarification regarding tool selection only.\n\n# Command:\nRoute all incoming requests to the available tools if they match their description.\nCheck the memory to route ongoing conversations correctly — only choose another tool if a new task has been requested or the context clearly has been switched. If the context has changed (e.g. you were asked to create a task before, but now the user asks to create an event), forget everything before the context switch.\n\nOnly call one tool at a time.\n\nDo not modify or alter the input before sending it to the tool or the output after receiving it from the tool. Simply pass through both input and output as they are.\n\n# Format:\nPass every response of each tool in raw format to the output. Do not modify, interpret, or add any information at all." }, "promptType": "define" }, "typeVersion": 1.6 }, { "id": "07b6d7e2-ab73-4f23-8dca-7c8b0309574c", "name": "OpenAI Chat Model", "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "position": [ 1520, 1100 ], "parameters": { "model": "gpt-4o", "options": { "temperature": 0 } }, "typeVersion": 1 }, { "id": "882a93d8-886e-465d-9c81-cc8069abd281", "name": "HTTP Request", "type": "@n8n/n8n-nodes-langchain.toolHttpRequest", "position": [ 1760, 1100 ], "parameters": { "url": "https://api.notion.com/v1/pages", "method": "POST", "jsonBody": "={\n \"parent\": {\n \"database_id\": \"{{ $json.databaseID }}\"\n },\n \"properties\": {\n \"Name\": {\n \"title\": [\n {\n \"text\": {\n \"content\": \"{title}\"\n }\n }\n ]\n },\n \"Priority\": {\n \"select\": {\n \"name\": \"{priority}\"\n }\n }\n },\n \"children\": [\n {\n \"object\": \"block\",\n \"type\": \"paragraph\",\n \"paragraph\": {\n \"rich_text\": [\n {\n \"type\": \"text\",\n \"text\": {\n \"content\": \"{description}\"\n }\n }\n ]\n }\n }\n ]\n}", "sendBody": true, "specifyBody": "json", "authentication": "predefinedCredentialType", "toolDescription": "Create a Task in Notion using a title, description and priority.", "nodeCredentialType": "notionApi", "placeholderDefinitions": { "values": [ { "name": "title", "type": "string", "description": "The name / title of the task." }, { "name": "description", "type": "string", "description": "The description of the task." }, { "name": "priority", "type": "string", "description": "The priority of the task. One of these values: \"do first\", \"important\", \"urgent\"" } ] } }, "typeVersion": 1.1 }, { "id": "e19aad2c-132e-454f-a091-334f128b0636", "name": "Settings", "type": "n8n-nodes-base.set", "position": [ 1320, 880 ], "parameters": { "options": {}, "assignments": { "assignments": [ { "id": "3f65df4c-fae1-4da3-acfd-acf352a3f8d2", "name": "sessionId", "type": "string", "value": "={{ $json.sessionId }}" }, { "id": "9745bdbd-fd97-46db-a742-6540f86dd43c", "name": "chatInput", "type": "string", "value": "={{ $json.prompt }}" }, { "id": "5e757768-d780-4b11-a6e0-593b08f32cc3", "name": "databaseID", "type": "string", "value": "92da2aa018ed4095afc0f1a0670f36e9" } ] } }, "typeVersion": 3.4 }, { "id": "0fe6aa57-7a64-40f4-af2d-30f4286b8aee", "name": "Format output", "type": "n8n-nodes-base.set", "position": [ 1920, 880 ], "parameters": { "options": {}, "assignments": { "assignments": [ { "id": "934c387a-71a5-4549-a68a-312708368117", "name": "output", "type": "string", "value": "=Please respond this to the user without modifications:\n\n{{ $json.output }}" } ] } }, "typeVersion": 3.4 }, { "id": "b2170997-5ebb-4261-92ce-70b33d68931f", "name": "Notion Task Agent", "type": "@n8n/n8n-nodes-langchain.agent", "position": [ 1540, 880 ], "parameters": { "options": { "systemMessage": "=# Role:\nYou are a helpful assistant. Your job is to create Tasks in Notion.\n\n# Behavior:\nBe clear, very concise, efficient, and accurate in responses. If the request is ambiguous, ask for clarification.\n\n# Command:\nYou create tasks in Notion. Each task consists of the mandatory fields title, description and priority. Priority is an enum value consisting of 'do first', 'important' and 'urgent'.\n\n# Ask questions:\nIf required information is missing, ask the user about the missing information and only the missing ones. Ask priority as last.\n\nIf the user only describes the task within a few words, use that as the title. In that case, ask the user, if he wants to add a more detailed description. If he responds with \"No\", leave the description empty when creating the task.\nOn the other hand if the user describes the task more detailed from the beginning, use that as the description and create a short meaningful title for that. \n\nIf you have all the required information, ask for approval, before creating the task. In that case, always return a draft, containing the title, description and priority.\n\n# Format:\nThe output of the draft for approval should always be in markdown and in this format (placeholders in angle brackets):\n\nHere is the drafted task. Shall I create it?\n\n> **