fix: guard None text in ItemHelpers.extract_last_content#3394
Conversation
6b52f73 to
48f00e7
Compare
|
Thanks for the review! Added inline comments on both
The two comments differ slightly in the second sentence to match their respective return types ( Force-pushed the amended commit. |
Extends the fix in openai#3375 (`fix: guard None text in text_message_output ...`) to one more sibling helper that had the same `-> str` type contract. `ResponseOutputText.text` is typed as `str` per the Responses API schema, but `src/agents/items.py:714-720` already documents that provider gateways (e.g. LiteLLM) and `model_construct` paths during streaming surface `None` values. PR openai#3375 fixed `text_message_output` for this case. `extract_last_content` (declared `-> str`, items.py:678) silently violated its type contract by returning `None` when `last_content.text` was `None`. Repro: >>> text_part = ResponseOutputText.model_construct( ... text=None, type="output_text", annotations=[]) >>> msg = ResponseOutputMessage.model_construct( ... id="m", role="assistant", status="completed", ... type="message", content=[text_part]) >>> ItemHelpers.extract_last_content(msg) None # but the function is typed `-> str` Fix mirrors the openai#3375 pattern: `return last_content.text or ""`. Note: `extract_last_text` (declared `-> str | None`) is intentionally left alone — `None` is already a valid return per its signature, and coalescing `""` → `None` would silently change semantics for tools that legitimately return empty text.
48f00e7 to
4fe452d
Compare
|
Follow-up: on second look at the diff, the original Reverted that change and dropped the related tests/inline comment. The PR is now scoped to a single, real fix:
Updated commit message + PR title accordingly. Sorry for the noise. |
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Extends the fix in #3375 (`fix: guard None text in text_message_output ...`) to the two sibling helpers in `ItemHelpers` that have the same shape.
`ResponseOutputText.text` is typed as `str` per the Responses API schema, but `src/agents/items.py:714-720` already documents (in the comment above the original #3375 fix) that provider gateways like LiteLLM and `model_construct` paths during streaming surface `None` values. PR #3375 fixed `text_message_output` for this case. Two sibling helpers were missed:
Repro for `extract_last_content` (declared `-> str`, returns `None`):
```python
Fix mirrors the #3375 pattern: `return last_content.text or ""` in `extract_last_content`, `return last_content.text or None` in `extract_last_text` for explicit semantics.
Test plan
Issue number
N/A — found while auditing for the same pattern that #3375 fixed.
Checks