{
  "research": {
    "v": 2,
    "name": "Explore a research question",
    "schemas": {
      "Input": {
        "type": "object",
        "properties": {
          "question": {
            "type": "string"
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "question",
          "sources"
        ],
        "additionalProperties": false
      },
      "Record": {
        "type": "object"
      },
      "AngleResult": {
        "type": "object",
        "properties": {
          "angle": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "gap": {
            "type": "boolean"
          }
        },
        "required": [
          "angle",
          "question",
          "records",
          "gap"
        ],
        "additionalProperties": false
      },
      "ResearchFollowup": {
        "type": "object",
        "properties": {
          "angle": {
            "type": "string"
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "resolved": {
            "type": "boolean"
          }
        },
        "required": [
          "angle",
          "records",
          "resolved"
        ],
        "additionalProperties": false
      },
      "EntityDiscovery": {
        "type": "object",
        "properties": {
          "entities": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "recordType": {
                  "type": "string"
                },
                "sourceId": {
                  "type": "string"
                },
                "role": {
                  "type": "string"
                },
                "relatedTo": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "name",
                "recordType",
                "sourceId",
                "role",
                "relatedTo"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "entities"
        ],
        "additionalProperties": false
      },
      "EntityResult": {
        "type": "object",
        "properties": {
          "entity": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "recordType": {
                "type": "string"
              },
              "sourceId": {
                "type": "string"
              },
              "role": {
                "type": "string"
              },
              "relatedTo": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "name",
              "recordType",
              "sourceId",
              "role",
              "relatedTo"
            ],
            "additionalProperties": false
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "complete": {
            "type": "boolean"
          }
        },
        "required": [
          "entity",
          "records",
          "complete"
        ],
        "additionalProperties": false
      },
      "SourceDiscovery": {
        "type": "object",
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "records"
        ],
        "additionalProperties": false
      },
      "NewsSearch": {
        "type": "object",
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text",
                "name",
                "birthYear",
                "location",
                "role"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "birthYear": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "location": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "role": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "phase": {
                  "type": "string"
                },
                "channel": {
                  "type": "string"
                },
                "identity": {
                  "type": "string"
                },
                "identityEvidence": {
                  "type": "object",
                  "required": [
                    "id",
                    "text"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "text": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": true
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "records"
        ],
        "additionalProperties": false
      },
      "Article": {
        "type": "object",
        "required": [
          "id",
          "text",
          "name",
          "birthYear",
          "location",
          "role"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "birthYear": {
            "type": [
              "integer",
              "null"
            ]
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "role": {
            "type": [
              "string",
              "null"
            ]
          },
          "phase": {
            "type": "string"
          },
          "channel": {
            "type": "string"
          },
          "identity": {
            "type": "string"
          },
          "identityEvidence": {
            "type": "object",
            "required": [
              "id",
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string"
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "ActivityEvidence": {
        "type": "object",
        "properties": {
          "source": {
            "type": "object",
            "required": [
              "id",
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string"
              }
            },
            "additionalProperties": true
          },
          "activity": {
            "type": [
              "string",
              "null"
            ]
          },
          "establishesPrincipal": {
            "type": "boolean"
          },
          "identityMatches": {
            "type": "boolean"
          }
        },
        "required": [
          "source",
          "activity",
          "establishesPrincipal",
          "identityMatches"
        ],
        "additionalProperties": false
      },
      "CandidateClasses": {
        "type": "object",
        "properties": {
          "alternatives": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "supported": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "missing": {
            "type": "boolean"
          }
        },
        "required": [
          "alternatives",
          "supported",
          "missing"
        ],
        "additionalProperties": false
      },
      "Report": {
        "type": "object",
        "properties": {
          "summary": {
            "type": "string"
          },
          "findings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string"
                },
                "detail": {
                  "type": "string"
                },
                "sourceIds": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "label",
                "detail",
                "sourceIds"
              ],
              "additionalProperties": false
            }
          },
          "uncertainties": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "summary",
          "findings",
          "uncertainties"
        ],
        "additionalProperties": false
      },
      "Plan": {
        "type": "object",
        "properties": {
          "questions": {
            "type": "array",
            "minItems": 5,
            "maxItems": 5,
            "items": {
              "type": "object",
              "properties": {
                "angle": {
                  "type": "string"
                },
                "question": {
                  "type": "string"
                }
              },
              "required": [
                "angle",
                "question"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "questions"
        ],
        "additionalProperties": false
      },
      "Relevant": {
        "type": "object",
        "properties": {
          "useful": {
            "type": "boolean",
            "description": "Does this record directly address the assigned research question or one of its planned angles, with identifiable supporting evidence? Exclude unrelated material and unsupported promotional assertions; several records may qualify."
          }
        },
        "required": [
          "useful"
        ],
        "additionalProperties": false
      }
    },
    "input": {
      "schemaId": "Input"
    },
    "output": {
      "schemaId": "Report",
      "path": "report"
    },
    "root": {
      "node": "chain",
      "steps": [
        {
          "node": "decide",
          "label": "research-planner",
          "instructions": "Break the research question into exactly five complementary subquestions covering origins, evidence, alternatives, limitations and open questions. Return these as research tasks, not answers.",
          "state": {
            "question": "{question}"
          },
          "out": "Plan",
          "as": "plan"
        },
        {
          "node": "map",
          "label": "research-questions",
          "itemsPath": "plan.questions",
          "body": {
            "node": "agent",
            "label": "research-angle",
            "instructions": "Research this assigned subquestion using the supplied initial records. Retain citations and identify what is missing. Do not answer other angles or invent sources.",
            "state": {
              "task": "{item}",
              "sources": "{sources}"
            },
            "out": "AngleResult",
            "as": "angleResult"
          },
          "as": "researchResults",
          "resultPath": "angleResult",
          "maxConcurrency": 3
        },
        {
          "node": "code",
          "label": "collect-research",
          "code": "(s) => ({\n      rawEvidence: s.researchResults.flatMap((result) => result.records),\n      gaps: s.researchResults\n        .filter((result) => result.gap)\n        .map((result) => ({ angle: result.angle, question: result.question })),\n    })"
        },
        {
          "node": "sift",
          "label": "sift-evidence",
          "itemsPath": "rawEvidence",
          "describe": "{item.text}",
          "state": {
            "question": "{question}"
          },
          "out": "Relevant",
          "as": "usefulEvidence",
          "keep": {
            "path": "useful",
            "gte": 0.7
          }
        },
        {
          "node": "pick",
          "label": "pick-followup",
          "itemsPath": "gaps",
          "describe": "{item.question}",
          "state": {
            "question": "{question}"
          },
          "instructions": "Select the single open research question whose answer would most improve this report. Pick none_of_these when no useful follow-up is supported. This chooses one task, not a filter over evidence.",
          "allowNone": true,
          "as": "followupChoice"
        },
        {
          "node": "code",
          "label": "followup-gate",
          "code": "(s) => ({\n      followupQueue: s.followupChoice.item ? [s.followupChoice.item] : [],\n    })"
        },
        {
          "node": "map",
          "label": "followup-tasks",
          "itemsPath": "followupQueue",
          "body": {
            "node": "agent",
            "label": "followup-research",
            "instructions": "Research the selected gap using the supplied follow-up records. State whether it was resolved; an empty pack remains unresolved.",
            "state": {
              "task": "{item}",
              "sources": "{sources}"
            },
            "out": "ResearchFollowup",
            "as": "followup"
          },
          "as": "followups",
          "resultPath": "followup",
          "maxConcurrency": 1
        },
        {
          "node": "agent",
          "label": "consolidate-report",
          "instructions": "Write a structured report from supplied evidence only. Cite source IDs. Keep missing evidence and uncertainty explicit. All records here are fictional; do not present this as live research or a real-world approval. Consolidate all five research angles; explain which evidence survived the relevance judgment, and any remaining gap.",
          "state": {
            "question": "{question}",
            "research": "{researchResults}",
            "evidence": "{usefulEvidence.items}",
            "followups": "{followups}",
            "gaps": "{gaps}"
          },
          "out": "Report",
          "as": "report"
        }
      ]
    }
  },
  "kyb": {
    "v": 2,
    "name": "Understand a business and its related people",
    "schemas": {
      "Input": {
        "type": "object",
        "properties": {
          "subject": {
            "type": "string"
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "subject",
          "sources"
        ],
        "additionalProperties": false
      },
      "Record": {
        "type": "object"
      },
      "AngleResult": {
        "type": "object",
        "properties": {
          "angle": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "gap": {
            "type": "boolean"
          }
        },
        "required": [
          "angle",
          "question",
          "records",
          "gap"
        ],
        "additionalProperties": false
      },
      "ResearchFollowup": {
        "type": "object",
        "properties": {
          "angle": {
            "type": "string"
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "resolved": {
            "type": "boolean"
          }
        },
        "required": [
          "angle",
          "records",
          "resolved"
        ],
        "additionalProperties": false
      },
      "EntityDiscovery": {
        "type": "object",
        "properties": {
          "entities": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "recordType": {
                  "type": "string"
                },
                "sourceId": {
                  "type": "string"
                },
                "role": {
                  "type": "string"
                },
                "relatedTo": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "name",
                "recordType",
                "sourceId",
                "role",
                "relatedTo"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "entities"
        ],
        "additionalProperties": false
      },
      "EntityResult": {
        "type": "object",
        "properties": {
          "entity": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "recordType": {
                "type": "string"
              },
              "sourceId": {
                "type": "string"
              },
              "role": {
                "type": "string"
              },
              "relatedTo": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "name",
              "recordType",
              "sourceId",
              "role",
              "relatedTo"
            ],
            "additionalProperties": false
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "complete": {
            "type": "boolean"
          }
        },
        "required": [
          "entity",
          "records",
          "complete"
        ],
        "additionalProperties": false
      },
      "SourceDiscovery": {
        "type": "object",
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "records"
        ],
        "additionalProperties": false
      },
      "NewsSearch": {
        "type": "object",
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text",
                "name",
                "birthYear",
                "location",
                "role"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "birthYear": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "location": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "role": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "phase": {
                  "type": "string"
                },
                "channel": {
                  "type": "string"
                },
                "identity": {
                  "type": "string"
                },
                "identityEvidence": {
                  "type": "object",
                  "required": [
                    "id",
                    "text"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "text": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": true
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "records"
        ],
        "additionalProperties": false
      },
      "Article": {
        "type": "object",
        "required": [
          "id",
          "text",
          "name",
          "birthYear",
          "location",
          "role"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "birthYear": {
            "type": [
              "integer",
              "null"
            ]
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "role": {
            "type": [
              "string",
              "null"
            ]
          },
          "phase": {
            "type": "string"
          },
          "channel": {
            "type": "string"
          },
          "identity": {
            "type": "string"
          },
          "identityEvidence": {
            "type": "object",
            "required": [
              "id",
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string"
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "ActivityEvidence": {
        "type": "object",
        "properties": {
          "source": {
            "type": "object",
            "required": [
              "id",
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string"
              }
            },
            "additionalProperties": true
          },
          "activity": {
            "type": [
              "string",
              "null"
            ]
          },
          "establishesPrincipal": {
            "type": "boolean"
          },
          "identityMatches": {
            "type": "boolean"
          }
        },
        "required": [
          "source",
          "activity",
          "establishesPrincipal",
          "identityMatches"
        ],
        "additionalProperties": false
      },
      "CandidateClasses": {
        "type": "object",
        "properties": {
          "alternatives": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "supported": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "missing": {
            "type": "boolean"
          }
        },
        "required": [
          "alternatives",
          "supported",
          "missing"
        ],
        "additionalProperties": false
      },
      "Report": {
        "type": "object",
        "properties": {
          "summary": {
            "type": "string"
          },
          "findings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string"
                },
                "detail": {
                  "type": "string"
                },
                "sourceIds": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "label",
                "detail",
                "sourceIds"
              ],
              "additionalProperties": false
            }
          },
          "uncertainties": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "summary",
          "findings",
          "uncertainties"
        ],
        "additionalProperties": false
      },
      "EntityKind": {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "company",
              "person",
              "unknown"
            ],
            "description": "Classify the discovered subject using explicit record type and identifiers. An incorporated entity is company; a named natural-person officer is person; insufficient evidence is unknown. A name alone is not enough.",
            "criteria": {
              "company": "An incorporated or registered organization.",
              "person": "A natural-person officer or owner.",
              "unknown": "Insufficient evidence to choose the specialist."
            }
          }
        },
        "required": [
          "kind"
        ],
        "additionalProperties": false
      },
      "Completeness": {
        "type": "object",
        "properties": {
          "complete": {
            "type": "boolean",
            "description": "Are all discovered subjects covered by a cited specialist result, with their required identity/ownership facts present and no unresolved subject? Empty evidence is incomplete. This checks this illustrative evidence pack, not legal compliance."
          }
        },
        "required": [
          "complete"
        ],
        "additionalProperties": false
      },
      "Risk": {
        "type": "object",
        "properties": {
          "outcome": {
            "type": "string",
            "enum": [
              "no_recorded_concern",
              "concern_for_review",
              "human_review"
            ],
            "description": "Assess this fictional review using all discovered subjects, retained findings and unresolved identity/ownership questions. Missing evidence requires human_review. If the supplied checks are complete and no recorded concern appears, return no_recorded_concern, never approval or a guarantee. A cited concern returns concern_for_review.",
            "criteria": {
              "no_recorded_concern": "The supplied checks are complete without a recorded concern; no approval implied.",
              "concern_for_review": "A supported concern requires human review.",
              "human_review": "Identity, ownership or required evidence is incomplete."
            }
          }
        },
        "required": [
          "outcome"
        ],
        "additionalProperties": false
      }
    },
    "input": {
      "schemaId": "Input"
    },
    "output": {
      "schemaId": "Report",
      "path": "report"
    },
    "root": {
      "node": "chain",
      "steps": [
        {
          "node": "agent",
          "label": "discover-entities",
          "instructions": "Read the supplied ownership filing. Discover related organizations and named officers, retaining each source ID and required checks. Do not substitute a preset list.",
          "state": {
            "subject": "{subject}",
            "sources": "{sources}"
          },
          "out": "EntityDiscovery",
          "as": "discovery"
        },
        {
          "node": "map",
          "label": "review-entities",
          "itemsPath": "discovery.entities",
          "body": {
            "node": "chain",
            "steps": [
              {
                "node": "judge",
                "label": "classify-entity",
                "state": {
                  "entity": "{item}"
                },
                "out": "EntityKind",
                "as": "entityKind"
              },
              {
                "node": "route",
                "label": "route-specialist",
                "state": {
                  "entity": "{item}",
                  "classification": "{entityKind}"
                },
                "as": "specialistRoute",
                "instructions": "Use company for an organization, person for a natural-person officer, and unknown when identity is unresolved. Never guess a subject type.",
                "unsure": {
                  "branch": "unknown",
                  "gte": 0.7
                },
                "branches": {
                  "company": {
                    "criteria": "Organization requiring registry and ownership research.",
                    "body": {
                      "node": "agent",
                      "label": "company-research",
                      "instructions": "Research this organization in the supplied initial records. Identify missing ownership facts; retain citations.",
                      "state": {
                        "entity": "{item}",
                        "sources": "{sources}"
                      },
                      "out": "EntityResult",
                      "as": "entityResult"
                    }
                  },
                  "person": {
                    "criteria": "Natural person requiring identity and officer-role research.",
                    "body": {
                      "node": "agent",
                      "label": "officer-research",
                      "instructions": "Research this officer in the supplied initial records. Require an explicit identifier and role; a similar name is insufficient.",
                      "state": {
                        "entity": "{item}",
                        "sources": "{sources}"
                      },
                      "out": "EntityResult",
                      "as": "entityResult"
                    }
                  },
                  "unknown": {
                    "criteria": "The subject type cannot be established.",
                    "body": {
                      "node": "code",
                      "label": "retain-unknown-entity",
                      "code": "(s) => ({\n                entityResult: { entity: s.item, records: [], complete: false },\n              })"
                    }
                  }
                }
              }
            ]
          },
          "as": "entityResults",
          "resultPath": "entityResult",
          "maxConcurrency": 2
        },
        {
          "node": "code",
          "label": "prepare-completeness",
          "code": "(s) => ({\n      reviewed: s.entityResults,\n      pendingEntities: s.entityResults\n        .filter((result) => !result.complete)\n        .map((result) => result.entity),\n    })"
        },
        {
          "node": "judge",
          "label": "completeness-check",
          "state": {
            "discovered": "{discovery.entities}",
            "reviewed": "{reviewed}"
          },
          "out": "Completeness",
          "as": "completeness"
        },
        {
          "node": "loop",
          "label": "complete-records",
          "maxIters": 2,
          "until": {
            "predicate": "field_true",
            "path": "completeness.complete"
          },
          "body": {
            "node": "chain",
            "steps": [
              {
                "node": "map",
                "label": "followup-entities",
                "itemsPath": "pendingEntities",
                "body": {
                  "node": "agent",
                  "label": "entity-followup",
                  "instructions": "Look for the missing subject facts in follow-up records. Preserve unresolved identity or ownership; never infer completeness from an empty search.",
                  "state": {
                    "entity": "{item}",
                    "sources": "{sources}"
                  },
                  "out": "EntityResult",
                  "as": "entityFollowup"
                },
                "as": "followupResults",
                "resultPath": "entityFollowup",
                "maxConcurrency": 2
              },
              {
                "node": "code",
                "label": "merge-entity-evidence",
                "code": "(s) => ({\n          reviewed: s.reviewed.map((result) => {\n            const next = s.followupResults.find(\n              (next) => next.entity.id === result.entity.id,\n            );\n            return next\n              ? {\n                  entity: result.entity,\n                  records: [\n                    ...result.records,\n                    ...next.records.filter(\n                      (record) =>\n                        !result.records.some(\n                          (existing) => existing.id === record.id,\n                        ),\n                    ),\n                  ],\n                  complete: next.complete || result.complete,\n                }\n              : result;\n          }),\n        })"
              },
              {
                "node": "code",
                "label": "remaining-entities",
                "code": "(s) => ({\n          pendingEntities: s.reviewed\n            .filter((result) => !result.complete)\n            .map((result) => result.entity),\n        })"
              },
              {
                "node": "judge",
                "label": "recheck-completeness",
                "state": {
                  "discovered": "{discovery.entities}",
                  "reviewed": "{reviewed}"
                },
                "out": "Completeness",
                "as": "completeness"
              }
            ]
          }
        },
        {
          "node": "judge",
          "label": "risk-judgment",
          "state": {
            "reviewed": "{reviewed}",
            "completeness": "{completeness}"
          },
          "out": "Risk",
          "as": "risk"
        },
        {
          "node": "agent",
          "label": "kyb-report",
          "instructions": "Write a structured report from supplied evidence only. Cite source IDs. Keep missing evidence and uncertainty explicit. All records here are fictional; do not present this as live research or a real-world approval. Explain the discovered organizations and officers, evidence completeness and any review requirement. Do not approve a business or make a legal compliance determination.",
          "state": {
            "subject": "{subject}",
            "reviewed": "{reviewed}",
            "risk": "{risk}"
          },
          "out": "Report",
          "as": "report"
        }
      ]
    }
  },
  "adverse": {
    "v": 2,
    "name": "Review an individual without confusing namesakes",
    "schemas": {
      "Input": {
        "type": "object",
        "properties": {
          "subject": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "birthYear": {
                "type": "integer"
              },
              "location": {
                "type": "string"
              },
              "role": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "birthYear",
              "location",
              "role"
            ],
            "additionalProperties": false
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "subject",
          "sources"
        ],
        "additionalProperties": false
      },
      "Record": {
        "type": "object"
      },
      "AngleResult": {
        "type": "object",
        "properties": {
          "angle": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "gap": {
            "type": "boolean"
          }
        },
        "required": [
          "angle",
          "question",
          "records",
          "gap"
        ],
        "additionalProperties": false
      },
      "ResearchFollowup": {
        "type": "object",
        "properties": {
          "angle": {
            "type": "string"
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "resolved": {
            "type": "boolean"
          }
        },
        "required": [
          "angle",
          "records",
          "resolved"
        ],
        "additionalProperties": false
      },
      "EntityDiscovery": {
        "type": "object",
        "properties": {
          "entities": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "recordType": {
                  "type": "string"
                },
                "sourceId": {
                  "type": "string"
                },
                "role": {
                  "type": "string"
                },
                "relatedTo": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "name",
                "recordType",
                "sourceId",
                "role",
                "relatedTo"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "entities"
        ],
        "additionalProperties": false
      },
      "EntityResult": {
        "type": "object",
        "properties": {
          "entity": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "recordType": {
                "type": "string"
              },
              "sourceId": {
                "type": "string"
              },
              "role": {
                "type": "string"
              },
              "relatedTo": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "name",
              "recordType",
              "sourceId",
              "role",
              "relatedTo"
            ],
            "additionalProperties": false
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "complete": {
            "type": "boolean"
          }
        },
        "required": [
          "entity",
          "records",
          "complete"
        ],
        "additionalProperties": false
      },
      "SourceDiscovery": {
        "type": "object",
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "records"
        ],
        "additionalProperties": false
      },
      "NewsSearch": {
        "type": "object",
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text",
                "name",
                "birthYear",
                "location",
                "role"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "birthYear": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "location": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "role": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "phase": {
                  "type": "string"
                },
                "channel": {
                  "type": "string"
                },
                "identity": {
                  "type": "string"
                },
                "identityEvidence": {
                  "type": "object",
                  "required": [
                    "id",
                    "text"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "text": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": true
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "records"
        ],
        "additionalProperties": false
      },
      "Article": {
        "type": "object",
        "required": [
          "id",
          "text",
          "name",
          "birthYear",
          "location",
          "role"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "birthYear": {
            "type": [
              "integer",
              "null"
            ]
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "role": {
            "type": [
              "string",
              "null"
            ]
          },
          "phase": {
            "type": "string"
          },
          "channel": {
            "type": "string"
          },
          "identity": {
            "type": "string"
          },
          "identityEvidence": {
            "type": "object",
            "required": [
              "id",
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string"
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "ActivityEvidence": {
        "type": "object",
        "properties": {
          "source": {
            "type": "object",
            "required": [
              "id",
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string"
              }
            },
            "additionalProperties": true
          },
          "activity": {
            "type": [
              "string",
              "null"
            ]
          },
          "establishesPrincipal": {
            "type": "boolean"
          },
          "identityMatches": {
            "type": "boolean"
          }
        },
        "required": [
          "source",
          "activity",
          "establishesPrincipal",
          "identityMatches"
        ],
        "additionalProperties": false
      },
      "CandidateClasses": {
        "type": "object",
        "properties": {
          "alternatives": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "supported": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "missing": {
            "type": "boolean"
          }
        },
        "required": [
          "alternatives",
          "supported",
          "missing"
        ],
        "additionalProperties": false
      },
      "Report": {
        "type": "object",
        "properties": {
          "summary": {
            "type": "string"
          },
          "findings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string"
                },
                "detail": {
                  "type": "string"
                },
                "sourceIds": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "label",
                "detail",
                "sourceIds"
              ],
              "additionalProperties": false
            }
          },
          "uncertainties": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "summary",
          "findings",
          "uncertainties"
        ],
        "additionalProperties": false
      },
      "Identity": {
        "type": "object",
        "properties": {
          "identity": {
            "type": "string",
            "enum": [
              "confirmed",
              "unrelated",
              "unresolved"
            ],
            "description": "Does this source identify the actual subject? confirmed requires a matching name, birth year and location plus consistent role, with no contradiction. A conflicting birth year or identity context is unrelated. Name-only and incomplete matches remain unresolved. This is identity attribution, not proof an allegation is true.",
            "criteria": {
              "confirmed": "Identifiers link the source to the subject.",
              "unrelated": "Identifiers establish a different subject.",
              "unresolved": "Insufficient identifying evidence; retain for follow-up."
            }
          }
        },
        "required": [
          "identity"
        ],
        "additionalProperties": false
      },
      "Confirmed": {
        "type": "object",
        "properties": {
          "confirmed": {
            "type": "boolean",
            "description": "Keep a source only when its retained identity judgment is confirmed with supporting identifiers. Do not treat unresolved namesakes as confirmed or as cleared. This does not establish whether the allegation is true."
          }
        },
        "required": [
          "confirmed"
        ],
        "additionalProperties": false
      },
      "NewsEvidence": {
        "type": "object",
        "properties": {
          "outcome": {
            "type": "string",
            "enum": [
              "identity_review",
              "allegation_review",
              "no_confirmed_match"
            ],
            "description": "Review confirmed sources and remaining unresolved matches separately. Unresolved identity requires identity_review. Confirmed allegations require allegation_review without treating them as proven facts or convictions. With neither, return no_confirmed_match, which is not a clean bill of health.",
            "criteria": {
              "identity_review": "An unresolved identity match remains.",
              "allegation_review": "A confirmed subject match contains an allegation requiring review.",
              "no_confirmed_match": "No supplied source is a confirmed match; no exoneration implied."
            }
          }
        },
        "required": [
          "outcome"
        ],
        "additionalProperties": false
      }
    },
    "input": {
      "schemaId": "Input"
    },
    "output": {
      "schemaId": "Report",
      "path": "report"
    },
    "root": {
      "node": "chain",
      "steps": [
        {
          "node": "parallel",
          "label": "search-sources",
          "branches": [
            {
              "node": "agent",
              "label": "news-search",
              "instructions": "Search supplied news records for candidate subject mentions. Keep uncertain namesakes for identity review.",
              "state": {
                "subject": "{subject}",
                "sources": "{sources}",
                "channel": "news"
              },
              "out": "NewsSearch",
              "as": "news"
            },
            {
              "node": "agent",
              "label": "regulatory-search",
              "instructions": "Search supplied regulatory records. Keep source status and identifiers; do not infer wrongdoing.",
              "state": {
                "subject": "{subject}",
                "sources": "{sources}",
                "channel": "regulatory"
              },
              "out": "NewsSearch",
              "as": "regulatory"
            },
            {
              "node": "agent",
              "label": "court-records-search",
              "instructions": "Search supplied court records for candidate identity matches. Preserve case status; an empty supplied result does not establish clearance.",
              "state": {
                "subject": "{subject}",
                "sources": "{sources}",
                "channel": "court-records"
              },
              "out": "NewsSearch",
              "as": "courtRecords"
            },
            {
              "node": "agent",
              "label": "sanctions-search",
              "instructions": "Search supplied sanctions records for candidate identity matches. Do not equate a namesake with a listed person or an empty supplied pack with clearance.",
              "state": {
                "subject": "{subject}",
                "sources": "{sources}",
                "channel": "sanctions"
              },
              "out": "NewsSearch",
              "as": "sanctions"
            },
            {
              "node": "agent",
              "label": "archive-search",
              "instructions": "Search supplied archive records for possible matches, including namesakes.",
              "state": {
                "subject": "{subject}",
                "sources": "{sources}",
                "channel": "archive"
              },
              "out": "NewsSearch",
              "as": "archive"
            }
          ]
        },
        {
          "node": "code",
          "label": "collect-news",
          "code": "(s) => ({\n      articles: [\n        ...s.news.records,\n        ...s.regulatory.records,\n        ...s.courtRecords.records,\n        ...s.sanctions.records,\n        ...s.archive.records,\n      ],\n    })"
        },
        {
          "node": "map",
          "label": "classify-matches",
          "itemsPath": "articles",
          "body": {
            "node": "chain",
            "steps": [
              {
                "node": "judge",
                "label": "identity-match",
                "state": {
                  "subject": "{subject}",
                  "article": "{item}"
                },
                "out": "Identity",
                "as": "identity"
              },
              {
                "node": "code",
                "label": "retain-match",
                "code": "(s) => ({\n          matched: { ...s.item, identity: s.identity.identity },\n        })"
              }
            ]
          },
          "as": "matches",
          "resultPath": "matched",
          "maxConcurrency": 3
        },
        {
          "node": "sift",
          "label": "sift-confirmed",
          "itemsPath": "matches",
          "describe": "{item.text}",
          "state": {
            "subject": "{subject}"
          },
          "out": "Confirmed",
          "as": "initialConfirmed",
          "keep": {
            "path": "confirmed",
            "gte": 0.7
          }
        },
        {
          "node": "code",
          "label": "prepare-identity-followup",
          "code": "(s) => ({\n      unresolved: s.matches.filter((match) => match.identity === \"unresolved\"),\n      identityDone: !s.matches.some((match) => match.identity === \"unresolved\"),\n    })"
        },
        {
          "node": "loop",
          "label": "followup-identities",
          "maxIters": 2,
          "until": {
            "predicate": "field_true",
            "path": "identityDone"
          },
          "body": {
            "node": "chain",
            "steps": [
              {
                "node": "map",
                "label": "review-unresolved",
                "itemsPath": "unresolved",
                "body": {
                  "node": "chain",
                  "steps": [
                    {
                      "node": "agent",
                      "label": "identity-followup",
                      "instructions": "Research only the identifying details of this candidate in supplied follow-up records. Keep the original source and allegation status. No follow-up evidence means identity remains unresolved.",
                      "state": {
                        "article": "{item}",
                        "sources": "{sources}"
                      },
                      "out": "Article",
                      "as": "updatedArticle"
                    },
                    {
                      "node": "judge",
                      "label": "followup-identity-match",
                      "state": {
                        "subject": "{subject}",
                        "article": "{updatedArticle}"
                      },
                      "out": "Identity",
                      "as": "updatedIdentity"
                    },
                    {
                      "node": "code",
                      "label": "retain-followup-match",
                      "code": "(s) => ({\n              matched: {\n                ...s.updatedArticle,\n                identity: s.updatedIdentity.identity,\n              },\n            })"
                    }
                  ]
                },
                "as": "identityFollowups",
                "resultPath": "matched",
                "maxConcurrency": 2
              },
              {
                "node": "code",
                "label": "merge-identity-followup",
                "code": "(s) => ({\n          matches: s.matches.map(\n            (match) =>\n              s.identityFollowups.find((next) => next.id === match.id) || match,\n          ),\n        })"
              },
              {
                "node": "code",
                "label": "remaining-identities",
                "code": "(s) => ({\n          unresolved: s.matches.filter(\n            (match) => match.identity === \"unresolved\",\n          ),\n          identityDone: !s.matches.some(\n            (match) => match.identity === \"unresolved\",\n          ),\n        })"
              }
            ]
          }
        },
        {
          "node": "sift",
          "label": "sift-final-confirmed",
          "itemsPath": "matches",
          "describe": "{item.text}",
          "state": {
            "subject": "{subject}"
          },
          "out": "Confirmed",
          "as": "confirmed",
          "keep": {
            "path": "confirmed",
            "gte": 0.7
          }
        },
        {
          "node": "judge",
          "label": "evidence-judgment",
          "state": {
            "confirmed": "{confirmed.items}",
            "unresolved": "{unresolved}"
          },
          "out": "NewsEvidence",
          "as": "assessment"
        },
        {
          "node": "agent",
          "label": "adverse-report",
          "instructions": "Write a structured report from supplied evidence only. Cite source IDs. Keep missing evidence and uncertainty explicit. All records here are fictional; do not present this as live research or a real-world approval. Report confirmed source attribution separately from truth of allegations. Keep unresolved matches visible and do not imply a clean search or a conviction. Empty supplied channels are not clearance.",
          "state": {
            "subject": "{subject}",
            "confirmed": "{confirmed.items}",
            "unresolved": "{unresolved}",
            "allMatches": "{matches}",
            "assessment": "{assessment}"
          },
          "out": "Report",
          "as": "report"
        }
      ]
    }
  },
  "mcc": {
    "v": 2,
    "name": "Classify a business using its actual activity",
    "schemas": {
      "Input": {
        "type": "object",
        "properties": {
          "subject": {
            "type": "string"
          },
          "entityId": {
            "type": "string"
          },
          "website": {
            "type": "string"
          },
          "policy": {
            "type": "object",
            "properties": {
              "version": {
                "type": "string"
              },
              "sections": {
                "type": "object",
                "properties": {
                  "identity": {
                    "type": "string",
                    "minLength": 1
                  },
                  "activity": {
                    "type": "string",
                    "minLength": 1
                  },
                  "selection": {
                    "type": "string",
                    "minLength": 1
                  },
                  "indicators": {
                    "type": "string",
                    "minLength": 1
                  },
                  "reporting": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "identity",
                  "activity",
                  "selection",
                  "indicators",
                  "reporting"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "version",
              "sections"
            ],
            "additionalProperties": false
          },
          "catalogue": {
            "type": "object",
            "properties": {
              "version": {
                "type": "string"
              },
              "rows": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "activity": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    },
                    "excludes": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id",
                    "activity",
                    "description",
                    "excludes"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "version",
              "rows"
            ],
            "additionalProperties": false
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "subject",
          "entityId",
          "website",
          "policy",
          "catalogue",
          "sources"
        ],
        "additionalProperties": false
      },
      "Record": {
        "type": "object"
      },
      "AngleResult": {
        "type": "object",
        "properties": {
          "angle": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "gap": {
            "type": "boolean"
          }
        },
        "required": [
          "angle",
          "question",
          "records",
          "gap"
        ],
        "additionalProperties": false
      },
      "ResearchFollowup": {
        "type": "object",
        "properties": {
          "angle": {
            "type": "string"
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "resolved": {
            "type": "boolean"
          }
        },
        "required": [
          "angle",
          "records",
          "resolved"
        ],
        "additionalProperties": false
      },
      "EntityDiscovery": {
        "type": "object",
        "properties": {
          "entities": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "recordType": {
                  "type": "string"
                },
                "sourceId": {
                  "type": "string"
                },
                "role": {
                  "type": "string"
                },
                "relatedTo": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "name",
                "recordType",
                "sourceId",
                "role",
                "relatedTo"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "entities"
        ],
        "additionalProperties": false
      },
      "EntityResult": {
        "type": "object",
        "properties": {
          "entity": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "recordType": {
                "type": "string"
              },
              "sourceId": {
                "type": "string"
              },
              "role": {
                "type": "string"
              },
              "relatedTo": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "name",
              "recordType",
              "sourceId",
              "role",
              "relatedTo"
            ],
            "additionalProperties": false
          },
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "complete": {
            "type": "boolean"
          }
        },
        "required": [
          "entity",
          "records",
          "complete"
        ],
        "additionalProperties": false
      },
      "SourceDiscovery": {
        "type": "object",
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "records"
        ],
        "additionalProperties": false
      },
      "NewsSearch": {
        "type": "object",
        "properties": {
          "records": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "text",
                "name",
                "birthYear",
                "location",
                "role"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "text": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "birthYear": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "location": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "role": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "phase": {
                  "type": "string"
                },
                "channel": {
                  "type": "string"
                },
                "identity": {
                  "type": "string"
                },
                "identityEvidence": {
                  "type": "object",
                  "required": [
                    "id",
                    "text"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "text": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": true
                }
              },
              "additionalProperties": true
            }
          }
        },
        "required": [
          "records"
        ],
        "additionalProperties": false
      },
      "Article": {
        "type": "object",
        "required": [
          "id",
          "text",
          "name",
          "birthYear",
          "location",
          "role"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "birthYear": {
            "type": [
              "integer",
              "null"
            ]
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "role": {
            "type": [
              "string",
              "null"
            ]
          },
          "phase": {
            "type": "string"
          },
          "channel": {
            "type": "string"
          },
          "identity": {
            "type": "string"
          },
          "identityEvidence": {
            "type": "object",
            "required": [
              "id",
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string"
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "ActivityEvidence": {
        "type": "object",
        "properties": {
          "source": {
            "type": "object",
            "required": [
              "id",
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string"
              }
            },
            "additionalProperties": true
          },
          "activity": {
            "type": [
              "string",
              "null"
            ]
          },
          "establishesPrincipal": {
            "type": "boolean"
          },
          "identityMatches": {
            "type": "boolean"
          }
        },
        "required": [
          "source",
          "activity",
          "establishesPrincipal",
          "identityMatches"
        ],
        "additionalProperties": false
      },
      "CandidateClasses": {
        "type": "object",
        "properties": {
          "alternatives": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "supported": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "missing": {
            "type": "boolean"
          }
        },
        "required": [
          "alternatives",
          "supported",
          "missing"
        ],
        "additionalProperties": false
      },
      "Report": {
        "type": "object",
        "properties": {
          "summary": {
            "type": "string"
          },
          "findings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string"
                },
                "detail": {
                  "type": "string"
                },
                "sourceIds": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "label",
                "detail",
                "sourceIds"
              ],
              "additionalProperties": false
            }
          },
          "uncertainties": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "summary",
          "findings",
          "uncertainties"
        ],
        "additionalProperties": false
      },
      "BusinessClass": {
        "type": "object",
        "properties": {
          "category": {
            "type": "string",
            "enum": [
              "repair_service",
              "retail_sales",
              "needs_review"
            ],
            "description": "Apply every section of the supplied versioned policy to all identity and activity findings and compare the supplied catalogue inclusions and exclusions. Choose the supported catalogue activity, or needs_review when the policy requires referral. Do not rewrite the policy, invent evidence or treat these teaching categories as official payment-network codes.",
            "criteria": {
              "repair_service": "Repairing customer-owned goods is the evidenced principal activity.",
              "retail_sales": "Selling goods is the evidenced principal activity.",
              "needs_review": "Principal activity is missing, conflicting or unsupported."
            }
          }
        },
        "required": [
          "category"
        ],
        "additionalProperties": false
      },
      "Indicators": {
        "type": "object",
        "properties": {
          "outcome": {
            "type": "string",
            "enum": [
              "no_recorded_flags",
              "refer"
            ],
            "description": "Independently apply every section of the supplied policy and catalogue to the evidence. Do not copy the assignment answer. Return refer when the policy identifies a blocker or gap; no_recorded_flags is limited to these supplied checks, never approval.",
            "criteria": {
              "no_recorded_flags": "No blocking indicator in the supplied fixture evidence.",
              "refer": "An identity, activity, conflict or evidence blocker requires human review."
            }
          }
        },
        "required": [
          "outcome"
        ],
        "additionalProperties": false
      }
    },
    "input": {
      "schemaId": "Input"
    },
    "output": {
      "schemaId": "Report",
      "path": "report"
    },
    "root": {
      "node": "chain",
      "steps": [
        {
          "node": "route",
          "label": "choose-source-path",
          "state": {
            "website": "{website}"
          },
          "instructions": "Use website when a supplied business website is available. If no website is supplied, discover sources from the supplied places listing, registry and aliases. Discovery locates evidence; it does not determine the business class.",
          "as": "sourceRoute",
          "unsure": {
            "branch": "discover",
            "gte": 0.7
          },
          "branches": {
            "website": {
              "criteria": "A business website was supplied.",
              "body": {
                "node": "agent",
                "label": "read-website",
                "instructions": "Read the supplied website record and locate its activity evidence. Retain source IDs and distinguish advertised activities from principal activity.",
                "state": {
                  "website": "{website}",
                  "sources": "{sources}"
                },
                "out": "SourceDiscovery",
                "as": "sourceDiscovery"
              }
            },
            "discover": {
              "criteria": "No business website is supplied.",
              "body": {
                "node": "agent",
                "label": "discover-sources",
                "instructions": "Use supplied places, registry and alias records to discover candidate business sources. Explain the identity links; do not assign a business class from a listing alone.",
                "state": {
                  "subject": "{subject}",
                  "sources": "{sources}"
                },
                "out": "SourceDiscovery",
                "as": "sourceDiscovery"
              }
            }
          }
        },
        {
          "node": "map",
          "label": "research-business",
          "itemsPath": "sourceDiscovery.records",
          "body": {
            "node": "agent",
            "label": "research-activity",
            "instructions": "Investigate this source for identity and principal business activity. A directory name is a lead, not proof of activity. Preserve contradictions and missing details.",
            "state": {
              "source": "{item}",
              "subject": "{subject}",
              "entityId": "{entityId}"
            },
            "out": "ActivityEvidence",
            "as": "activityEvidence"
          },
          "as": "activityFindings",
          "resultPath": "activityEvidence",
          "maxConcurrency": 2
        },
        {
          "node": "agent",
          "label": "candidate-classes",
          "instructions": "Use all activity findings to propose illustrative repair_service and retail_sales alternatives. Explain their evidence, exclusions and unresolved principal-activity questions. Do not choose a final class.",
          "state": {
            "findings": "{activityFindings}",
            "policy": "{policy}",
            "catalogue": "{catalogue}"
          },
          "out": "CandidateClasses",
          "as": "candidates"
        },
        {
          "node": "judge",
          "label": "classify-business",
          "state": {
            "findings": "{activityFindings}",
            "candidates": "{candidates}",
            "policy": "{policy}",
            "catalogue": "{catalogue}"
          },
          "out": "BusinessClass",
          "as": "classification"
        },
        {
          "node": "judge",
          "label": "check-business-indicators",
          "state": {
            "findings": "{activityFindings}",
            "policy": "{policy}",
            "catalogue": "{catalogue}"
          },
          "out": "Indicators",
          "as": "indicators"
        },
        {
          "node": "code",
          "label": "resolve-catalogue-row",
          "code": "(s) => {\n      if (\n        new Set(s.catalogue.rows.map((row) => row.id)).size !==\n        s.catalogue.rows.length\n      )\n        throw new Error(\"Catalogue row IDs must be unique\");\n      const rows = s.catalogue.rows.filter(\n        (row) => row.activity === s.classification.category,\n      );\n      const blocked =\n        s.classification.category === \"needs_review\" ||\n        s.indicators.outcome === \"refer\";\n      if (!blocked && rows.length !== 1)\n        throw new Error(\n          \"The selected activity must resolve to exactly one supplied catalogue row\",\n        );\n      return {\n        selectedRow: blocked ? null : rows[0],\n        referred: blocked,\n        policyVersion: s.policy.version,\n        catalogVersion: s.catalogue.version,\n      };\n    }"
        },
        {
          "node": "agent",
          "label": "mcc-report",
          "instructions": "Write a structured report from supplied evidence only. Cite source IDs. Keep missing evidence and uncertainty explicit. All records here are fictional; do not present this as live research or a real-world approval. Explain the illustrative category and supporting/excluding evidence. If evidence is insufficient, require review rather than inventing an official MCC. This is not a financial or regulatory determination.",
          "state": {
            "subject": "{subject}",
            "findings": "{activityFindings}",
            "candidates": "{candidates}",
            "classification": "{classification}",
            "indicators": "{indicators}",
            "selectedRow": "{selectedRow}",
            "referred": "{referred}",
            "policyVersion": "{policyVersion}",
            "catalogVersion": "{catalogVersion}",
            "policy": "{policy}",
            "catalogue": "{catalogue}"
          },
          "out": "Report",
          "as": "report"
        }
      ]
    }
  }
}
