fix(genai): improve tool config, response metadata, and structured output#10434
Open
pawel-twardziak wants to merge 4 commits intolangchain-ai:mainfrom
Open
Conversation
🦋 Changeset detectedLatest commit: af1aafd The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Improves
@langchain/google-genaiprovider with tool config handling, response metadata, structured output defaults, and modernized tests.Changes
Core (
chat_models.ts,utils/common.ts)tool_choice: "none"fallback: Whentool_choiceis set to"none"but no tools are provided (e.g. afterbindTools([], { tool_choice: "none" })),invocationParamsnow emitstoolConfig: { functionCallingConfig: { mode: FunctionCallingMode.NONE } }. Previously, the"none"choice was silently ignored whenoptions.toolswas empty becauseconvertToolsToGenAIwas never called.response_metadata.model: BothmapGenerateContentResultToChatResult(invoke) andconvertResponseContentToChatGenerationChunk(stream) now include the model name inresponse_metadata, matching the pattern used by other LangChain providers (OpenAI, Anthropic).model_provider: "google-genai"was already present for streaming and is now also added to the non-streaming path.withStructuredOutputmethod: Themethodparameter now defaults to"functionCalling"instead ofundefined, making the behavior explicit and consistent with other providers.ls_structured_output_formatmetadata:withStructuredOutputnow attachesls_structured_output_format(withkwargs.methodandschema) to the config for both"functionCalling"and"jsonSchema"paths, enabling LangSmith to track which structured output strategy was used.Tests
invocationParamswithtool_choice: "none"(with and without tools).tool_choice: "none"viabindTools(both invoke and stream).gemini-2.0-flash/gemini-1.5-pro/gemini-1.5-flashtogemini-2.5-flash.model: "gemini-embedding-001"to all embedding integration tests.GoogleSearchRetrievalTooltests: Skipped (describe.skip) -google_search_retrievalis no longer supported by current models; newer models usegoogle_searchinstead.describe.skipIf(!videoFileExists)so the suite is skipped gracefully when the large video fixture is not downloaded.toBetotoBeGreaterThanOrEqualfortotal_tokenschecks and increasedmaxOutputTokensfrom 10 to 256 to avoid truncation flakiness.as anycasts ininvocationParamstest calls withas Partial<GoogleGenerativeAIChatCallOptions>.tool_call_conversion.test.tsfrom@langchain/google-genai(package self-reference) to relative../chat_models.js.Related to #10432
This PR fixes the same problem, but for `@langchain/google-genai
Changes have been verified with the current state of the official docs for Google AI
integration tests
90% of the tests were not valid any longer; all fixed
unit tests