<?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-human-approval-gate" name="AI Proposal with Human Approval" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0.0"/>
    </bpmn:extensionElements>
    <bpmn:startEvent id="complaint-received" name="Complaint received">
      <bpmn:outgoing>Flow_complaint-received_propose-resolution</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="propose-resolution" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Propose resolution">
      <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 resolve customer complaints within policy. Reply with JSON: {&quot;action&quot;: &quot;refund&quot; | &quot;voucher&quot; | &quot;apology&quot;, &quot;amount&quot;: number, &quot;reason&quot;: string}." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=&quot;Complaint: &quot; + complaint + &quot;\nOrder total: &quot; + string(orderTotal)" 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" target="proposal"/>
        </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_complaint-received_propose-resolution</bpmn:incoming>
      <bpmn:outgoing>Flow_propose-resolution_needs-approval</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:exclusiveGateway id="needs-approval" name="Needs approval?" default="Flow_needs-approval_approve-proposal">
      <bpmn:incoming>Flow_propose-resolution_needs-approval</bpmn:incoming>
      <bpmn:outgoing>Flow_needs-approval_execute-merge</bpmn:outgoing>
      <bpmn:outgoing>Flow_needs-approval_approve-proposal</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:userTask id="approve-proposal" name="Approve AI proposal">
      <bpmn:extensionElements>
        <zeebe:userTask/>
        <zeebe:assignmentDefinition candidateGroups="support-leads"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_needs-approval_approve-proposal</bpmn:incoming>
      <bpmn:outgoing>Flow_approve-proposal_approved</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:exclusiveGateway id="approved" name="Approved?" default="Flow_approved_handoff">
      <bpmn:incoming>Flow_approve-proposal_approved</bpmn:incoming>
      <bpmn:outgoing>Flow_approved_execute-merge</bpmn:outgoing>
      <bpmn:outgoing>Flow_approved_handoff</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="handoff" name="Hand off to a human agent">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="helpdesk-ticket-assign"/>
        <zeebe:taskHeaders>
          <zeebe:header key="queue" value="complaints"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_approved_handoff</bpmn:incoming>
      <bpmn:outgoing>Flow_handoff_handed-off</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="handed-off" name="Handed off">
      <bpmn:incoming>Flow_handoff_handed-off</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:exclusiveGateway id="execute-merge">
      <bpmn:incoming>Flow_needs-approval_execute-merge</bpmn:incoming>
      <bpmn:incoming>Flow_approved_execute-merge</bpmn:incoming>
      <bpmn:outgoing>Flow_execute-merge_execute-resolution</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="execute-resolution" name="Execute resolution">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="resolution-execute"/>
        <zeebe:ioMapping>
          <zeebe:input source="=proposal.action" target="resolutionAction"/>
          <zeebe:input source="=proposal.amount" target="resolutionAmount"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_execute-merge_execute-resolution</bpmn:incoming>
      <bpmn:outgoing>Flow_execute-resolution_reply-customer</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="reply-customer" name="Reply to customer">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="email-send"/>
        <zeebe:ioMapping>
          <zeebe:input source="=proposal.reason" target="body"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_execute-resolution_reply-customer</bpmn:incoming>
      <bpmn:outgoing>Flow_reply-customer_resolved</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="resolved" name="Resolved">
      <bpmn:incoming>Flow_reply-customer_resolved</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_complaint-received_propose-resolution" sourceRef="complaint-received" targetRef="propose-resolution"/>
    <bpmn:sequenceFlow id="Flow_propose-resolution_needs-approval" sourceRef="propose-resolution" targetRef="needs-approval"/>
    <bpmn:sequenceFlow id="Flow_needs-approval_execute-merge" sourceRef="needs-approval" targetRef="execute-merge" name="auto">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=proposal.action != "refund" or proposal.amount &lt;= 100</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_needs-approval_approve-proposal" sourceRef="needs-approval" targetRef="approve-proposal" name="approve"/>
    <bpmn:sequenceFlow id="Flow_approve-proposal_approved" sourceRef="approve-proposal" targetRef="approved"/>
    <bpmn:sequenceFlow id="Flow_approved_execute-merge" sourceRef="approved" targetRef="execute-merge" name="yes">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=proposalApproved</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_approved_handoff" sourceRef="approved" targetRef="handoff" name="no"/>
    <bpmn:sequenceFlow id="Flow_handoff_handed-off" sourceRef="handoff" targetRef="handed-off"/>
    <bpmn:sequenceFlow id="Flow_execute-merge_execute-resolution" sourceRef="execute-merge" targetRef="execute-resolution"/>
    <bpmn:sequenceFlow id="Flow_execute-resolution_reply-customer" sourceRef="execute-resolution" targetRef="reply-customer"/>
    <bpmn:sequenceFlow id="Flow_reply-customer_resolved" sourceRef="reply-customer" targetRef="resolved"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="ai-human-approval-gate_di">
    <bpmndi:BPMNPlane id="ai-human-approval-gate_di_plane" bpmnElement="ai-human-approval-gate">
      <bpmndi:BPMNShape id="complaint-received_di" bpmnElement="complaint-received">
        <dc:Bounds x="65" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="20" y="82" width="126" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="propose-resolution_di" bpmnElement="propose-resolution">
        <dc:Bounds x="201" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="needs-approval_di" bpmnElement="needs-approval">
        <dc:Bounds x="401" y="35" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="374" y="89" width="105" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="approve-proposal_di" bpmnElement="approve-proposal">
        <dc:Bounds x="551" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="approved_di" bpmnElement="approved">
        <dc:Bounds x="751" y="35" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="745" y="89" width="63" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="handoff_di" bpmnElement="handoff">
        <dc:Bounds x="901" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="handed-off_di" bpmnElement="handed-off">
        <dc:Bounds x="1133" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1116" y="82" width="70" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="execute-merge_di" bpmnElement="execute-merge">
        <dc:Bounds x="926" y="195" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="execute-resolution_di" bpmnElement="execute-resolution">
        <dc:Bounds x="1101" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="reply-customer_di" bpmnElement="reply-customer">
        <dc:Bounds x="1301" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="resolved_di" bpmnElement="resolved">
        <dc:Bounds x="1501" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1491" y="242" width="56" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_complaint-received_propose-resolution_di" bpmnElement="Flow_complaint-received_propose-resolution">
        <di:waypoint x="101" y="60"/>
        <di:waypoint x="201" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_propose-resolution_needs-approval_di" bpmnElement="Flow_propose-resolution_needs-approval">
        <di:waypoint x="301" y="60"/>
        <di:waypoint x="401" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_needs-approval_execute-merge_di" bpmnElement="Flow_needs-approval_execute-merge">
        <di:waypoint x="426" y="85"/>
        <di:waypoint x="426" y="220"/>
        <di:waypoint x="926" y="220"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="656" y="196" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_needs-approval_approve-proposal_di" bpmnElement="Flow_needs-approval_approve-proposal">
        <di:waypoint x="451" y="60"/>
        <di:waypoint x="551" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="477" y="36" width="49" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_approve-proposal_approved_di" bpmnElement="Flow_approve-proposal_approved">
        <di:waypoint x="651" y="60"/>
        <di:waypoint x="751" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_approved_execute-merge_di" bpmnElement="Flow_approved_execute-merge">
        <di:waypoint x="776" y="85"/>
        <di:waypoint x="776" y="148"/>
        <di:waypoint x="951" y="148"/>
        <di:waypoint x="951" y="195"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="844" y="124" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_approved_handoff_di" bpmnElement="Flow_approved_handoff">
        <di:waypoint x="801" y="60"/>
        <di:waypoint x="901" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="831" y="36" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_handoff_handed-off_di" bpmnElement="Flow_handoff_handed-off">
        <di:waypoint x="1001" y="60"/>
        <di:waypoint x="1133" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_execute-merge_execute-resolution_di" bpmnElement="Flow_execute-merge_execute-resolution">
        <di:waypoint x="976" y="220"/>
        <di:waypoint x="1101" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_execute-resolution_reply-customer_di" bpmnElement="Flow_execute-resolution_reply-customer">
        <di:waypoint x="1201" y="220"/>
        <di:waypoint x="1301" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_reply-customer_resolved_di" bpmnElement="Flow_reply-customer_resolved">
        <di:waypoint x="1401" y="220"/>
        <di:waypoint x="1501" y="220"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

