<?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-parallelization" name="AI Parallel Guardrails" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0.0"/>
    </bpmn:extensionElements>
    <bpmn:startEvent id="reply-drafted" name="Reply drafted">
      <bpmn:outgoing>Flow_reply-drafted_fan-out</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:parallelGateway id="fan-out">
      <bpmn:incoming>Flow_reply-drafted_fan-out</bpmn:incoming>
      <bpmn:outgoing>Flow_fan-out_check-pii</bpmn:outgoing>
      <bpmn:outgoing>Flow_fan-out_check-policy</bpmn:outgoing>
      <bpmn:outgoing>Flow_fan-out_check-tone</bpmn:outgoing>
    </bpmn:parallelGateway>
    <bpmn:serviceTask id="check-pii" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Check for personal data">
      <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="Does the text reveal personal data? Reply with JSON: {&quot;flagged&quot;: boolean}." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=reply" 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.flagged" target="piiFlagged"/>
        </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_fan-out_check-pii</bpmn:incoming>
      <bpmn:outgoing>Flow_check-pii_fan-in</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="check-policy" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Check refund policy">
      <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="Does the text promise anything the refund policy forbids? Reply with JSON: {&quot;flagged&quot;: boolean}." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=reply" 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.flagged" target="policyFlagged"/>
        </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_fan-out_check-policy</bpmn:incoming>
      <bpmn:outgoing>Flow_check-policy_fan-in</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="check-tone" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Rate tone">
      <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="Rate the politeness of the text from 1 to 5. Reply with JSON: {&quot;score&quot;: number}." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=reply" 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.score" target="toneScore"/>
        </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_fan-out_check-tone</bpmn:incoming>
      <bpmn:outgoing>Flow_check-tone_fan-in</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:parallelGateway id="fan-in">
      <bpmn:incoming>Flow_check-pii_fan-in</bpmn:incoming>
      <bpmn:incoming>Flow_check-policy_fan-in</bpmn:incoming>
      <bpmn:incoming>Flow_check-tone_fan-in</bpmn:incoming>
      <bpmn:outgoing>Flow_fan-in_combine-votes</bpmn:outgoing>
    </bpmn:parallelGateway>
    <bpmn:scriptTask id="combine-votes" name="Combine votes">
      <bpmn:extensionElements>
        <zeebe:script expression="=piiFlagged or policyFlagged or toneScore &lt; 3" resultVariable="flagged"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_fan-in_combine-votes</bpmn:incoming>
      <bpmn:outgoing>Flow_combine-votes_flagged-gw</bpmn:outgoing>
    </bpmn:scriptTask>
    <bpmn:exclusiveGateway id="flagged-gw" name="Flagged?" default="Flow_flagged-gw_flagged-gw_join">
      <bpmn:incoming>Flow_combine-votes_flagged-gw</bpmn:incoming>
      <bpmn:outgoing>Flow_flagged-gw_human-review</bpmn:outgoing>
      <bpmn:outgoing>Flow_flagged-gw_flagged-gw_join</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:userTask id="human-review" name="Review flagged reply">
      <bpmn:extensionElements>
        <zeebe:userTask/>
        <zeebe:assignmentDefinition candidateGroups="support-leads"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_flagged-gw_human-review</bpmn:incoming>
      <bpmn:outgoing>Flow_human-review_flagged-gw_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_flagged-gw_join_send-reply</bpmn:incoming>
      <bpmn:outgoing>Flow_send-reply_reply-sent</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="reply-sent" name="Reply sent">
      <bpmn:incoming>Flow_send-reply_reply-sent</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:exclusiveGateway id="flagged-gw_join">
      <bpmn:incoming>Flow_human-review_flagged-gw_join</bpmn:incoming>
      <bpmn:incoming>Flow_flagged-gw_flagged-gw_join</bpmn:incoming>
      <bpmn:outgoing>Flow_flagged-gw_join_send-reply</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:sequenceFlow id="Flow_reply-drafted_fan-out" sourceRef="reply-drafted" targetRef="fan-out"/>
    <bpmn:sequenceFlow id="Flow_fan-out_check-pii" sourceRef="fan-out" targetRef="check-pii" name="pii"/>
    <bpmn:sequenceFlow id="Flow_fan-out_check-policy" sourceRef="fan-out" targetRef="check-policy" name="policy"/>
    <bpmn:sequenceFlow id="Flow_fan-out_check-tone" sourceRef="fan-out" targetRef="check-tone" name="tone"/>
    <bpmn:sequenceFlow id="Flow_check-pii_fan-in" sourceRef="check-pii" targetRef="fan-in"/>
    <bpmn:sequenceFlow id="Flow_check-policy_fan-in" sourceRef="check-policy" targetRef="fan-in"/>
    <bpmn:sequenceFlow id="Flow_check-tone_fan-in" sourceRef="check-tone" targetRef="fan-in"/>
    <bpmn:sequenceFlow id="Flow_fan-in_combine-votes" sourceRef="fan-in" targetRef="combine-votes"/>
    <bpmn:sequenceFlow id="Flow_combine-votes_flagged-gw" sourceRef="combine-votes" targetRef="flagged-gw"/>
    <bpmn:sequenceFlow id="Flow_flagged-gw_human-review" sourceRef="flagged-gw" targetRef="human-review" name="review">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=flagged</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_human-review_flagged-gw_join" sourceRef="human-review" targetRef="flagged-gw_join"/>
    <bpmn:sequenceFlow id="Flow_flagged-gw_flagged-gw_join" sourceRef="flagged-gw" targetRef="flagged-gw_join" name="clean"/>
    <bpmn:sequenceFlow id="Flow_send-reply_reply-sent" sourceRef="send-reply" targetRef="reply-sent"/>
    <bpmn:sequenceFlow id="Flow_flagged-gw_join_send-reply" sourceRef="flagged-gw_join" targetRef="send-reply"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="ai-parallelization_di">
    <bpmndi:BPMNPlane id="ai-parallelization_di_plane" bpmnElement="ai-parallelization">
      <bpmndi:BPMNShape id="reply-drafted_di" bpmnElement="reply-drafted">
        <dc:Bounds x="48" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="20" y="242" width="91" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="fan-out_di" bpmnElement="fan-out">
        <dc:Bounds x="184" y="195" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="check-pii_di" bpmnElement="check-pii">
        <dc:Bounds x="334" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="check-policy_di" bpmnElement="check-policy">
        <dc:Bounds x="334" y="340" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="check-tone_di" bpmnElement="check-tone">
        <dc:Bounds x="334" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="fan-in_di" bpmnElement="fan-in">
        <dc:Bounds x="534" y="195" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="combine-votes_di" bpmnElement="combine-votes">
        <dc:Bounds x="684" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="flagged-gw_di" bpmnElement="flagged-gw">
        <dc:Bounds x="884" y="195" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="881" y="249" width="56" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="human-review_di" bpmnElement="human-review">
        <dc:Bounds x="1034" y="340" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="send-reply_di" bpmnElement="send-reply">
        <dc:Bounds x="1384" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="reply-sent_di" bpmnElement="reply-sent">
        <dc:Bounds x="1584" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1567" y="242" width="70" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="flagged-gw_join_di" bpmnElement="flagged-gw_join">
        <dc:Bounds x="1234" y="195" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_reply-drafted_fan-out_di" bpmnElement="Flow_reply-drafted_fan-out">
        <di:waypoint x="84" y="220"/>
        <di:waypoint x="184" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_fan-out_check-pii_di" bpmnElement="Flow_fan-out_check-pii">
        <di:waypoint x="234" y="220"/>
        <di:waypoint x="334" y="220"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="264" y="196" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_fan-out_check-policy_di" bpmnElement="Flow_fan-out_check-policy">
        <di:waypoint x="209" y="245"/>
        <di:waypoint x="209" y="380"/>
        <di:waypoint x="334" y="380"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="185" y="306" width="42" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_fan-out_check-tone_di" bpmnElement="Flow_fan-out_check-tone">
        <di:waypoint x="209" y="195"/>
        <di:waypoint x="209" y="60"/>
        <di:waypoint x="334" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="185" y="121" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_check-pii_fan-in_di" bpmnElement="Flow_check-pii_fan-in">
        <di:waypoint x="434" y="220"/>
        <di:waypoint x="534" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_check-policy_fan-in_di" bpmnElement="Flow_check-policy_fan-in">
        <di:waypoint x="384" y="340"/>
        <di:waypoint x="384" y="300"/>
        <di:waypoint x="559" y="300"/>
        <di:waypoint x="559" y="245"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_check-tone_fan-in_di" bpmnElement="Flow_check-tone_fan-in">
        <di:waypoint x="384" y="100"/>
        <di:waypoint x="384" y="140"/>
        <di:waypoint x="559" y="140"/>
        <di:waypoint x="559" y="195"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_fan-in_combine-votes_di" bpmnElement="Flow_fan-in_combine-votes">
        <di:waypoint x="584" y="220"/>
        <di:waypoint x="684" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_combine-votes_flagged-gw_di" bpmnElement="Flow_combine-votes_flagged-gw">
        <di:waypoint x="784" y="220"/>
        <di:waypoint x="884" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_flagged-gw_human-review_di" bpmnElement="Flow_flagged-gw_human-review">
        <di:waypoint x="909" y="245"/>
        <di:waypoint x="909" y="380"/>
        <di:waypoint x="1034" y="380"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="885" y="306" width="42" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_human-review_flagged-gw_join_di" bpmnElement="Flow_human-review_flagged-gw_join">
        <di:waypoint x="1084" y="340"/>
        <di:waypoint x="1084" y="220"/>
        <di:waypoint x="1234" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_flagged-gw_flagged-gw_join_di" bpmnElement="Flow_flagged-gw_flagged-gw_join">
        <di:waypoint x="909" y="195"/>
        <di:waypoint x="909" y="155"/>
        <di:waypoint x="1259" y="155"/>
        <di:waypoint x="1259" y="195"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1064" y="131" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_send-reply_reply-sent_di" bpmnElement="Flow_send-reply_reply-sent">
        <di:waypoint x="1484" y="220"/>
        <di:waypoint x="1584" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_flagged-gw_join_send-reply_di" bpmnElement="Flow_flagged-gw_join_send-reply">
        <di:waypoint x="1284" y="220"/>
        <di:waypoint x="1384" y="220"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

