chat mode: json_output toggle to return clean extracted JSON

For JSON-producing system prompts (e.g. LTX prompt-relay), json_output=true pulls
the JSON object out of the reply (strips reasoning/prose/code-fences via _parse_json,
which handles nested schemas and reasoning-then-JSON) and returns it re-serialized;
falls back to raw text if none parses. agent_bridge gains --json-output.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 02:09:36 +02:00
parent f7ea559690
commit 8b567cb531
3 changed files with 28 additions and 6 deletions
+8 -2
View File
@@ -49,7 +49,8 @@ def _http_json(url: str, payload: dict | None = None, timeout: int = 30):
def _inject(graph: dict, prompt: str, negative: str, seed: int, run_tag: str, mode: str,
reference_description: str = "", profile: str = "", model_select: str = "",
model_path: str = "", system_prompt: str = "", user_prompt: str = ""):
model_path: str = "", system_prompt: str = "", user_prompt: str = "",
json_output: bool = False):
"""Set the receptor's prompt/seed and the judge's mode/run_tag in-place.
compare mode needs a receptor (to inject the prompt). describe mode is the first
@@ -79,6 +80,8 @@ def _inject(graph: dict, prompt: str, negative: str, seed: int, run_tag: str, mo
inputs["system_prompt"] = system_prompt
if user_prompt:
inputs["user_prompt"] = user_prompt
if json_output:
inputs["json_output"] = True
if mode == "compare" and not found_receptor:
raise SystemExit(
f"[agent_bridge] no '{RECEPTOR_CLASS}' node in the workflow — add the "
@@ -123,6 +126,8 @@ def main(argv=None):
help="describe = first pass over the reference; chat = general VLM with your prompts")
ap.add_argument("--system-prompt", default="", help="chat mode: system prompt")
ap.add_argument("--user-prompt", default="", help="chat mode: user prompt over the image(s)")
ap.add_argument("--json-output", action="store_true",
help="chat mode: extract & return clean JSON from the reply")
ap.add_argument("--prompt", default="", help="generation prompt (required for compare)")
ap.add_argument("--negative", default="")
ap.add_argument("--seed", type=int, default=0)
@@ -155,7 +160,8 @@ def main(argv=None):
graph = json.load(f)
_inject(graph, args.prompt, args.negative, args.seed, args.run_tag, args.mode, ref_desc,
args.profile, args.model_select, args.model_path, args.system_prompt, args.user_prompt)
args.profile, args.model_select, args.model_path, args.system_prompt, args.user_prompt,
args.json_output)
client_id = uuid.uuid4().hex
try: