Skip to content

fix(py/google-genai)!: Interactions models take extra; per-request timeout is seconds and comes to Gemini - #6646

Merged
huangjeff5 merged 37 commits into
mainfrom
fix/py-interactions-config-strict
Nov 2, 2026
Merged

huangjeff5 merged 37 commits into
mainfrom
fix/py-interactions-config-strict

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Antigravity, Interactions Lyria and Deep Research run on the Interactions API, and on main they had no extra. Main's GenkitConfig already rejects unknown keys (#6697), and its error even says "put provider-only settings in config['extra']", but these three configs had no extra field. They now take extra, deep-merged into the create body. Their per-request timeout is now seconds, like every other Genkit Python timeout, and Gemini models get the same per-request timeout, which Go and JS already have.

# --- BEFORE ---
# 1. An undeclared Interactions field had no way in
await ai.generate_operation(
    model='googleai/deep-research-preview-04-2026',
    prompt='Summarize recent advances in quantum error correction.',
    config={'extra': {'agent_config': {'visualization': 'auto'}}},
)
# => INVALID_ARGUMENT: unknown config key 'extra'

# 2. timeout was milliseconds, inherited from google-genai
config={'timeout': 30000}

# --- AFTER ---
# 1. extra deep-merges into the create body; the caller's key wins
await ai.generate_operation(
    model='googleai/deep-research-preview-04-2026',
    prompt='Summarize recent advances in quantum error correction.',
    config={'thinking_summaries': 'auto', 'extra': {'agent_config': {'visualization': 'auto'}}},
)
# => agent_config: {'type': 'deep-research', 'thinking_summaries': 'auto', 'visualization': 'auto'}

# 2. None inside extra means unset; the built block is kept
config={'extra': {'agent_config': None}}
# => agent_config: {'type': 'deep-research', ...}

# 3. Fields Genkit builds from the request can't be replaced through extra
config={'code_execution': True, 'extra': {'tools': [{'type': 'url_context'}]}}
# => INVALID_ARGUMENT: extra['tools'] can't be set in extra. Use the declared tool settings: google_search, url_context, code_execution, file_search_store_names, mcp_servers.
config={'extra': {'input': '...'}}
# => INVALID_ARGUMENT: extra['input'] can't be set in extra. Pass the prompt and messages to generate().

# 3b. Function tools on Antigravity (not yet wired in this plugin) and Lyria raise instead of being dropped
await ai.generate(model='googleai/antigravity-preview-05-2026', prompt='hi', tools=['todays_specials'])
# => INVALID_ARGUMENT: Function tools on googleai/antigravity-preview-05-2026 are not yet supported in this plugin.

# 4. timeout is seconds, per request
config={'timeout': 30}

# 5. Gemini models take the same per-request timeout
await ai.generate(model='googleai/gemini-2.5-flash', prompt='Suggest a dish.', config=GeminiConfig(timeout=30))
# => this request's http_options.timeout: 30000 ms; base_url, headers and the rest stay the plugin's

Decisions

  • extra deep-merges, nested dicts key by key. extra={'agent_config': {'visualization': 'auto'}} overrides one key without wiping thinking_summaries. Keys match ignoring case and underscores, the same alignment google-genai uses for Gemini's extra_body.
  • None inside extra means unset, at every level. Pydantic's exclude_none doesn't reach into a dict[str, Any], so extra={'agent_config': None} used to send null over the built block. Genkit already treats None as unset on declared fields and top-level keys. An explicit {} and list items go out as written.
  • Fields built from the request are reserved in extra, like Gemini's managed body fields: the model id (agent, model on Lyria), input, tools, and Lyria's system_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, so tools stays reserved in extra rather than exposing raw wire lists that flat tool flags and generate(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 declare supports.tools=False), so passed tools raise instead of being silently dropped. Deep Research already raised.
  • Request timeout is seconds. Every other Python timeout in Genkit is seconds: Ollama(timeout=), Bedrock's read_timeout / total_timeout, OpenAI and Anthropic client_options, The same goes for the standard library and httpx. google-genai's milliseconds were the outlier. This also applies to Deep Research's check_operation / cancel_operation config, so one value means the same thing on start, check and cancel.
  • Gemini gets a per-request 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-genai http_options.timeout, along with X-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, GeminiTtsConfig and GeminiImageConfig inherit it.

Breaking

  • timeout on AntigravityConfig, DeepResearchConfig and LyriaConfig is seconds, as is timeout in Deep Research's check_operation / cancel_operation config. Divide by 1000: {'timeout': 30000} becomes {'timeout': 30}. An unconverted 30000 waits over 8 hours. 0, negative, inf, NaN and bool raise INVALID_ARGUMENT. In JS, googleai Gemini, Antigravity, and Deep Research checkOperation/cancelOperation read timeout as milliseconds (while JS Deep Research start, Lyria, and vertexai models ignore timeout), so a .prompt file shared across SDKs needs a per-SDK value.
  • extra can't set agent / model, input, tools, or Lyria's system_instruction on these three models. Use generate(model=, prompt=, messages=) and the declared tool settings.
  • generate(tools=...) on Antigravity and Lyria raises instead of silently dropping the tools.
  • GeminiConfig has a new timeout field (seconds). Additive, but a timeout key that used to raise as unknown is now accepted.

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.
…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
…-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
…arch configs reject unknown keys and another plugin's config class
@github-actions github-actions Bot added docs Improvements or additions to documentation python Python fix labels Oct 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

huangjeff5 added a commit that referenced this pull request Oct 7, 2026
…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.
An error occurred while trying to automatically change base from fix/py-gemini-config-strict to fix/py-model-config-any-model October 8, 2026 05:17

@cabljac cabljac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
@huangjeff5 huangjeff5 changed the title fix(py/google-genai)!: Antigravity, Interactions Lyria, Deep Research reject unknown keys and other plugins' configs fix(py/google-genai)!: Interactions models take extra; per-request timeout is seconds and comes to Gemini Oct 30, 2026
@huangjeff5
huangjeff5 requested a review from cabljac October 30, 2026 22:44
…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 hilariie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@huangjeff5

Copy link
Copy Markdown
Contributor Author

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 agentConfig camelCase merge test and end-to-end generate() / generate_stream() Gemini timeout tests, and scoped the JS timeout note in Breaking to googleai Gemini, Antigravity, and Deep Research check/cancel.

@huangjeff5
huangjeff5 added this pull request to stack #7023 November 2, 2026 18:32
@huangjeff5
huangjeff5 merged commit f3e71c5 into main Nov 2, 2026
32 checks passed
@huangjeff5
huangjeff5 deleted the fix/py-interactions-config-strict branch November 2, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation fix python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants