Repository navigation
fix(py/google-genai)!: Interactions models take extra; per-request timeout is seconds and comes to Gemini - #6646
Conversation
A dict config is now checked against the config class the model registered, at ai.generate, generate_stream, generate_operation and prompt calls, before anything is sent. An unknown key or a bad value raises GenkitError(INVALID_ARGUMENT) naming the model and the key, with the validation error as cause. ModelConfig rejects unknown keyword arguments and gains extra: dict[str, Any] | None for provider settings a plugin doesn't declare. What's inside extra isn't checked. A ref from ai.lookup_model() for a model with no config class stays unchecked, the same as calling that model by name.
…overrides Typos in config now raise for Gemini, OpenAI, Anthropic and Ollama. Fields not yet declared go in config.extra, which each plugin flattens onto the wire after declared fields (extra wins), matching Go's compat_oai forwardRequestExtra. Fields Genkit builds from the request (messages, tools, response schema, ...) are rejected inside extra.
extra_body would silently replace the model the action resolved. Matches Go's rejectManagedConfig; pin a model with version.
With unknown keys rejected, a config dump only holds declared fields, so the unknown-key mover, the stream pop and the max_tokens fallback can never fire. extra_body now comes only from config.extra.
…g name each other
…oogle_search replaces google_search_retrieval
…-key-raises-main # Conflicts: # py/packages/genkit-middleware/src/genkit_middleware/_fallback.py # py/packages/genkit-middleware/tests/fallback_test.py # py/packages/genkit/src/genkit/_ai/_aio.py
…jects response_format
…-main' into fix/py-model-config-any-model # Conflicts: # py/packages/genkit/src/genkit/_ai/_model.py # py/packages/genkit/tests/genkit/ai/generate_config_keys_test.py
…-key-raises-main # Conflicts: # py/packages/genkit/src/genkit/_ai/_prompt.py
…l-config-any-model
…l-config-any-model
…arch configs reject unknown keys and another plugin's config class
There was a problem hiding this comment.
Code Review
This pull request introduces a strict configuration schema for the Antigravity, Interactions Lyria, and Deep Research models by forbidding unknown keys in their Pydantic configurations. To allow for undocumented API fields, a dedicated extra dictionary field has been added to these configurations, which is safely deep-merged into the top-level request body. Additionally, the model registration has been refactored to use helper functions (model and background_model), and extensive tests have been added to verify these behaviors. There are no review comments to address, so I have no feedback to provide.
…Veo extra guards instances
- Each strict nested Gemini class declares exactly the fields of the
google-genai type it is sent as (SafetySetting.method, ImageConfig
output/person/prominent fields, FunctionCallingConfig
.stream_function_call_arguments, VoiceConfig.replicated_voice_config).
A test pins the field sets, so a new SDK field fails CI, not users.
- code_execution / google_search / url_context dicts validate against
the SDK tool type: a bad key raises INVALID_ARGUMENT with its dotted
path instead of FAILED 'internal error'. False attaches no tool.
- attach_config_extra takes the family's managed body fields; Veo
rejects extra={'instances': ...} and keeps the plugin's extra_body.
- Drop Veo's unreachable leftovers branch and api_key re-checks.
- Leave the unused _lyria.LyriaConfig untouched; Interactions Lyria
strictness lands in #6646.
cabljac
left a comment
There was a problem hiding this comment.
A few comments/questions. The main one is the README line about managed fields.
…onfig-strict Main landed #6697 (GenkitConfig, extra='forbid'), #6698 (flat Deep Research config, McpServerConfig TypedDict), #6757/#6766/#6777 (Model/BackgroundModel classes, ModelContext). Conflicts were only in this PR's files. Resolution: take main's version of _antigravity.py, _deep_research.py and _interactions_lyria.py, then re-apply this PR's net change on top: the `extra` field (EXTRA_DESCRIPTION), the class docstrings, and deep_merge(create_kwargs, extra) at create_interaction. The model() / background_model() builder and persist() removal from the PR are superseded by main's Model/BackgroundModel. Tests: keep main's test_lyria_rejects_unknown_config_fields; drop the PR's nested-key typo test (main's McpServerConfig deliberately passes unknown keys through, and nested file_search is now rejected by main's reject_nested_file_search with its own tests) and the PR's top-level `extra={'temperature': ...}` Lyria test (covered by the generation_config one).
`extra={'agent_config': None}` on Deep Research sent "agent_config": null
over the built block and dropped type/thinking_summaries/visualization.
None now means unset inside `extra`, the same as for declared fields
(exclude_none) and for top-level config keys in core: pop_extra() drops
None at every dict level, and a dict that held only None values. An
explicit {} and list items go out as written.
Addresses review thread on _sdk_config.py (cabljac).
…p built tools
`code_execution=True` plus `extra={'tools': [...]}` sent only the extra
list: deep_merge replaces lists, so the built code_execution tool was
dropped silently. Before `extra`, built tools won over a passthrough
`tools` key.
Now that combination raises INVALID_ARGUMENT naming the built tool types,
before any job starts. `extra['tools']` with no declared tool settings
still goes out as written, since that is the only way to send a tool type
DeepResearchConfig doesn't declare. Gemini, Anthropic, and OpenAI all
reject an `extra` key that collides with a field Genkit builds; this keeps
that rule but only when the collision is real. Raising also leaves room to
switch to appending later without breaking anyone.
Addresses review thread on _deep_research.py (cabljac).
`timeout` on AntigravityConfig, DeepResearchConfig, and LyriaConfig was milliseconds. It is now float seconds, keeping the name: the standard library, httpx, requests, aiohttp, and the OpenAI and Anthropic SDKs all mean seconds by `timeout`, and #6826 makes GoogleAI(timeout=...) seconds too, so the plugin ends up with one name and one unit. The same applies to `timeout` in check_operation/cancel_operation `config` for Deep Research, so one value means the same thing on start, check, and cancel. 0, negative, inf, and NaN raise INVALID_ARGUMENT with the same message as #6826 ("timeout must be a positive, finite number of seconds"). The field description and class docstrings carry the ms -> s migration note. ClientOptions.timeout stays milliseconds on purpose: #6826 builds ClientOptions(timeout=<ms>) from the plugin's HttpOptions and rewrites _options.py/_client.py, so the conversion happens once, in client_overrides_from_config / client_overrides_from_call_config, rounding up to whole ms like #6826. Dropping the internal ms helper (_client.timeout_seconds) is a follow-up once both PRs land. BREAKING CHANGE: config={'timeout': 30000} on Antigravity, Deep Research, or Interactions Lyria now waits 30000 seconds. Divide by 1000.
Follow-ups from a local red-team pass on the seconds change:
- check/cancel `config={'timeout': 'abc'}` (or a list) raised a raw
TypeError; it now raises INVALID_ARGUMENT. A numeric string like '5' is
still read as a number, as ClientOptions did before.
- timeout=1e306 passed validation and then hit OverflowError in
math.ceil; values whose milliseconds overflow now fail validation.
- timeout=True was coerced to 1.0 by pydantic before the after-validator
ran; a before-validator rejects bool on the configs too.
- round before ceil so 2.007 s is 2007 ms, not 2008.
- docstrings no longer point at GoogleAI(timeout=...), which only exists
once #6826 lands; README gets the ms -> s migration line.
Tests: case-folded TOOLS / t_o_o_l_s, MCP / file search / search tools
colliding with extra['tools'], extra={'tools': []}, bad timeouts on check
and cancel.
…; per-request timeout on Gemini models extra['tools'] raises on Deep Research, same as Gemini keeping tools managed. GeminiConfig.timeout (seconds) goes out as the request's http_options.timeout, matching Go httpOptions.timeout and JS config.timeout. Timeout validators move to _sdk_config so Gemini and the Interactions models share them.
…fields; function tools raise The model id (agent / model), input, tools, and Lyria's system_instruction come from generate(), so extra raises on them, like Gemini's managed body fields. generate(tools=...) on Antigravity and Lyria raises instead of being dropped.
hilariie
left a comment
There was a problem hiding this comment.
A couple of the timeout claims don't hold yet. README says the per-request timeout is in seconds "over the plugin's", but the plugin's http_options.timeout is milliseconds on main, and GoogleAI(timeout=) from #6826 hasn't merged. Also JS Deep Research start and Lyria don't read timeout at all, so "JS still takes milliseconds" is only true for Antigravity and check/cancel.
About 16 of the new interactions tests (other config classes, unknown keys, saved handles, list_actions schema) pass unchanged against main, so they don't cover this change. Meanwhile nothing checks that a camelCase key like agentConfig merges into the built block, and the Gemini timeout is only tested at the config builder, not through generate or streaming.
…m migration text and redundant tests
|
addressed the top-level review items in 732f99e: dropped "over the plugin's" from README, removed the 16 interactions tests that already pass unchanged on main, added the |
Antigravity, Interactions Lyria and Deep Research run on the Interactions API, and on main they had no
extra. Main'sGenkitConfigalready rejects unknown keys (#6697), and its error even says "put provider-only settings in config['extra']", but these three configs had noextrafield. They now takeextra, deep-merged into the create body. Their per-requesttimeoutis now seconds, like every other Genkit Python timeout, and Gemini models get the same per-requesttimeout, which Go and JS already have.Decisions
extradeep-merges, nested dicts key by key.extra={'agent_config': {'visualization': 'auto'}}overrides one key without wipingthinking_summaries. Keys match ignoring case and underscores, the same alignment google-genai uses for Gemini'sextra_body.Noneinsideextrameans unset, at every level. Pydantic'sexclude_nonedoesn't reach into adict[str, Any], soextra={'agent_config': None}used to sendnullover the built block. Genkit already treatsNoneas unset on declared fields and top-level keys. An explicit{}and list items go out as written.extra, like Gemini's managed body fields: the model id (agent,modelon Lyria),input,tools, and Lyria'ssystem_instruction. Keys fold the same way as the merge. Deep Research's built-in tools are its declared settings (google_search,url_context,code_execution,file_search_store_names,mcp_servers); Antigravity tool configuration is not yet wired in this plugin, sotoolsstays reserved inextrarather than exposing raw wire lists that flat tool flags andgenerate(tools=...)would collide with later. Blocks with defaults (agent_config,environment) still merge.generate(tools=...)raises on Antigravity and Lyria. Lyria takes no tools and this plugin doesn't wire Antigravity tools yet (both declaresupports.tools=False), so passed tools raise instead of being silently dropped. Deep Research already raised.timeoutis seconds. Every other Python timeout in Genkit is seconds:Ollama(timeout=), Bedrock'sread_timeout/total_timeout, OpenAI and Anthropicclient_options, The same goes for the standard library and httpx. google-genai's milliseconds were the outlier. This also applies to Deep Research'scheck_operation/cancel_operationconfig, so one value means the same thing on start, check and cancel.timeout. Go (httpOptions.timeout) and JS (config.timeout) already have one on Gemini models; Python only had the plugin-level one.GeminiConfig.timeout(seconds, same validation) goes out as this request's google-genaihttp_options.timeout, along withX-Server-Timeout, so per-request timeouts above a plugin-level timeout aren't capped by the header google-genai caches on the shared client. The Gemini API rejects server deadlines under 10s with HTTP 400 (Vertex AI accepts shorter values).GemmaConfig,GeminiTtsConfigandGeminiImageConfiginherit it.Breaking
timeoutonAntigravityConfig,DeepResearchConfigandLyriaConfigis seconds, as istimeoutin Deep Research'scheck_operation/cancel_operationconfig. Divide by 1000:{'timeout': 30000}becomes{'timeout': 30}. An unconverted30000waits over 8 hours. 0, negative, inf, NaN and bool raiseINVALID_ARGUMENT. In JS,googleaiGemini, Antigravity, and Deep ResearchcheckOperation/cancelOperationreadtimeoutas milliseconds (while JS Deep Research start, Lyria, andvertexaimodels ignoretimeout), so a.promptfile shared across SDKs needs a per-SDK value.extracan't setagent/model,input,tools, or Lyria'ssystem_instructionon these three models. Usegenerate(model=, prompt=, messages=)and the declared tool settings.generate(tools=...)on Antigravity and Lyria raises instead of silently dropping the tools.GeminiConfighas a newtimeoutfield (seconds). Additive, but atimeoutkey that used to raise as unknown is now accepted.