Repository navigation
fix(py/plugins)!: OpenAI tool_choice after tool turns, integer topK, evaluator typing - #6696
Merged
Merged
Conversation
google-genai types GenerateContentConfig.top_k as float, so building the config coerced 40 to 40.0 and the generateContent body carried "topK": 40.0 on both GoogleAI and Vertex. The API defines topK as int32. Reassign the int after construction; the SDK doesn't validate on assignment. AnthropicConfig inherits top_k: float from ModelConfig, so the dumped params sent "top_k": 40.0. Convert integral values to int, as max_tokens already is. Other int knobs (maxOutputTokens, candidateCount, seed, logprobs) were already ints. Ollama coerces through ollama.Options; OpenAI drops top_k.
The OpenAI model forced tool_choice='none' whenever history held a tool message, whatever the caller asked for. So after one tool result the model couldn't call another tool: no multi-step chaining, and tool_choice='required' was dropped from the second turn on. The rule came in with the DeepSeek plugin (#4051) with no stated reason; it stopped a 'required' run from re-forcing tool calls forever. Core's max_turns already bounds that loop, as it does for Anthropic, Gemini and Go compat_oai, which pass the value through. Genkit's auto/required/none are OpenAI's values, so they go out unchanged and None sends nothing. tool_choice now rides only with tools: OpenAI rejects it without them. Vertex AI Model Garden's OpenAI-compatible models build the same OpenAIModel, so they get the fix too.
Contributor
There was a problem hiding this comment.
Code Review
This pull request addresses type coercion and parameter handling across several Genkit provider packages. Specifically, it ensures that integer sampling parameters (like top_k) are correctly serialized as integers rather than floats for Anthropic and Google GenAI models. It also updates the Django package's __all__ export, refactors Google GenAI's evaluator resolution to support Python 3.10 StrEnum type-checking, and refactors OpenAI's tool_choice logic to allow tool chaining and avoid sending tool_choice when no tools are defined. Relevant unit and integration tests have been added to verify these behaviors. There are no review comments, so I have no feedback to provide.
cabljac
approved these changes
Oct 12, 2026
This was referenced Oct 12, 2026
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.
Three small fixes for plugin bugs on
main: OpenAI keeps the caller'stool_choiceafter a tool turn; Gemini and Anthropic sendtopKas an integer on the wire; and Vertex evaluator metric lookup type-checks underpyreflyon Python 3.10.Decisions
tool_choice='none'once history held any tool message, so after one tool result the model could not call a second tool,'required'was dropped from the second turn on, and an old tool turn (role='tool') in history whenrequest.toolswas empty senttool_choice='none'withouttools(which OpenAI rejects with 400). Now, with notool_choiceset, the model can call tools again after a tool round (bounded bymax_turns);'required'forces a tool call every turn untilmax_turnsstops the loop (matching Anthropic and Gocompat_oai); and whenrequest.toolsis empty,tool_choiceis omitted even if history contains a prior tool round.google-genai2.21 typesGenerateContentConfig.top_kasOptional[float], even though the Gemini API definestopKasint32, turning40into40.0duringGenerateContentConfig(**known)validation. We assign the integer back after constructing the SDK config so it serializes as aninton both Google AI and Vertex AI. Anthropic had the same issue viaAnthropicConfig.top_k: float(inherited fromModelConfig);_build_paramsnow converts integral floats toint, matching how it handlesmax_tokens.pyreflyruns withpython_version = "3.10", whereStrEnumcomes from thestrenumbackport whose stub types__new__as returning the baseStrEnuminstead of the subclass. Looking upVertexAIEvaluationMetricTypeby iterating members and matching.valuepreserves theVertexAIEvaluationMetricTypesubtype without casts or suppressions.