llm_helpers: unwrap CreateResult.content defensively (fix Step 9b on gateway)

llm_call_expect_json did `result.content.content`, assuming a nested object.
On the OpenAI/phyagi-gateway path CreateResult.content is already a plain
str, so this raised "'str' object has no attribute 'content'" on every
attempt — Step 9b (trajectory-informed task verification) failed all retries
and silently fell back to a default. The bug was masked because the test only
asserts the result keys exist, not that the step ran.

Mirror task_classification's helper: unwrap .content only when present. Step
9b now runs clean against the gateway (no retries, real verdict).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
corby
2026-05-29 12:52:36 -07:00
parent 19224e97da
commit c529b48511

View File

@@ -81,7 +81,13 @@ async def llm_call_expect_json(
if json_output:
create_kwargs["json_output"] = True
result = await client.create(**create_kwargs)
response_text = (result.content.content or "").strip()
# CreateResult.content is a plain str on the OpenAI/gateway path
# but a nested object on some Azure wrappers — unwrap defensively
# (mirrors task_classification's helper) so neither shape breaks.
content = result.content
if hasattr(content, "content"):
content = content.content
response_text = (content or "").strip()
except Exception as e:
# Don't nudge on transport errors — the LLM never saw the
# prompt, so an "Error: ConnectionError" turn is just noise.