-
Notifications
You must be signed in to change notification settings - Fork 270
[genai, vertexai]: Add anyOf
support for Union
types in tool calling
#992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[genai, vertexai]: Add anyOf
support for Union
types in tool calling
#992
Conversation
…dg/langchain-google into fix/union-type-tool-calling merge
@msaadg integration tests are failing |
@lkuligin It seems that the failing integration tests in vertexai are unrelated to the changes I made. There were no new updates on this PR, and the integration tests transitioned from passing to failing automatically. Could you please confirm? |
you got - "can't create service account key on gcp", yet its important to check IT with gemini imho |
@lkuligin the integration tests are now passing! |
Hey, any updates on the merge? We’re eager to get it through since it’s key to resolving an urgent issue on our side. 🙏 |
@msaadg thanks a lot for your contribution. approved, next time, please, split different libraries in different PRs since it would be easier to review and release then. |
PR Description
This PR adds support for Union types in tool arguments for Gemini tool calling in both
langchain_google_genai
andlangchain_google_vertexai
. Previously, Union types causedInvalidArgument
errors inChatVertexAI
and incomplete schema handling inChatGoogleGenerativeAI
. The fix introducesanyOf
schema support to represent all Union type variants, ensuring compatibility with Gemini’s API. Additionally,bind_tools
docstrings are updated to document this new feature.Relevant issues
Fixes #463 #986
Type
🆕 New Feature
🐛 Bug Fix
📖 Documentation
✅ Test
Changes
_get_properties_from_schema
in_function_utils.py
to supportanyOf
for non-nullable Union types.bind_tools
inchat_models.py
to document Union type support in the docstring.test_function_utils.py
for Union types (simple, primitive, nested, PydanticField
)._format_json_schema_to_gapic
infunctions_utils.py
to handle arbitraryanyOf
types, resolvingInvalidArgument
errors.bind_tools
inchat_models.py
to document Union type support in the docstring.test_function_utils.py
to validate schema conversion andgapic.Schema
compatibility.Optional
fields.Testing
Union[Helper1, Helper2]
)Union[str, Helper]
)List[Union[str, Contact]]
)Field
with Union types and metadataOptional
fieldsgapic.Schema
compatibility (for Vertex AI).make test
.Note
genai
andvertexai
packages due to the shared nature of tool calling functionality with Gemini.