fix(items): empty list/tuple tool output dropped via all([]) == True#3554
Open
vidigoat wants to merge 1 commit into
Open
fix(items): empty list/tuple tool output dropped via all([]) == True#3554vidigoat wants to merge 1 commit into
vidigoat wants to merge 1 commit into
Conversation
ItemHelpers._convert_tool_output stringifies a tool's list/tuple return value unless every element is a structured output type, gated on 'if all(maybe_converted_output_list)'. For an empty list/tuple the comprehension yields [] and all([]) is True, so the empty collection wrongly takes the structured-output branch and returns an empty ResponseFunctionCallOutputItemListParam. Sent to the Responses API as a function_call_output, that empty list drops the tool result entirely instead of producing the expected stringified '[]' / '()'. Guard the branch with a truthiness check so empty collections fall through to str(output). Non-empty lists were already stringified correctly; only the empty case is fixed. Adds regression tests for empty list and empty tuple. Signed-off-by: Vidit Patankar <vidit.patankar16@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ItemHelpers._convert_tool_output(insrc/agents/items.py, reached via the publicItemHelpers.tool_call_output_item) decides whether a tool's list/tuple return value is structured output or should be stringified:For an empty list or tuple, the comprehension yields
[]andall([]) == True, so the empty collection wrongly takes the structured-output branch and returns an emptyResponseFunctionCallOutputItemListParam([]). Sent to the Responses API as afunction_call_output, an empty structured list drops the tool result entirely — the model sees no output for that tool call — instead of the expected stringified"[]"/"()".A non-empty plain list like
[1, 2, 3]correctly stringifies to"[1, 2, 3]"; only the empty case misbehaves.Fix
Empty collections now fall through to
str(output).Verification
ruff check, ruff format --check, and mypy all pass on the changed files.
Adds
test_tool_call_output_item_empty_list_not_convertedand..._empty_tuple_not_convertedmirroring the existing "not_converted" test style.