<?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-prompt-chaining" name="AI Prompt Chaining" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0.0"/>
    </bpmn:extensionElements>
    <bpmn:startEvent id="brief-received" name="Brief received">
      <bpmn:outgoing>Flow_brief-received_write-outline</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="write-outline" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Write outline">
      <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 plan technical articles. Reply with a numbered outline only." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=&quot;Outline an article for this brief:\n&quot; + brief" 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="outline"/>
        </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_brief-received_write-outline</bpmn:incoming>
      <bpmn:outgoing>Flow_write-outline_check-outline</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:scriptTask id="check-outline" name="Check outline">
      <bpmn:extensionElements>
        <zeebe:script expression="=string length(outline) >= 40 and contains(outline, &quot;1.&quot;)" resultVariable="outlineOk"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_write-outline_check-outline</bpmn:incoming>
      <bpmn:outgoing>Flow_check-outline_gate</bpmn:outgoing>
    </bpmn:scriptTask>
    <bpmn:exclusiveGateway id="gate" name="Outline passes?" default="Flow_gate_return-brief">
      <bpmn:incoming>Flow_check-outline_gate</bpmn:incoming>
      <bpmn:outgoing>Flow_gate_write-draft</bpmn:outgoing>
      <bpmn:outgoing>Flow_gate_return-brief</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="write-draft" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Write draft">
      <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 write clear technical articles from an outline." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=&quot;Write the article for this outline:\n&quot; + outline" 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="draft"/>
        </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_gate_write-draft</bpmn:incoming>
      <bpmn:outgoing>Flow_write-draft_edit-draft</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="edit-draft" zeebe:modelerTemplate="io.camunda.connectors.agenticai.aiagent.v1" zeebe:modelerTemplateVersion="1" name="Edit for tone and length">
      <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 copy editor. Tighten the text; keep the facts." target="data.systemPrompt.prompt"/>
          <zeebe:input source="=draft" 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="article"/>
        </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_write-draft_edit-draft</bpmn:incoming>
      <bpmn:outgoing>Flow_edit-draft_publish-article</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="publish-article" name="Save to CMS as draft">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="cms-draft-save"/>
        <zeebe:ioMapping>
          <zeebe:output source="=url" target="articleUrl"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_edit-draft_publish-article</bpmn:incoming>
      <bpmn:outgoing>Flow_publish-article_article-ready</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="article-ready" name="Article ready">
      <bpmn:incoming>Flow_publish-article_article-ready</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:serviceTask id="return-brief" name="Return brief to requester">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="requester-notify"/>
        <zeebe:taskHeaders>
          <zeebe:header key="template" value="brief-unclear"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_gate_return-brief</bpmn:incoming>
      <bpmn:outgoing>Flow_return-brief_brief-returned</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="brief-returned" name="Brief returned">
      <bpmn:incoming>Flow_return-brief_brief-returned</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_brief-received_write-outline" sourceRef="brief-received" targetRef="write-outline"/>
    <bpmn:sequenceFlow id="Flow_write-outline_check-outline" sourceRef="write-outline" targetRef="check-outline"/>
    <bpmn:sequenceFlow id="Flow_check-outline_gate" sourceRef="check-outline" targetRef="gate"/>
    <bpmn:sequenceFlow id="Flow_gate_write-draft" sourceRef="gate" targetRef="write-draft" name="pass">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=outlineOk</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_write-draft_edit-draft" sourceRef="write-draft" targetRef="edit-draft"/>
    <bpmn:sequenceFlow id="Flow_edit-draft_publish-article" sourceRef="edit-draft" targetRef="publish-article"/>
    <bpmn:sequenceFlow id="Flow_publish-article_article-ready" sourceRef="publish-article" targetRef="article-ready"/>
    <bpmn:sequenceFlow id="Flow_gate_return-brief" sourceRef="gate" targetRef="return-brief" name="fail"/>
    <bpmn:sequenceFlow id="Flow_return-brief_brief-returned" sourceRef="return-brief" targetRef="brief-returned"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="ai-prompt-chaining_di">
    <bpmndi:BPMNPlane id="ai-prompt-chaining_di_plane" bpmnElement="ai-prompt-chaining">
      <bpmndi:BPMNShape id="brief-received_di" bpmnElement="brief-received">
        <dc:Bounds x="51" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="20" y="82" width="98" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="write-outline_di" bpmnElement="write-outline">
        <dc:Bounds x="187" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="check-outline_di" bpmnElement="check-outline">
        <dc:Bounds x="387" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="gate_di" bpmnElement="gate">
        <dc:Bounds x="587" y="35" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="560" y="89" width="105" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="write-draft_di" bpmnElement="write-draft">
        <dc:Bounds x="737" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="edit-draft_di" bpmnElement="edit-draft">
        <dc:Bounds x="937" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="publish-article_di" bpmnElement="publish-article">
        <dc:Bounds x="1137" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="article-ready_di" bpmnElement="article-ready">
        <dc:Bounds x="1337" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1310" y="242" width="91" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="return-brief_di" bpmnElement="return-brief">
        <dc:Bounds x="737" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="brief-returned_di" bpmnElement="brief-returned">
        <dc:Bounds x="969" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="938" y="82" width="98" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_brief-received_write-outline_di" bpmnElement="Flow_brief-received_write-outline">
        <di:waypoint x="87" y="60"/>
        <di:waypoint x="187" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_write-outline_check-outline_di" bpmnElement="Flow_write-outline_check-outline">
        <di:waypoint x="287" y="60"/>
        <di:waypoint x="387" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_check-outline_gate_di" bpmnElement="Flow_check-outline_gate">
        <di:waypoint x="487" y="60"/>
        <di:waypoint x="587" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_gate_write-draft_di" bpmnElement="Flow_gate_write-draft">
        <di:waypoint x="612" y="85"/>
        <di:waypoint x="612" y="220"/>
        <di:waypoint x="737" y="220"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="588" y="146" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_write-draft_edit-draft_di" bpmnElement="Flow_write-draft_edit-draft">
        <di:waypoint x="837" y="220"/>
        <di:waypoint x="937" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_edit-draft_publish-article_di" bpmnElement="Flow_edit-draft_publish-article">
        <di:waypoint x="1037" y="220"/>
        <di:waypoint x="1137" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_publish-article_article-ready_di" bpmnElement="Flow_publish-article_article-ready">
        <di:waypoint x="1237" y="220"/>
        <di:waypoint x="1337" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_gate_return-brief_di" bpmnElement="Flow_gate_return-brief">
        <di:waypoint x="637" y="60"/>
        <di:waypoint x="737" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="667" y="36" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_return-brief_brief-returned_di" bpmnElement="Flow_return-brief_brief-returned">
        <di:waypoint x="837" y="60"/>
        <di:waypoint x="969" y="60"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

