"""Parse workflow-generator answers separately from leading model reasoning.""" import re from typing import Any import json_repair from graphon.nodes.llm.reasoning import split_reasoning _THINK_CLOSE_TAG_RE = re.compile(r"", re.IGNORECASE) def parse_workflow_generator_response(text: str) -> Any: """Repair answer JSON without parsing a leading reasoning envelope. Only consume complete envelopes at the beginning of the response. The existing reasoning owner recognizes each isolated envelope; applying it to the entire answer would also strip literal tags inside JSON strings. A recognized unclosed envelope has no answer and yields non-object JSON, leaving rejection and correction budgets with the generator's caller. """ answer = text.lstrip() while answer.lower().startswith("