Fix `ImageGeneration` under `FallbackModel` and `dataclasses.replace`, and compare `Embedder` by identity
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
Why we make these changes
Post-merge follow-ups to #5357 (ImageGenerator), grouped into one PR. None changes what is sent to a provider API.
[!WARNING]
Compatibility impact: Two distinct Embedder instances no longer compare equal, even over the same model (on main any two with the same instrument did), and Embedder is now hashable. ImageGeneration(fallback_subagent_model=...).local and XSearch(fallback_subagent_model=...).local now read None instead of the derived subagent Tool. As a result, two identically configured ImageGenerations or XSearches with fallback_subagent_model now compare equal, and their repr no longer shows local=Tool(...). The dropped-settings warnings shipped in v2.41.0 now backtick setting names and quote model names, and the native-only one names the model it ran on after setting(s); their leading text is unchanged, except that native=False with your own local tool now gets one `ImageGeneration` ignored setting(s) notice instead of `ImageGeneration` ignored direct-only setting(s), whose advice to pass native=False didn't apply.
Why this can ship in a minor release: All three are bug fixes under the version policy's undocumented-behavior exception. Field equality compared only instrument, so Embedders over different models compared equal and the class was unhashable; a derived tool stored on local is what made dataclasses.replace raise (#8095); and the warning text is quoted nowhere in the docs.
Migration: Compare Embedders by identity (is); build the subagent tool with the public image_generation_tool(model=..., native_tool=...) or x_search_tool(model=..., native_tool=...) rather than reading .local; match a warning filter on the message's leading text rather than on the whole message, and on `ImageGeneration` ignored for the native=False notice.
- Under a
FallbackModel,ImageGenerationwith a direct generator, the native tool left enabled (the default), and any dropped setting (dimensions,quality, ...) raisedNotImplementedError: FallbackModel does not have its own model profile.on every run. The per-request notice readctx.model.profile, while routing reads each inner model's profile. - With
native=False, local=<your own tool>, that tool receives none of the capability's settings, yet onlydimensionsand a non-nativeaspect_ratiowarned, with advice that didn't fit; every other setting was dropped silently. dataclasses.replaceonImageGeneration/XSearchwithfallback_subagent_modelraised the fallback-versus-localUserError(#8095).replace(cap, fallback_model=...)still raises, sincereplacealso passes the currentfallback_subagent_model; usefallback_subagent_model=.copy.deepcopyofWrapperModel/WrapperEmbeddingModelhitRecursionError;WrapperImageGenerationModelalready had the guard.Embeddercompared equal across models and was unhashable (#8144).- #8285 (docs half only): no page showed how to get the generated image out of a capability-driven run, and the routing example's custom tool returned
bytes, which reaches the model as base64 text and never lands inToolReturnPart.files.
New public surface
None. gemini-3.1-flash-lite-image joins LatestGoogleModelNames and the four google KnownModelName blocks; the direct Gemini API, Vertex AI and the Gateway all serve it.
User-visible behavior
- The notice reads the profile each request is prepared against: each of a
FallbackModel's models, and a wrapper's own profile (soTemporalModel'susing_model()choice counts). ATemporalModelwhose current model is aFallbackModel, or a model of your own that routes without a profile of its own, gets no notice, since nothing public says which model a request reaches; onmainsuch a model crashed the same way. It warns for, and names, each model whose path drops a setting (qualityon the direct generator,dimensionson the native tool), also in aTemporalDurabilityworkflow; a provider's native tool still ignores a setting it has no field for without a warning. native=Falsewith your ownlocaltool now warns once at construction, naming every setting that tool won't receive.- The subagent tool is derived in
get_toolset, like the direct generator's, so.localkeeps what was declared (None) andreplaceis a plain field copy. Construction still rejects an image-only subagent model or a mistypednative. Embeddercompares and hashes by identity, likeImageGenerator.- New "Getting the Generated Image" section in
docs/capabilities/image-generation.md; the routing example's custom tool returnsBinaryImage.
Not in this PR, deliberately: a static native=ImageGenerationTool(...) instance's native-only settings, model and action='edit' are still dropped silently on the direct fallback, as on main. After dataclasses.replace, the native tool native=True resolves to looks the same as a declared one, so reading the instance would act on settings a copy no longer has. #9495 decides that distinction first.
Verification
tests/test_capability_image_generation.py:test_image_generation_dropped_settings_notice_reads_each_routed_model,test_image_generation_dropped_settings_notice_says_nothing_for_a_model_that_routes_itself(a model of your own without a profile, bare and wrapped),test_image_generation_native_false_with_a_custom_local_tool_warns_for_every_setting_it_ignores,test_image_generation_native_only_notice_keeps_its_shipped_prefix,test_image_generation_replace_clears_a_setting_from_the_direct_fallbacktests/test_fallback_native_factory.py:test_fallback_subagent_model_survives_dataclass_replaceandtest_native_capable_outer_model_skips_the_fallback_subagent(both capabilities)tests/test_capability_native_or_local.py::TestXSearchCapability::test_xsearch_native_false_local_callabletests/models/test_model.py::test_wrapper_model_deepcopy,tests/test_embeddings.py::test_wrapper_embedding_model_deepcopy,tests/test_embeddings.py::test_embedder_compares_by_identitytests/durable_exec/temporal/test_agent.py:test_image_generation_prepare_function_reads_the_model_temporal_selected;test_image_generation_prepare_function_reads_the_model_inside_an_activity, which now pinsunless_nativeand fails when the stamp is dropped;test_image_generation_notice_says_nothing_for_a_temporal_agent_fallback_modelruns aTemporalAgentworkflow over aFallbackModeland gets no noticetests/durable_exec/temporal/test_durability.py:test_durability_image_generation_notice_meets_the_fallback_model_in_workflow_coderuns the notice over aFallbackModelinside aTemporalDurabilityworkflow;test_durability_image_generation_notice_names_the_fallback_member_that_drops_a_setting_in_workflow_codepins the warning that names the member droppingqualityin workflow code
What changes for existing users
A run under a FallbackModel, or a model of your own without a profile, that crashed now completes, and some dropped settings now warn. The three compatibility impacts are in the warning above.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.