<?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="document-classification" name="AI Document Classification" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0.0"/>
    </bpmn:extensionElements>
    <bpmn:startEvent id="document-uploaded" name="Document uploaded">
      <bpmn:outgoing>Flow_document-uploaded_classify-document</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="classify-document" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Classify document">
      <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 business documents. Reply with JSON: {&quot;type&quot;: &quot;invoice&quot; | &quot;contract&quot; | &quot;other&quot;, &quot;confidence&quot;: number between 0 and 1}." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=&quot;Document text:\n&quot; + documentText" 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.type" target="documentType"/>
          <zeebe:output source="=agent.responseJson.confidence" target="classificationConfidence"/>
        </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_document-uploaded_classify-document</bpmn:incoming>
      <bpmn:outgoing>Flow_classify-document_route</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:exclusiveGateway id="route" name="Document type?" default="Flow_route_classify-manually">
      <bpmn:incoming>Flow_classify-document_route</bpmn:incoming>
      <bpmn:outgoing>Flow_route_route-to-ap</bpmn:outgoing>
      <bpmn:outgoing>Flow_route_route-to-legal</bpmn:outgoing>
      <bpmn:outgoing>Flow_route_classify-manually</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="route-to-ap" name="Route to accounts payable">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="dms-route"/>
        <zeebe:taskHeaders>
          <zeebe:header key="queue" value="accounts-payable"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_route_route-to-ap</bpmn:incoming>
      <bpmn:outgoing>Flow_route-to-ap_filed-invoice</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="filed-invoice" name="Filed as invoice">
      <bpmn:incoming>Flow_route-to-ap_filed-invoice</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:serviceTask id="route-to-legal" name="Route to legal">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="dms-route"/>
        <zeebe:taskHeaders>
          <zeebe:header key="queue" value="legal"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_route_route-to-legal</bpmn:incoming>
      <bpmn:outgoing>Flow_route-to-legal_filed-contract</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="filed-contract" name="Filed as contract">
      <bpmn:incoming>Flow_route-to-legal_filed-contract</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:userTask id="classify-manually" name="Classify manually">
      <bpmn:extensionElements>
        <zeebe:userTask/>
        <zeebe:assignmentDefinition candidateGroups="records"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_route_classify-manually</bpmn:incoming>
      <bpmn:outgoing>Flow_classify-manually_filed-manually</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:endEvent id="filed-manually" name="Filed by hand">
      <bpmn:incoming>Flow_classify-manually_filed-manually</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_document-uploaded_classify-document" sourceRef="document-uploaded" targetRef="classify-document"/>
    <bpmn:sequenceFlow id="Flow_classify-document_route" sourceRef="classify-document" targetRef="route"/>
    <bpmn:sequenceFlow id="Flow_route_route-to-ap" sourceRef="route" targetRef="route-to-ap" name="invoice">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=documentType = "invoice" and classificationConfidence &gt;= 0.8</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_route-to-ap_filed-invoice" sourceRef="route-to-ap" targetRef="filed-invoice"/>
    <bpmn:sequenceFlow id="Flow_route_route-to-legal" sourceRef="route" targetRef="route-to-legal" name="contract">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=documentType = "contract" and classificationConfidence &gt;= 0.8</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_route-to-legal_filed-contract" sourceRef="route-to-legal" targetRef="filed-contract"/>
    <bpmn:sequenceFlow id="Flow_route_classify-manually" sourceRef="route" targetRef="classify-manually" name="unsure"/>
    <bpmn:sequenceFlow id="Flow_classify-manually_filed-manually" sourceRef="classify-manually" targetRef="filed-manually"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="document-classification_di">
    <bpmndi:BPMNPlane id="document-classification_di_plane" bpmnElement="document-classification">
      <bpmndi:BPMNShape id="document-uploaded_di" bpmnElement="document-uploaded">
        <dc:Bounds x="62" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="20" y="242" width="119" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="classify-document_di" bpmnElement="classify-document">
        <dc:Bounds x="198" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="route_di" bpmnElement="route">
        <dc:Bounds x="398" y="195" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="374" y="249" width="98" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="route-to-ap_di" bpmnElement="route-to-ap">
        <dc:Bounds x="548" y="340" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="filed-invoice_di" bpmnElement="filed-invoice">
        <dc:Bounds x="748" y="362" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="710" y="402" width="112" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="route-to-legal_di" bpmnElement="route-to-legal">
        <dc:Bounds x="548" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="filed-contract_di" bpmnElement="filed-contract">
        <dc:Bounds x="748" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="706" y="82" width="119" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="classify-manually_di" bpmnElement="classify-manually">
        <dc:Bounds x="548" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="filed-manually_di" bpmnElement="filed-manually">
        <dc:Bounds x="748" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="720" y="242" width="91" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_document-uploaded_classify-document_di" bpmnElement="Flow_document-uploaded_classify-document">
        <di:waypoint x="98" y="220"/>
        <di:waypoint x="198" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_classify-document_route_di" bpmnElement="Flow_classify-document_route">
        <di:waypoint x="298" y="220"/>
        <di:waypoint x="398" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route_route-to-ap_di" bpmnElement="Flow_route_route-to-ap">
        <di:waypoint x="423" y="245"/>
        <di:waypoint x="423" y="380"/>
        <di:waypoint x="548" y="380"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="399" y="306" width="49" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route-to-ap_filed-invoice_di" bpmnElement="Flow_route-to-ap_filed-invoice">
        <di:waypoint x="648" y="380"/>
        <di:waypoint x="748" y="380"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route_route-to-legal_di" bpmnElement="Flow_route_route-to-legal">
        <di:waypoint x="423" y="195"/>
        <di:waypoint x="423" y="60"/>
        <di:waypoint x="548" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="399" y="121" width="56" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route-to-legal_filed-contract_di" bpmnElement="Flow_route-to-legal_filed-contract">
        <di:waypoint x="648" y="60"/>
        <di:waypoint x="748" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route_classify-manually_di" bpmnElement="Flow_route_classify-manually">
        <di:waypoint x="448" y="220"/>
        <di:waypoint x="548" y="220"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="477" y="196" width="42" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_classify-manually_filed-manually_di" bpmnElement="Flow_classify-manually_filed-manually">
        <di:waypoint x="648" y="220"/>
        <di:waypoint x="748" y="220"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

