[Platform][VertexAi] Wrap list-array tool responses for Struct-proto compatibility#2102
Open
peter-si wants to merge 1 commit into
Open
[Platform][VertexAi] Wrap list-array tool responses for Struct-proto compatibility#2102peter-si wants to merge 1 commit into
peter-si wants to merge 1 commit into
Conversation
2549c02 to
1976b00
Compare
Author
|
Heads up on red CI here:
I've opened #2103 with the two-line fix. Once that merges, the failure here will clear after a rebase. Let me know if you'd prefer this PR to depend on / include that fix instead. |
Gemini declares `functionResponse.response` as a `google.protobuf.Struct`
which represents a JSON object. Sequential JSON arrays from tools that
return lists are rejected with "Proto field is not repeating, cannot
start list", failing the whole turn.
Wrap list-arrays as `{items: [...]}` so list-returning tools work end
to end. Existing handling is preserved: associative arrays pass through,
scalars / null wrap as `{rawResponse: <value>}`.
Also extracts the JSON-decode and shape-coercion into named helpers,
adds a class-level docblock describing the Struct quirk, and drops a
no-op `array_filter()` on the outer payload.
1976b00 to
1adabea
Compare
Member
|
Hi @peter-si, I would expect a tool result to be more structured, and that's why we have the |
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.
Summary
Wraps list-array tool responses in a
{items: [...]}object so they pass Gemini's Struct-proto validation onfunctionResponse.response. Without this, any tool that returns a JSON list 500s the whole turn withProto field is not repeating, cannot start list.Why
google.protobuf.Structis a JSON-object shape — it cannot represent a sequential JSON array. The current normalizer wraps scalars as{rawResponse: <value>}(good) but passes lists through unchanged (broken). Every tool that returns rows / records / promos / search results / etc. fails.Concrete reproducer: a tool method returning
[{name: 'A'}, {name: 'B'}]producesfunctionResponse.response = [{name: 'A'}, {name: 'B'}], which Vertex rejects.What changes
In
Symfony\AI\Platform\Bridge\VertexAi\Contract\ToolCallMessageNormalizer:{items: [...]}(new){rawResponse: <value>}(unchanged)Drive-bys while in the file: extracted
decodeContent()andasStruct()for readability, added a class-level docblock describing the Struct quirk, and dropped a no-oparray_filter()on the outer payload (it never had anything to filter).Backwards compatibility
The output shape changes for tools that returned a JSON list, but those tools currently 500 with the Struct-proto error against Gemini, so there are no working consumers depending on the broken shape. A
[BC BREAK]entry has been added to theai-vertex-ai-platformCHANGELOG under0.10.Tests
New
src/platform/tests/Bridge/VertexAi/Contract/ToolCallMessageNormalizerTestcovers associative passthrough, list-wrap, empty-list-wrap, scalar wrap, non-JSON content, null content, and tool-name preservation. 9 tests, 9 assertions, all green.🤖 Generated with Claude Code