{
  "name": "Lead Scoring + KG Storage",
  "goal": "Score a batch of leads against ICP criteria and persist results to the Knowledge Graph.",
  "description": "Pattern 09 (KG-storage). Replace the scoring prompt, ICP criteria, and list keys for your workspace.",
  "status": "draft",
  "context": {
    "executionInputConfig": {
      "title": "Score Leads",
      "description": "Source list of leads to score.",
      "runCTALabel": "Run",
      "fields": [
        { "name": "source_list_key", "label": "Source list key", "type": "text", "required": true },
        { "name": "target_list_key", "label": "Target list (scored results)", "type": "text", "required": true }
      ]
    }
  },
  "steps": [
    {
      "id": "start",
      "type": "trigger",
      "name": "Manual Start",
      "pipelineStepStartConditions": { "trigger": { "type": "manual" } },
      "next": { "stepId": "read-leads" }
    },
    {
      "id": "read-leads",
      "type": "appAction",
      "name": "Read Leads",
      "app": { "id": "kg", "actionId": "kg.read-list", "source": "native" },
      "stepInputData": {
        "listKey": "{{input.source_list_key}}",
        "limit": "500"
      },
      "next": { "stepId": "score" }
    },
    {
      "id": "score",
      "type": "aiAction",
      "name": "Score Lead",
      "loopConfig": {
        "source": "executionContent",
        "config": { "stepId": "read-leads", "field": "listEntries" },
        "ItemAlias": "lead"
      },
      "pipelineStepPrompt": {
        "template": "Score this lead against the ICP. Return a structured result.\n\nLead: {{lead}}\n\nReturn: fit_score (0-100), decision (one of: qualify, nurture, reject), reason (short).",
        "responseStructure": {
          "fit_score": "number (0-100)",
          "decision": "string (qualify | nurture | reject)",
          "reason": "string"
        }
      },
      "creditCost": 8,
      "next": { "stepId": "sync-scores" }
    },
    {
      "id": "sync-scores",
      "type": "knowledgeSync",
      "name": "Save Scores to KG",
      "entryConditions": {
        "onCriteriaFail": "wait",
        "conditionText": "Wait for all scoring calls to complete.",
        "criteria": [
          { "type": "loop_completion", "stepId": "score", "operator": "==", "value": true }
        ]
      },
      "knowledgeSync": {
        "source": { "stepId": "score", "resultsPath": "items" },
        "listKey": "{{input.target_list_key}}",
        "fieldMapping": {
          "fit_score": "fit_score",
          "decision": "decision",
          "reason": "reason"
        }
      },
      "next": { "stepId": "done" }
    },
    {
      "id": "done",
      "type": "milestone",
      "name": "Done"
    }
  ]
}
