{
  "contract": "algal.organism.v1",
  "key": "organism:refine",
  "name": "Draft refinement loop",
  "budgets": {
    "maxAgentCalls": 12,
    "maxContextBytes": 65536,
    "maxDepth": 4,
    "maxOutputBytes": 65536,
    "maxSteps": 128,
    "maxWork": 400000
  },
  "cells": [
    {
      "id": "ticket",
      "kind": "input",
      "outputs": {
        "draft": {
          "type": "text"
        }
      }
    },
    {
      "id": "loop",
      "kind": "repeat",
      "manifest": "sha256:39192d2a7a2d67b30d09302fa36fd6c612536eae3a190f448f92b11031ab7c31",
      "maxRounds": 4,
      "carry": {
        "draft": "draft"
      },
      "until": {
        "output": "verdict",
        "equals": "ship"
      }
    },
    {
      "id": "ship",
      "kind": "fn",
      "fn": "tag.v1"
    },
    {
      "id": "hold",
      "kind": "fn",
      "fn": "tag.v1"
    }
  ],
  "edges": [
    {
      "from": {
        "cell": "ticket",
        "port": "draft"
      },
      "to": {
        "cell": "loop",
        "port": "draft"
      }
    },
    {
      "from": {
        "cell": "loop",
        "port": "verdict"
      },
      "to": {
        "cell": "ship",
        "port": "tag"
      },
      "guard": {
        "equals": "ship"
      }
    },
    {
      "from": {
        "cell": "loop",
        "port": "draft"
      },
      "to": {
        "cell": "ship",
        "port": "value"
      }
    },
    {
      "from": {
        "cell": "loop",
        "port": "verdict"
      },
      "to": {
        "cell": "hold",
        "port": "tag"
      },
      "guard": {
        "equals": "revise"
      }
    },
    {
      "from": {
        "cell": "loop",
        "port": "draft"
      },
      "to": {
        "cell": "hold",
        "port": "value"
      }
    }
  ],
  "note": "A repeat cell re-runs organism:refine-inner until the critic ships or maxRounds is spent. Iteration is the cell; the graph stays a DAG.",
  "interface": {
    "inputs": {
      "draft": {
        "cell": "ticket",
        "port": "draft"
      }
    },
    "outputs": {
      "result": {
        "cell": "ship",
        "port": "value"
      }
    }
  }
}
