fix(adk-middleware): map oneOf → anyOf so genai keeps discriminated-union tool params#2027
Open
jplikesbikes wants to merge 1 commit into
Open
Conversation
|
@jplikesbikes is attempting to deploy a commit to the CopilotKit Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
@contextablemark Just wanted to bring this to your attention no rush |
jplikesbikes
force-pushed
the
fix/clean-schema-oneof-to-anyof
branch
from
July 6, 2026 17:11
68fb604 to
eb1b185
Compare
Contributor
Author
|
@contextablemark friendly reminder |
google.genai's Schema accepts `anyOf` but not `oneOf`, so the schema
cleaner's allowlist silently dropped `oneOf` — erasing the structure of
discriminated unions. CopilotKit / AG-UI frontend tools serialize a zod
`discriminatedUnion` to `oneOf` via zod-to-json-schema, so any frontend
tool with such a parameter reached Gemini as a bare `{description}` object
with no fields, and the model would invent a shape.
Map `oneOf` -> `anyOf` (recursively, cleaning each branch) alongside the
existing `examples`/`const` mappings. For tool-argument schemas the
distinction is immaterial — the model emits exactly one branch either way.
Mirrors the prior Gemini-compat fixes (ag-ui-protocol#1919 additionalProperties, ag-ui-protocol#1664
nested required).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jplikesbikes
force-pushed
the
fix/clean-schema-oneof-to-anyof
branch
from
July 16, 2026 13:54
eb1b185 to
b7e1eec
Compare
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.
Fix: map oneOf → anyOf in ADK middleware schema cleaner
Problem
google.genai'stypes.SchemaacceptsanyOfbut notoneOf. The ADK middleware's_clean_schema_for_genaifilters tool-parameter schemas through an allowlist derived fromtypes.Schema.model_fields, so anyoneOfkey was silently dropped.This erases the structure of discriminated unions. CopilotKit / AG-UI frontend tools serialize a zod
discriminatedUniontooneOf(viazod-to-json-schema), so any frontend tool with such a parameter reached Gemini as a bare{description}object with no fields — and the model would just invent a shape.Fix
Map
oneOf→anyOfrecursively (cleaning each branch), alongside the existingexamples→exampleandconst→enummappings. For tool-argument schemas theoneOf/anyOfdistinction is immaterial: the model emits exactly one branch either way.This mirrors prior Gemini-compat fixes — #1919 (
additionalProperties) and #1664 (nestedrequired).Changes
client_proxy_tool.py: add theoneOf→anyOfmapping in_clean_schema_for_genai.test_client_proxy_tool.py: add tests covering a flatoneOfmapping and a nested discriminated-union schema where each branch is recursively cleaned ($-keys / rejected keys stripped,const→enum) and the siblingdescriptionis preserved.