Skip to content

fix(langchain): allow Gemini 3 models to use ProviderStrategy with tools#34464

Merged
ccurme (ccurme) merged 8 commits intolangchain-ai:masterfrom
thdesc:fix/agents-gemini-provider-strategy
Feb 19, 2026
Merged

fix(langchain): allow Gemini 3 models to use ProviderStrategy with tools#34464
ccurme (ccurme) merged 8 commits intolangchain-ai:masterfrom
thdesc:fix/agents-gemini-provider-strategy

Conversation

@thdesc
Copy link
Copy Markdown
Contributor

@thdesc Théo Deschamps (thdesc) commented Dec 23, 2025

Fixes #34463

Summary

Passing a raw Pydantic model to create_agent(..., response_format=MyModel) defaults to AutoStrategy, which checks _supports_provider_strategy before deciding between ProviderStrategy and ToolStrategy. For Gemini models the helper currently returns False whenever tools are present, so Gemini 3 models end up using ToolStrategy even though they support provider-specific structured output with tools (link). Explicitly passing ProviderStrategy(MyModel) works; only the AutoStrategy detection path is affected.

Impact

  • Gemini 3 users invoking create_agent(..., response_format=MyModel) can’t access Gemini’s native structured output when tools are bound.
  • Agents fall back to ToolStrategy.
  • Users have to know to wrap their schema in ProviderStrategy manually, defeating the convenience of AutoStrategy.

Expected Behavior

  • _supports_provider_strategy should return True for Gemini 3 models when tools are present, so AutoStrategy upgrades to ProviderStrategy automatically.
  • Gemini versions prior to 3 (and the gemini-flash(-lite)-latest aliases until they point to 3-series backends) should continue to fall back to ToolStrategy.

Additional Context

  • Logic resides in libs/langchain_v1/langchain/agents/factory.py::_supports_provider_strategy.
  • Tests in libs/langchain_v1/tests/unit_tests/agents/test_response_format.py cover strategy selection, but there’s currently no case ensuring Gemini 3 + AutoStrategy succeeds.
  • Explicit response_format=ProviderStrategy(...) is a temporary workaround but shouldn’t be required.

@github-actions github-actions bot added langchain `langchain` package issues & PRs fix For PRs that implement a fix labels Dec 23, 2025
@thdesc
Copy link
Copy Markdown
Contributor Author

This should fixe this issue #34463

@github-actions github-actions bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Jan 6, 2026
@mdrxy Mason Daugherty (mdrxy) changed the title fix(langchain): allow Gemini 3 models to use ProviderStrategy with tools fix(langchain): allow Gemini 3 models to use ProviderStrategy with tools Jan 10, 2026
@github-actions github-actions bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Jan 10, 2026
Copy link
Copy Markdown
Collaborator

@ccurme ccurme (ccurme) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ccurme ccurme (ccurme) merged commit 83f81d6 into langchain-ai:master Feb 19, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external fix For PRs that implement a fix langchain `langchain` package issues & PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create_agent falls back to ToolStrategy for Gemini 3 models when tools and response_format are passed

3 participants