<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="@bpmnkit/core" exporterVersion="0.0.23" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.9.0">
  <bpmn:process id="ai-routing" name="AI Routing" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0.0"/>
    </bpmn:extensionElements>
    <bpmn:startEvent id="message-received" name="Support message received">
      <bpmn:outgoing>Flow_message-received_classify</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="classify" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Classify request">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="io.camunda.agenticai:aiagent:1"/>
        <zeebe:ioMapping>
          <zeebe:input source="anthropic" target="provider.type"/>
          <zeebe:input source="{{secrets.ANTHROPIC_API_KEY}}" target="provider.anthropic.authentication.apiKey"/>
          <zeebe:input source="claude-sonnet-4-5" target="provider.anthropic.model.model"/>
          <zeebe:input source="Classify support messages. Reply with JSON: {&quot;category&quot;: &quot;billing&quot; | &quot;technical&quot; | &quot;other&quot;}." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=message" target="data.userPrompt.prompt"/>
          <zeebe:input source="in-process" target="data.memory.storage.type"/>
          <zeebe:input source="5" target="data.limits.maxModelCalls"/>
          <zeebe:input source="json" target="data.response.format.type"/>
          <zeebe:input source="=true" target="data.response.format.parseJson"/>
          <zeebe:output source="=agent.responseJson.category" target="category"/>
        </zeebe:ioMapping>
        <zeebe:taskHeaders>
          <zeebe:header key="elementTemplateVersion" value="1"/>
          <zeebe:header key="elementTemplateId" value="io.camunda.connectors.agenticai.aiagent.v1"/>
          <zeebe:header key="resultVariable" value="agent"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_message-received_classify</bpmn:incoming>
      <bpmn:outgoing>Flow_classify_route</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:exclusiveGateway id="route" name="Category?" default="Flow_route_answer-manually">
      <bpmn:incoming>Flow_classify_route</bpmn:incoming>
      <bpmn:outgoing>Flow_route_lookup-invoice</bpmn:outgoing>
      <bpmn:outgoing>Flow_route_draft-technical-reply</bpmn:outgoing>
      <bpmn:outgoing>Flow_route_answer-manually</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="lookup-invoice" name="Look up invoice">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="billing-invoice-lookup"/>
        <zeebe:ioMapping>
          <zeebe:output source="=invoice" target="invoice"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_route_lookup-invoice</bpmn:incoming>
      <bpmn:outgoing>Flow_lookup-invoice_draft-billing-reply</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="draft-billing-reply" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Draft billing reply">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="io.camunda.agenticai:aiagent:1"/>
        <zeebe:ioMapping>
          <zeebe:input source="anthropic" target="provider.type"/>
          <zeebe:input source="{{secrets.ANTHROPIC_API_KEY}}" target="provider.anthropic.authentication.apiKey"/>
          <zeebe:input source="claude-sonnet-4-5" target="provider.anthropic.model.model"/>
          <zeebe:input source="You answer billing questions using only the invoice data given." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=&quot;Question: &quot; + message + &quot;\nInvoice: &quot; + string(invoice)" target="data.userPrompt.prompt"/>
          <zeebe:input source="in-process" target="data.memory.storage.type"/>
          <zeebe:input source="5" target="data.limits.maxModelCalls"/>
          <zeebe:input source="text" target="data.response.format.type"/>
          <zeebe:output source="=agent.responseText" target="reply"/>
        </zeebe:ioMapping>
        <zeebe:taskHeaders>
          <zeebe:header key="elementTemplateVersion" value="1"/>
          <zeebe:header key="elementTemplateId" value="io.camunda.connectors.agenticai.aiagent.v1"/>
          <zeebe:header key="resultVariable" value="agent"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_lookup-invoice_draft-billing-reply</bpmn:incoming>
      <bpmn:outgoing>Flow_draft-billing-reply_route_join</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="draft-technical-reply" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Draft troubleshooting reply">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="io.camunda.agenticai:aiagent:1"/>
        <zeebe:ioMapping>
          <zeebe:input source="anthropic" target="provider.type"/>
          <zeebe:input source="{{secrets.ANTHROPIC_API_KEY}}" target="provider.anthropic.authentication.apiKey"/>
          <zeebe:input source="claude-sonnet-4-5" target="provider.anthropic.model.model"/>
          <zeebe:input source="You are a support engineer. Give numbered troubleshooting steps." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=message" target="data.userPrompt.prompt"/>
          <zeebe:input source="in-process" target="data.memory.storage.type"/>
          <zeebe:input source="5" target="data.limits.maxModelCalls"/>
          <zeebe:input source="text" target="data.response.format.type"/>
          <zeebe:output source="=agent.responseText" target="reply"/>
        </zeebe:ioMapping>
        <zeebe:taskHeaders>
          <zeebe:header key="elementTemplateVersion" value="1"/>
          <zeebe:header key="elementTemplateId" value="io.camunda.connectors.agenticai.aiagent.v1"/>
          <zeebe:header key="resultVariable" value="agent"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_route_draft-technical-reply</bpmn:incoming>
      <bpmn:outgoing>Flow_draft-technical-reply_route_join</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:userTask id="answer-manually" name="Answer manually">
      <bpmn:extensionElements>
        <zeebe:userTask/>
        <zeebe:assignmentDefinition candidateGroups="support"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_route_answer-manually</bpmn:incoming>
      <bpmn:outgoing>Flow_answer-manually_route_join</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:serviceTask id="send-reply" name="Send reply">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="email-send"/>
        <zeebe:ioMapping>
          <zeebe:input source="=reply" target="body"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_route_join_send-reply</bpmn:incoming>
      <bpmn:outgoing>Flow_send-reply_replied</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="replied" name="Replied">
      <bpmn:incoming>Flow_send-reply_replied</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:exclusiveGateway id="route_join">
      <bpmn:incoming>Flow_draft-billing-reply_route_join</bpmn:incoming>
      <bpmn:incoming>Flow_draft-technical-reply_route_join</bpmn:incoming>
      <bpmn:incoming>Flow_answer-manually_route_join</bpmn:incoming>
      <bpmn:outgoing>Flow_route_join_send-reply</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:sequenceFlow id="Flow_message-received_classify" sourceRef="message-received" targetRef="classify"/>
    <bpmn:sequenceFlow id="Flow_classify_route" sourceRef="classify" targetRef="route"/>
    <bpmn:sequenceFlow id="Flow_route_lookup-invoice" sourceRef="route" targetRef="lookup-invoice" name="billing">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=category = "billing"</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_lookup-invoice_draft-billing-reply" sourceRef="lookup-invoice" targetRef="draft-billing-reply"/>
    <bpmn:sequenceFlow id="Flow_draft-billing-reply_route_join" sourceRef="draft-billing-reply" targetRef="route_join"/>
    <bpmn:sequenceFlow id="Flow_route_draft-technical-reply" sourceRef="route" targetRef="draft-technical-reply" name="technical">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=category = "technical"</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_draft-technical-reply_route_join" sourceRef="draft-technical-reply" targetRef="route_join"/>
    <bpmn:sequenceFlow id="Flow_route_answer-manually" sourceRef="route" targetRef="answer-manually" name="other"/>
    <bpmn:sequenceFlow id="Flow_answer-manually_route_join" sourceRef="answer-manually" targetRef="route_join"/>
    <bpmn:sequenceFlow id="Flow_send-reply_replied" sourceRef="send-reply" targetRef="replied"/>
    <bpmn:sequenceFlow id="Flow_route_join_send-reply" sourceRef="route_join" targetRef="send-reply"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="ai-routing_di">
    <bpmndi:BPMNPlane id="ai-routing_di_plane" bpmnElement="ai-routing">
      <bpmndi:BPMNShape id="message-received_di" bpmnElement="message-received">
        <dc:Bounds x="86" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="20" y="242" width="168" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="classify_di" bpmnElement="classify">
        <dc:Bounds x="222" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="route_di" bpmnElement="route">
        <dc:Bounds x="422" y="195" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="416" y="249" width="63" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="lookup-invoice_di" bpmnElement="lookup-invoice">
        <dc:Bounds x="572" y="340" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="draft-billing-reply_di" bpmnElement="draft-billing-reply">
        <dc:Bounds x="772" y="340" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="draft-technical-reply_di" bpmnElement="draft-technical-reply">
        <dc:Bounds x="572" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="answer-manually_di" bpmnElement="answer-manually">
        <dc:Bounds x="572" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="send-reply_di" bpmnElement="send-reply">
        <dc:Bounds x="1122" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="replied_di" bpmnElement="replied">
        <dc:Bounds x="1322" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1316" y="242" width="49" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="route_join_di" bpmnElement="route_join">
        <dc:Bounds x="972" y="195" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_message-received_classify_di" bpmnElement="Flow_message-received_classify">
        <di:waypoint x="122" y="220"/>
        <di:waypoint x="222" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_classify_route_di" bpmnElement="Flow_classify_route">
        <di:waypoint x="322" y="220"/>
        <di:waypoint x="422" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route_lookup-invoice_di" bpmnElement="Flow_route_lookup-invoice">
        <di:waypoint x="447" y="245"/>
        <di:waypoint x="447" y="380"/>
        <di:waypoint x="572" y="380"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="423" y="306" width="49" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_lookup-invoice_draft-billing-reply_di" bpmnElement="Flow_lookup-invoice_draft-billing-reply">
        <di:waypoint x="672" y="380"/>
        <di:waypoint x="772" y="380"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_draft-billing-reply_route_join_di" bpmnElement="Flow_draft-billing-reply_route_join">
        <di:waypoint x="822" y="340"/>
        <di:waypoint x="822" y="220"/>
        <di:waypoint x="972" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route_draft-technical-reply_di" bpmnElement="Flow_route_draft-technical-reply">
        <di:waypoint x="447" y="195"/>
        <di:waypoint x="447" y="60"/>
        <di:waypoint x="572" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="423" y="121" width="63" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_draft-technical-reply_route_join_di" bpmnElement="Flow_draft-technical-reply_route_join">
        <di:waypoint x="622" y="100"/>
        <di:waypoint x="622" y="140"/>
        <di:waypoint x="997" y="140"/>
        <di:waypoint x="997" y="195"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route_answer-manually_di" bpmnElement="Flow_route_answer-manually">
        <di:waypoint x="472" y="220"/>
        <di:waypoint x="572" y="220"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="502" y="196" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_answer-manually_route_join_di" bpmnElement="Flow_answer-manually_route_join">
        <di:waypoint x="672" y="220"/>
        <di:waypoint x="972" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_send-reply_replied_di" bpmnElement="Flow_send-reply_replied">
        <di:waypoint x="1222" y="220"/>
        <di:waypoint x="1322" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route_join_send-reply_di" bpmnElement="Flow_route_join_send-reply">
        <di:waypoint x="1022" y="220"/>
        <di:waypoint x="1122" y="220"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

