Repository navigation
Conversation
The default chat model in both LangChain handlers built ChatAnthropic for "anthropic", ChatBedrockConverse for "bedrock", and ChatOpenAI for anything else, so a config whose provider is Gemini went to OpenAI and failed. - Add a "gemini" branch that builds langchain_google_genai.ChatGoogleGenerativeAI, behind a new optional `google` extra on both packages, with an install hint when it is missing. - Classify every ChatGoogleGenerativeAI constructor key as forwarded, owned, or excluded, rename its three aliases to their fields, and cover the class in the drift, probe, and never-forwarded tests. - The messages handler passes max_retries as max_retries + 1, because the genai client counts attempts and reads 0 as its own default. - Map Gemini's blocking finish reasons to content_filter in the shared table. - Document the extra, the routing, and GOOGLE_API_KEY in both READMEs. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Matches the Gemini rows in the Python telemetry contract (launchdarkly/python-ai-sdk#320) and the Go table (launchdarkly/go-ai-sdk#114). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 80cfbe2. Configure here.
Semconv's well-known value for the Gemini API is gcp.gemini, as Bedrock's is aws.bedrock. Every handler that maps bedrock to aws.bedrock (LangChain, LiteLLM, Vercel, OpenCode, and evaluation spans) now maps gemini the same way, matching launchdarkly/go-ai-sdk#114 and launchdarkly/js-ai-sdk#257. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Semconv's well-known value for the Gemini API is gcp.gemini, as Bedrock's is aws.bedrock. Every handler that maps bedrock to aws.bedrock (LangChain, LiteLLM, Vercel, and evaluation spans) now maps gemini the same way, matching launchdarkly/go-ai-sdk#114 and launchdarkly/python-ai-sdk#320. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…xtra 4.5.2 is the release this support was built and verified against: it normalizes finish reasons to strings, which the content_filter mapping reads, and exposes the reasoning_effort field the thinking_level rename targets. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
4.4.0 through 4.5.2 all report the finish reason as a string and expose reasoning_effort with the thinking_level alias, and the Gemini tests pass on 4.4.0, so the >=4.4 floor stands. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
jeffdupont
left a comment
There was a problem hiding this comment.
Thanks for this. Gemini through LangChain is a real gap, and the tests are thorough (including the real-class reply test). A few things before it can merge, one of them a real bug.
Blocking: this needs the shared cross-SDK contract updated first. Two things here aren't covered by it yet:
- Routing a Gemini config to
ChatGoogleGenerativeAI(detection rule, whichmodel.parametersare forwarded and with what precedence, credentials, the missing-package error, retries, streaming and thought signatures). Today the three SDK PRs differ on several of these (below), which is what the contract step is meant to prevent. - Writing
gcp.geminiforgen_ai.provider.name. The contract currently makes Bedrock (aws.bedrock) the only remapped provider name; every other configured name is written lower-cased as is, so Gemini isgeminitoday.gcp.geminiis the semantic-conventions value and probably the right call, but it changes existing span output (LiteLLM, Vercel, evaluations too), so it should land as a contract change covering all three SDKs, the way the Bedrock rename did.
The code direction looks right; once the contract change is agreed, the SDKs can align to it.
Blocking: streaming Gemini tool calls lose their thought signatures. The streaming tool loop rebuilds the assistant turn as AIMessage(content=..., tool_calls=...) and drops the gathered chunk's additional_kwargs, where langchain-google-genai keeps the function-call thought signatures. Gemini 3 rejects the next turn without them, so multi-turn tool calling breaks on the streaming path. JS (#257) and Go (#114) both carry the signature across. Please keep the signature-bearing metadata when rebuilding the message, and add a two-turn streaming test through the real class.
Should fix: align the Gemini parameter contract across the three SDKs (python-ai-sdk#320, js-ai-sdk#257, go-ai-sdk#114). Today the same AI Config behaves differently:
- thinking: Python takes flat
thinking_budget/thinking_level/reasoning_effort; JS takes nestedthinking_config(and forwardsinclude_thoughts, which Python deliberately drops); Go forwards none. seed,frequency_penalty,presence_penalty: forwarded in Python and Go, dropped in JS.max_output_tokens: Python and JS; Go reads onlymax_tokens.media_resolution: Python only.- both
stopandstop_sequencesset: Python letsstopwin, JS and Go letstop_sequenceswin. - empty
model.name: Python sends"", JS and Go default togemini-2.5-flash. - key env vars: Python and Go read
GOOGLE_API_KEYthenGEMINI_API_KEY; JS documents onlyGOOGLE_API_KEY.
Pick one table (with explicit per-language exceptions where a client can't take a field) and make all three match it.
Should fix: the package guides. packages/langchain-messages/agents.md and packages/langchain-agents/AGENTS.md don't mention the new [google] extra, the Gemini route or its credentials, and still describe only the ChatOpenAI default (the JS and Go PRs updated theirs).
packages/langchain-messages/src/launchdarkly_ai_langchain_messages/handler.py:1565: Streaming tool loop: rebuilding the turn with only content and tool_calls drops additional_kwargs, including Gemini's function-call thought signatures, so the next turn fails on Gemini 3.
| """ | ||
| provider = str((config.get("provider") or {}).get("name") or "openai").lower() | ||
| return "aws.bedrock" if provider == "bedrock" else provider | ||
| return {"bedrock": "aws.bedrock", "gemini": "gcp.gemini"}.get(provider, provider) |
There was a problem hiding this comment.
This is the gemini → gcp.gemini remap (see the first point in the summary): it changes existing span output, so it should wait for the shared contract change.
There was a problem hiding this comment.
The contract change is in https://github.com/launchdarkly/ai-sdks-monorepo/pull/170: gcp.gemini becomes a rename across every handler and the evaluations spans, the same way as Bedrock. This PR already writes it everywhere, and 76554e4 aligns the rest of the Gemini route with the contract.
The streaming tool loop rebuilt the assistant turn from its text and tool calls only, dropping additional_kwargs, where langchain-google-genai keeps each function call's thought signature. Gemini 3 rejects the next turn without it. Carry additional_kwargs and response_metadata over, and test two streamed turns through the real ChatGoogleGenerativeAI. Document the [google] extra, the Gemini route, and its credentials in the package guides. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
@jeffdupont two of your items are in 08fb4b7:
The contract items (the parameter table, thinking keys, and |
Match the Gemini rules in ai-sdks-monorepo TESTING.md (PR 170): - stop_sequences wins over stop; max_output_tokens wins over max_tokens - thinking_level is checked against the five levels and sent in lower case, thinking_budget must be a whole number and is dropped when a level is kept, media_resolution is checked and sent in upper case, and reasoning_effort is no longer read - an empty model name runs on gemini-2.5-flash - the key comes from GOOGLE_API_KEY, then GEMINI_API_KEY, and a run with neither fails before any request with an error naming both - the messages stream path resolves its model inside the root span's guard, so a missing package or key ends the root with ERROR - the streaming tool loop keeps signed text blocks, so a text part's thought signature reaches the next turn Tests cover the retry count against a failing endpoint, the missing package and key cases on both paths, and real-class runs for signatures, the thinking level on the wire, usage, and blocked replies, in both packages. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
The contract change is up for review: https://github.com/launchdarkly/ai-sdks-monorepo/pull/170. It makes
🤖 Generated with Claude Code |

Human
AgentControl offers Gemini as a provider, but a config whose provider is Gemini fails on its first call in the Python LangChain handlers, because the built-in default model only knows Anthropic and Bedrock and sends everything else to OpenAI. With this change,
langchain-messagesandlangchain-agentsbuild a real Gemini model for those configs: install the new[google]extra and setGOOGLE_API_KEY. This matches the Go SDK fix in launchdarkly/go-ai-sdk#114.Bot
Changes
_make_default_chat_modelin both handlers now buildslangchain_google_genai.ChatGoogleGenerativeAIwhen the lowercasedprovider.nameisgemini. The import is lazy, and a missing package raises anImportErrorthat namespip install "launchdarkly-ai-langchain-<package>[google]".google = ["langchain-google-genai>=4.4"]on both packages, next toanthropicandaws. It is also a dev dependency, andscripts/check_packaging.pychecks the new extras._CHAT_GOOGLE_GENERATIVE_AI_FORWARDED_KEYS,_OWNED_KEYS,_EXCLUDED_KEYS, and_RENAMES, classified from the realChatGoogleGenerativeAI.model_fields.temperature,top_p,top_k,seed,frequency_penalty,presence_penalty,max_output_tokens,stop,reasoning_effort,thinking_budget, andmedia_resolution, plus the aliasesmax_tokens,stop_sequences, andthinking_level.model. The class has no alias for it.vertexai,project,location).additional_headers,default_metadata,client_args,model_kwargs).response_mime_type,response_schema), which the handler owns throughoutputFormat.n/candidate_count, because the handler reads one reply.include_thoughtsandthinking_config, which would put thought summaries into the returned content.convert_system_message_to_human,safety_settings,labels,cached_content, and LangChain's runtime fields.tests/never_forwarded.pyaddsgoogle_api_key,client_args,additional_headers,default_metadata,location,cached_content,labels, andsafety_settings.tests/test_never_forwarded_parameters.pychecks the new forwarded list in both modules.max_retries + 1toChatGoogleGenerativeAI. Itsmax_retriesis the genai client's total attempt count, and it reads 0 as "use the Google default", so the extra attempt keepsmax_retries=0meaning no retries. The agents handler has nomax_retriesoption, so nothing changes there.gen_ai.provider.name = "gcp.gemini", the semconv well-known value, as Bedrock writesaws.bedrock. The same mapping now applies in every handler that maps Bedrock (LangChain, LiteLLM, Vercel, OpenCode, and evaluation spans).TELEMETRY-CONTRACT.mdsection 9 and the cross-handler parity tests cover it.usage_metadata, includingcache_read, so no change is needed there.launchdarkly_ai_server/content.pymaps Gemini's blocking reasons (SAFETY,RECITATION,BLOCKLIST,PROHIBITED_CONTENT,SPII,IMAGE_SAFETY) tocontent_filter.STOPandMAX_TOKENSalready mapped.TELEMETRY-CONTRACT.mdhas the new rows.[google]extra, the routing byprovider.name, andGOOGLE_API_KEY(orGEMINI_API_KEY).langchain-google-genai4.5.2 andgoogle-genai. It also moveslangchain-corefrom 1.6.4 to 1.8.4 andlangsmithfrom 0.9.3 to 0.16.0, because the currentlangchain-google-genaineedslangchain-core>=1.8.Tests
model.regiondropped (both packages).ImportErrorinstall hint whenlangchain-google-genaiis missing (both packages).stopwins overstop_sequences(both packages).ChatGoogleGenerativeAIwith only the genai network call stubbed. It checks the output,gen_ai.provider.name, input, output, and cache-read tokens, andcontent_filterfor aSAFETYfinish.max_retries: 7 becomes 8 attempts, 0 becomes 1, a real client gets 8, a configretriesvalue is ignored, and an omitted value is not passed.packages/client/tests/test_content.py.Verification
make lint,make format-check,make typecheck, andmake api-report-checkpass.make test: 4280 passed, 24 skipped.make check-packaging: every extra imports from its built wheel, including both[google]extras.make audit: no known vulnerabilities.GOOGLE_API_KEYhere. A real call before release would confirm the wire shape end to end, including multi-turn tool calls on Gemini 3 models, which need thought signatures.ChatGoogleGenerativeAIcarries those itself.🤖 Generated with Claude Code
Note
Overview
Adds first-class Gemini routing in
langchain-agentsandlangchain-messages: whenprovider.nameis Gemini, handlers lazily buildChatGoogleGenerativeAIvia a new optional[google]extra (langchain-google-genai), with API keys fromGOOGLE_API_KEY/GEMINI_API_KEYonly (never from config).Introduces a full parameter-forwarding contract for Gemini (forwarded / excluded keys,
max_tokens→max_output_tokens,thinking_level/media_resolutionvalidation, default modelgemini-2.5-flash). Messages adjustsmax_retriesto total attempts (+1) for Gemini’s client semantics.Telemetry parity:
gen_ai.provider.namemapsgemini→gcp.geminiacross LangChain, LiteLLM, Vercel, OpenCode, and evaluation spans;to_semconv_finish_reasonmaps Gemini blocking reasons tocontent_filter. Contract and parity tests updated.Streaming/tool loops preserve Gemini 3 thought signatures on replayed assistant turns. Docs, packaging checks, dev deps, and extensive handler/drift tests accompany the change.
Reviewed by Cursor Bugbot for commit 76554e4. Bugbot is set up for automated code reviews on this repo. Configure here.