Repository navigation
Conversation
There was a problem hiding this comment.
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.
c0b14c3 to
2a2ad94
Compare
hilariie
left a comment
There was a problem hiding this comment.
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:
-
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.
-
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.
c0440db to
395d4d6
Compare
|
Both config issues fixed in 286e225 as one change, as you suggested.
Namespace hint, cancel coverage, and the breaking-changes note are in follow-up commits. Can you take another look? |
…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.
…e hint" This reverts commit 5cd304b.
…e isinstance guard
…ground model module
…ion in _validate_input
…mismatch fallback
…to nested OutputConfig PR
…config_json_schema_refs_plugin_schema and test_model_request_dump_emits_no_serializer_warnings
bb8be01 to
fb3cbf1
Compare
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 aconfig_schemaparameter onmodel_ref.Stack (split of #5806)
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 intoModelConfig;ModelRequest[PluginConfig]coerces dicts into the plugin schema and rejects mismatched config instances. Values that are neitherBaseModelnor dict raiseTypeError.ModelRequest.configis no longer typedModelConfig | None: it resolves toUnknown | Noneunder pyright, so attribute access on it is unchecked. BindModelRequest[YourConfig]for typed access.Cross-language files
The
abortedfinish reason already exists in the JS runtime; this PR syncs the tools zod source, the generatedgenkit-schema.json, and Go's generatedgo/ai/gen.go(CI enforces all three). No hand-written Go or tools changes.