Skip to content

feat(py): core support for background model operations and typed model refs - #5854

Closed
cabljac wants to merge 31 commits into
mainfrom
jh-interactions-1-core
Closed

cabljac wants to merge 31 commits into
mainfrom
jh-interactions-1-core

Conversation

@cabljac

@cabljac cabljac commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

First slice of the #5806 split: FinishReason.ABORTED (typing + genkit-schema.json), a cancel-operation action kind with registry lookup, background operation lifecycle updates, generate_operation/check_operation plumbing, and a config_schema parameter on model_ref.

Stack (split of #5806)

  1. feat(py): core support for background model operations and typed model refs #5854 core support for background model operations and typed model refs
  2. feat(py/plugins/google-genai): raw Interactions HTTP client, converters, and options #5855 Interactions HTTP client, converters, and options
  3. feat(py/plugins/google-genai): Deep Research, Antigravity, and Lyria interaction models #5856 Deep Research, Antigravity, and Lyria interaction models
  4. refactor(py/plugins/google-genai): move Veo to background model actions #5857 move Veo to background model actions
  5. feat(py/plugins/google-genai): wire Interactions models into GoogleAI plugin #5858 wire Interactions models into GoogleAI plugin
  6. feat(py/plugins/google-genai): finish_message for image models and effective config echo #5859 gemini finish_message (parallel, based on this PR)

The split originally reproduced #5806 byte-for-byte; this slice has since picked up review fixes. Work co-authored with @huangjeff5.

Breaking changes

  • ModelRequest(config={...}) keeps the dict instead of coercing into ModelConfig; ModelRequest[PluginConfig] coerces dicts into the plugin schema and rejects mismatched config instances. Values that are neither BaseModel nor dict raise TypeError.
  • Bare ModelRequest.config is no longer typed ModelConfig | None: it resolves to Unknown | None under pyright, so attribute access on it is unchecked. Bind ModelRequest[YourConfig] for typed access.

Cross-language files

The aborted finish reason already exists in the JS runtime; this PR syncs the tools zod source, the generated genkit-schema.json, and Go's generated go/ai/gen.go (CI enforces all three). No hand-written Go or tools changes.

@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 enhances background model support and model configuration validation in the Python SDK. Key changes include adding the 'aborted' finish reason, allowing background models to return an Operation to poll, improving model resolution with helpful namespace hints, and refining ModelRequest config validation to gracefully handle plugin-specific schemas and dicts. The feedback suggests optimizing the input validation path in _action.py to avoid the overhead of catching ValidationError on every model call by checking and dumping BaseModel inputs upfront.

@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.

Overall, the CL looks good but there are two things we may want to change before this
lands, both in the config validation, and they interact:

  1. mode='plain' on _validate_config replaces more than the validator. The JSON schema for config comes back as {"default": null, "title": "Config"} (define_background_model feeds exactly that into _override_input_schema), the serializer goes with it so every traced call logs a PydanticSerializationUnexpectedValue warning, and the annotation no longer matches what the field accepts at runtime, which is why pyright fails on this PR's own tests under just lint (CI only checks packages/*/src). The dev UI does still get the real schema via customOptions, same as JS, so the inputSchema loss is mostly a regression against main's $ref. I provided more details inline.

  2. The _validate_input retry never fires for the case its own comment describes. I patched it to count and ran that flow, 0 retries. Pydantic revalidates instances that share the generic origin, so a bare ModelRequest is taken on the first pass, and when the config is already a model instance it passes through untouched, so the action's schema doesn't win there either. When the retry does fire on a ModelRequest (it is reachable, via a same-shape foreign BaseModel, just not from this path) the model_dump round-trip silently drops output config.

These two are coupled: if 1 moves off mode='plain', wrong-typed instance configs start
failing first-pass validation, the retry in 2 becomes the thing that rescues them, and
its output drop goes live. Whatever the fix is, it probably wants to land as one change.

Everything else is comment-level and left inline.

@cabljac
cabljac force-pushed the jh-interactions-1-core branch from c0440db to 395d4d6 Compare August 4, 2026 08:52
@cabljac

cabljac commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Both config issues fixed in 286e225 as one change, as you suggested.

  1. Dropped mode='plain'. Config is now a left_to_right union (dict | SerializeAsAny[ConfigT] | None) with a before-validator doing only the dict coercion, so the core schema survives: $ref back in inputSchema, no serializer warnings, mismatched instances rejected at the boundary. A TYPE_CHECKING split keeps config: ConfigT | None for type checkers, which also clears the pyright errors on this PR's tests.

  2. With the stricter union, cross-schema instance configs now fail first-pass, so the retry is the live rescue path its comment describes. The output drop is fixed by unnesting the wire output key on validation; round-trip test covers your repro.

Namespace hint, cancel coverage, and the breaking-changes note are in follow-up commits. Can you take another look?

@cabljac
cabljac requested a review from hilariie August 4, 2026 10:03

@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.

LGTM

cabljac and others added 9 commits August 6, 2026 10:31
…l refs

Core plumbing extracted from #5806: FinishReason.ABORTED (schema + typing),
cancel-operation action kind and registry lookup, background operation
lifecycle updates in _background.py, generate_operation/check_operation
plumbing in _ai, and a config_schema parameter on model_ref.

Co-authored-by: Jeff Huang <huangjeff@google.com>
…nishReason

Regenerates go/ai/gen.go from genkit-schema.json (FinishReasonAborted) and
narrows the runtime-parameterized ModelRequest cast to type[BaseModel] to
match _override_input_schema's signature.

Co-authored-by: Jeff Huang <huangjeff@google.com>
mode='plain' replaced the field's core schema, so the config JSON schema
collapsed to an empty object, every traced dump warned, and mismatched
config instances passed validation. The field is now a left-to-right
union (dict | SerializeAsAny[ConfigT] | None) with a before-validator
coercing dicts into the bound schema; type checkers see ConfigT | None
with a shadow __init__ that accepts dicts. Validation also unnests the
wire output key so model_dump round-trips keep output config, which the
action input retry relies on when re-validating cross-schema configs.
Hardcoded googleai/vertexai suggestions misdirect users of other
plugins; build the hint from the registry's plugin names instead.
…config_json_schema_refs_plugin_schema and test_model_request_dump_emits_no_serializer_warnings
@hilariie

hilariie commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded. Background operations, cancel_operation, the aborted finish reason and typed model ref configs all landed on main through other PRs (#6130, #6674, #6757, #6777).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants