{
  "version": "3.15",
  "name": "Test10: Complex Multi-stage Pipeline",
  "registry": {
    "params": ["requirement(STRING)"],
    "vars": [
      "$plan(OBJECT)",
      "$tasks([OBJECT])",
      "$implementations([STRING])",
      "$report(STRING)"
    ],
    "files": { "inputs": [], "artifacts": ["Output/*"] }
  },
  "steps": [
    {
      "id": "LLM_Plan",
      "in": {
        "messages": [
          { "role": "system", "content": "You are a project planner. Given a requirement, output a plan as JSON." },
          { "role": "user",   "content": "=requirement" }
        ],
        "output_config": {
          "format": {
            "type": "json_schema",
            "schema": {
              "type": "object",
              "properties": {
                "title": { "type": "string" },
                "tasks": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "name":        { "type": "string" },
                      "description": { "type": "string" }
                    },
                    "required": ["name", "description"],
                    "additionalProperties": false
                  }
                }
              },
              "required": ["title", "tasks"],
              "additionalProperties": false
            }
          }
        }
      },
      "out": {
        "$plan":  "=_result",
        "$tasks": "=_result.tasks"
      },
      "next": "Loop_Implement"
    },
    {
      "id": "Loop_Implement",
      "mode": "parallel",
      "source": "=$tasks",
      "children": ["LLM_Implement"],
      "next": "LLM_Report"
    },
    {
      "id": "LLM_Implement",
      "in": {
        "messages": [
          { "role": "user", "content": "=\"Implement in one sentence: \" + _item.name + \" - \" + _item.description" }
        ]
      },
      "out": { "$implementations[_index]": "=_result" },
      "next": "RETURN"
    },
    {
      "id": "LLM_Report",
      "in": {
        "messages": [
          { "role": "user", "content": "=\"Summarize in 2 sentences the project: \" + $plan.title" }
        ]
      },
      "out": "$report",
      "next": "Write_Report"
    },
    {
      "id": "Write_Report",
      "target": "Output/test10_report.txt",
      "value": "=$report",
      "next": "Stop_End"
    },
    { "id": "Stop_End" }
  ]
}
