{
  "nodes": [
    {
      "id": "dbd0b5f4-bb55-4a33-b03e-3cabd5a7b840",
      "name": "Get many tickets",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        128,
        96
      ],
      "parameters": {
        "resource": "ticket",
        "operation": "getAll",
        "authentication": "oAuth2",
        "additionalFields": {
          "properties": [
            "content",
            "createdate",
            "hs_all_conversation_mentions",
            "hs_pipeline_stage",
            "subject",
            "hs_created_by_user_id",
            "hs_all_associated_contact_emails"
          ]
        }
      },
      "credentials": {
        "hubspotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "492b2964-330d-46c2-b667-7a0ceaabaec1",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1824,
        384
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {
          "temperature": 0
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fbf725e8-9fc3-4efa-abf3-1722d742af7e",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -96,
        544
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "route"
            },
            {
              "name": "userId"
            },
            {
              "name": "text"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "8d6628a5-4bca-47d6-a24c-25738e28b832",
      "name": "Sentinel",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        928,
        320
      ],
      "parameters": {
        "name": "Sentinel",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{$workflow.id }}"
        },
        "description": "Detects churn risk, customer intent, and emotional tone. ",
        "workflowInputs": {
          "value": {
            "text": "={{ $('Set the variables').item.json.message }}",
            "route": "Sentinel"
          },
          "schema": [
            {
              "id": "route",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "route",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "userId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "userId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "text",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "text",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "route"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "f3dd6fb6-bf9d-4abf-bb28-f6a8a600d6c7",
      "name": "Profiler",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        1056,
        320
      ],
      "parameters": {
        "name": "Profiler",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{$workflow.id }}"
        },
        "workflowInputs": {
          "value": {
            "route": "Profiler",
            "userId": "={{ $('Search contacts').item.json.id }}"
          },
          "schema": [
            {
              "id": "route",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "route",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "userId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "userId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "route"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "14a177f5-093b-4e0f-93dd-1ff41a04bd1c",
      "name": "Profiler_agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        352,
        688
      ],
      "parameters": {
        "text": "=# Overview  \nYou are a Profiler, an AI agent responsible for retrieving and analyzing a user's interactions from a CRM\n\n## Context  \n- Triggered by every incoming message.  \n- Retrieve any past interaction using the from_crm tool\n- Return the list of the past interactions\n\n## Instructions  \n1. get all interactions with the from_crm tool\n2. Return it to the agent\n---",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "df816db0-6ab1-47d5-bd7f-43f18db908d3",
      "name": "Sentinel_agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        352,
        384
      ],
      "parameters": {
        "text": "=# Overview  \nYou are Sentinel, an AI agent responsible for detecting risks and opportunities in customer communication. Your role is to analyze every inbound message for emotional tone, churn risk, and purchase intent. If any alert is triggered, you must immediately notify the customer via Messenger.\n\n## Context  \n- Triggered by every incoming message.  \n- Operates in real time and takes immediate action when any risk or intent signal is detected.  \n- Your objective is to preempt churn, detect intent to buy, and ensure the emotional tone is addressed quickly.  \n  ",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "0c8813a0-b865-4126-a263-defd06d803c7",
      "name": "Search contacts",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        416,
        96
      ],
      "parameters": {
        "operation": "search",
        "authentication": "oAuth2",
        "filterGroupsUi": {
          "filterGroupsValues": [
            {
              "filtersUi": {
                "filterValues": [
                  {
                    "value": "={{ $json.properties.hs_all_associated_contact_emails.value }}",
                    "propertyName": "email|string"
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {}
      },
      "credentials": {
        "hubspotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "9937e184-d03a-4688-b4d2-c4143e5d3d08",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1184,
        320
      ],
      "parameters": {
        "jsonSchemaExample": "{\n\t\"risk\": \"high\",\n\t\"text\": \"this is a text\",\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "366d8b7d-57aa-4716-8c92-7e736157929b",
      "name": "Orchestrator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        992,
        96
      ],
      "parameters": {
        "text": "=# Overview  \nYou are an AI orchestrator for a Customer Success (CS) system. Your role is to monitor incoming chat messages across any customer-facing channel and coordinate a real-time, automated response by leveraging various internal tools. Your ultimate goal is to reduce churn, boost engagement, automate support and marketing tasks, and connect internal teams with valuable insights.\nThe current date and time is {{ $now }}\n\n## Context  \n- Triggered by any new inbound message like:\n{{ $json.message }}\n- The system should operate autonomously without requiring human intervention.  \n- The orchestrator must adapt to each customer's context, sentiment, and intent.  \n\n## Instructions \n{{ $json.agent}}\n\n## Tools    \n- **Profiler**: Gathers real-time customer insights from CRM, tickets, and behavior. \n- **Sentinel**: Detects churn risk, customer intent, and emotional tone.  \n- **Classifier**: Chooses the right classification for the output message. In order to send it to the right person. \n\n## Examples  \n- Input: \"I'm really frustrated that my order is late.\"  \n- Output:  \n  1. **Sentinel** flags high frustration and churn risk. Sets \n  2. **Profiler** shows this is a repeat buyer with past complaints.  \n  3. **Classifier** fulfillment\n\n- Input: \"Why do I keep getting logged out of my account? This is so annoying!\"  \n- Output:  \n  1. **Sentinel** flags high frustration and possible churn risk.  \n  2. **Profiler** identifies frequent login issues over the past week and device/browser inconsistencies.  \n  3. **Classifier** technical\n\n- Input: \"I love the new dashboard update. Really smooth experience!\"  \n- Output:  \n  1. **Sentinel** detects positive sentiment and customer satisfaction.  \n  2. **Profiler** confirms the user is a long-time customer with high engagement.  \n  3. **Classifier** commercial\n\n## SOP (Standard Operating Procedure)  \n1. Detect inbound message across any channel.  \n2. Run sentiment, intent, and tone detection via **Sentinel**.  \n3. Enrich customer profile using **Profiler**.  \n4. Calssify the message using **Classifier**\n7. Monitor engagement outcome and update customer status.  \n\n## Final Notes  \n- Always prioritize empathetic and context-aware responses.  \n- Ensure internal teams only receive insights when relevant and actionable.  \n- Responses must be personalized, timely, and aligned with customer history.  \n- Operate entirely autonomously, but log all actions for transparency and review.  \n---\n\nIf one of the tool doesn't work, stop immediately",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "3299144b-a36a-4ae1-8269-599c2a98cb59",
      "name": "Set the variables",
      "type": "n8n-nodes-base.set",
      "position": [
        704,
        96
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bdc0fff6-b6fd-49e5-b308-040a7cfe3feb",
              "name": "message",
              "type": "string",
              "value": "={{ $('Get many tickets').item.json.properties.subject.value }}\n{{ $('Get many tickets').item.json.properties.content.value}}"
            },
            {
              "id": "a5341fdc-4936-42cd-8aff-b50e32bac86a",
              "name": "agents",
              "type": "string",
              "value": "1. When a new message arrives, analyze it for tone, intent, and urgency using **Sentinel**.  \n2. Query **Profiler** to fetch a full understanding of the customer's status, behavior, and history.  \n3. Use **Content Manager** to retrieve or personalize the appropriate content or message snippet.  \n4. If response suggestions are needed, activate **Guide** to auto-generate a suitable reply.  \n5. Send the response automatically via **Messenger**, choosing the right channel and timing.  \n6. If insights from the message or customer state can support other teams (e.g., product or sales), use **Facilitator** to share those insights internally.  \n7. Continuously update the customer profile and behavior signals in real time.  "
            },
            {
              "id": "cb6bd968-90ae-4692-bdf8-963f6b739884",
              "name": "agent",
              "type": "string",
              "value": "1. When a new message arrives, analyze it for tone, intent, and urgency using **Sentinel**.\n2. Query **Profiler** to fetch a full understanding of the customer's status, behavior, and history. \n3. Then run **Classifier** to get the classification of the message abd return it as a variable named \"class\" \n4. Then summarize the output of the Profiler using **Summarizer**\n5. You will return a variable named \"risk\" to true if you estimate that the client is at risk. False otherwise\n6. you will return the output as \"text\""
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c3031469-f7aa-4a76-8828-b5de0350c65e",
      "name": "Create an issue in Jira",
      "type": "n8n-nodes-base.jira",
      "position": [
        2112,
        128
      ],
      "parameters": {
        "project": {
          "__rl": true,
          "mode": "list",
          "value": "10001",
          "cachedResultName": "Testing n9n workflow"
        },
        "summary": "={{ $json.output.text }}",
        "issueType": {
          "__rl": true,
          "mode": "list",
          "value": "10011",
          "cachedResultName": "Epic"
        },
        "additionalFields": {
          "assignee": {
            "__rl": true,
            "mode": "list",
            "value": "712020:ca8ed082-0f07-48b8-b231-5a3bf70a74d4",
            "cachedResultName": "Thomas Vie"
          },
          "description": "={{ $('Orchestrator').item.json.output.text }}"
        }
      },
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "97c36385-a37b-4877-a3d3-6ae4a16433b7",
      "name": "Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        128,
        544
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "sentinel",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "ae3a40cd-b4ad-47af-bef8-87f7f97df1f4",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.route }}",
                    "rightValue": "Sentinel"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "profiler",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d6b7f19e-dc1d-4968-b661-e333ed0228b4",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.route }}",
                    "rightValue": "Profiler"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "048caf93-771a-4a11-b54f-e58bab648b86",
      "name": "from_crm",
      "type": "n8n-nodes-base.hubspotTool",
      "position": [
        432,
        912
      ],
      "parameters": {
        "contactId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When Executed by Another Workflow').item.json.userId }}"
        },
        "operation": "get",
        "authentication": "oAuth2",
        "additionalFields": {
          "propertiesCollection": {
            "propertiesValues": {
              "properties": [
                "hs_buying_role",
                "hs_conversations_visitor_email",
                "num_contacted_notes",
                "email"
              ]
            }
          }
        }
      },
      "credentials": {
        "hubspotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "beab4322-2f47-40e7-af70-d99986877bd1",
      "name": "Cateogory Classifier",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        1744,
        96
      ],
      "parameters": {
        "options": {
          "systemPromptTemplate": "Please classify the text provided by the user into one of the following categories: {categories}, and use the provided formatting instructions below. Don't explain, and only output the json."
        },
        "inputText": "={{ $('Orchestrator').item.json.output.text }}",
        "categories": {
          "categories": [
            {
              "category": "invoicing",
              "description": "for problems related to wrong invoice, delay of payment"
            },
            {
              "category": "technical",
              "description": "for problems related to software not working, for feature request."
            },
            {
              "category": "commercial",
              "description": "if the message is positive"
            },
            {
              "category": "fulfillment",
              "description": "for problems related to sending and receiving products, delayed shipments."
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "e1f92d13-5c4a-4078-ab18-b8a77462ecff",
      "name": "generate ticket title",
      "type": "@n8n/n8n-nodes-langchain.chainSummarization",
      "position": [
        1392,
        96
      ],
      "parameters": {
        "options": {
          "summarizationMethodAndPrompts": {
            "values": {
              "prompt": "=Write a concise title for a ticket of the following:\n\n{{ $json.output.text }}\n\n\nCONCISE SUMMARY: ",
              "combineMapPrompt": "=Write a concise title for a ticket of the following:\n{{ $json.output.text }}\n\n\"\"\n\n\nCONCISE SUMMARY:"
            }
          }
        },
        "chunkSize": 200,
        "chunkOverlap": 20
      },
      "typeVersion": 2.1
    },
    {
      "id": "11414136-f230-48eb-91dd-411ea79e85e4",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        352
      ],
      "parameters": {
        "color": 6,
        "width": 832,
        "height": 688,
        "content": "## Sub-worflows for agents\nHere eyou can add any agent that you need"
      },
      "typeVersion": 1
    },
    {
      "id": "41d01ec4-fdf0-43d1-8ec1-2075280ab5d4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1680,
        0
      ],
      "parameters": {
        "color": 5,
        "width": 656,
        "height": 288,
        "content": "## Ticket router\nSet here the repoonsible team for each category output"
      },
      "typeVersion": 1
    },
    {
      "id": "332c214a-3ac9-435b-b3a5-108756744a49",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        896,
        0
      ],
      "parameters": {
        "color": 5,
        "width": 752,
        "height": 464,
        "content": "## Ticket generation\nModify the prompt to suit your needs"
      },
      "typeVersion": 1
    },
    {
      "id": "540c7fa8-4de4-4e28-9c78-fdef19450154",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        16
      ],
      "parameters": {
        "color": 5,
        "width": 576,
        "height": 272,
        "content": "## Get tickets from Hubspot\nSet here your CRM retrieving system"
      },
      "typeVersion": 1
    },
    {
      "id": "a38ef7cf-89ce-423c-bda2-10063ac9f3dc",
      "name": "For testing",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -96,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2a389272-0f90-41e7-afca-24b194985732",
      "name": "Set the running interval",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -96,
        192
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "073896f5-d6cf-4be5-a57e-40673b394b55",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        -128
      ],
      "parameters": {
        "width": 768,
        "height": 100,
        "content": "## Contact me\n### If you need some help with this workflow: Write to me: [thomas@pollup.net](mailto:thomas@pollup.net)\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Router": {
      "main": [
        [
          {
            "node": "Sentinel_agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Profiler_agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Profiler": {
      "ai_tool": [
        [
          {
            "node": "Orchestrator",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Sentinel": {
      "ai_tool": [
        [
          {
            "node": "Orchestrator",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "from_crm": {
      "ai_tool": [
        [
          {
            "node": "Profiler_agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "For testing": {
      "main": [
        [
          {
            "node": "Get many tickets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Orchestrator": {
      "main": [
        [
          {
            "node": "generate ticket title",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search contacts": {
      "main": [
        [
          {
            "node": "Set the variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get many tickets": {
      "main": [
        [
          {
            "node": "Search contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Orchestrator",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Sentinel_agent",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Profiler_agent",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "generate ticket title",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Cateogory Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set the variables": {
      "main": [
        [
          {
            "node": "Orchestrator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cateogory Classifier": {
      "main": [
        [
          {
            "node": "Create an issue in Jira",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create an issue in Jira",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create an issue in Jira",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create an issue in Jira",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "generate ticket title": {
      "main": [
        [
          {
            "node": "Cateogory Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set the running interval": {
      "main": [
        [
          {
            "node": "Get many tickets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Orchestrator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}