The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(image_gen): describe Krea image inputs as style references so the model stops rewriting the style into the prompt
Mariano Nicolinibcf216d461e2
diff --git a/agent/image_gen_provider.py b/agent/image_gen_provider.pyindex 927586dda4f..447a2cf3799 100644--- a/agent/image_gen_provider.py+++ b/agent/image_gen_provider.py@@ -34,8 +34,9 @@ class ImageGenProvider(CatalogProviderBase):def capabilities(self) -> dict[str, Any]:"""``modalities`` (``"text"`` and/or ``"image"``) and ``max_reference_images``; optionally- ``supports_upscale`` (bool) and ``creative_controls`` (names from the tool's creative-control- vocabulary: ``creativity``, ``intensity``, ``complexity``, ``movement``). Surfaced in the+ ``supports_upscale`` (bool), ``creative_controls`` (names from the tool's creative-control+ vocabulary: ``creativity``, ``intensity``, ``complexity``, ``movement``) and+ ``source_image_role`` (``"style"`` when image inputs set the look and are not edited). Surfaced in thedynamic tool schema so the model knows when ``image_url`` / ``upscale`` / each control ishonored, and only declared controls are passed to :meth:`generate`; the text-only defaultkeeps non-overriding providers backward compatible."""diff --git a/plugins/image_gen/krea/__init__.py b/plugins/image_gen/krea/__init__.pyindex e558c4e6276..45504d67304 100644--- a/plugins/image_gen/krea/__init__.py+++ b/plugins/image_gen/krea/__init__.py@@ -460,6 +460,7 @@ class KreaImageGenProvider(StaticImageGenProvider):return {"modalities": ["text", "image"], "max_reference_images": _MAX_STYLE_REFERENCES,"supports_upscale": True, "creative_controls": ["creativity", *_K2_SLIDERS],+ "source_image_role": "style",}def generate(diff --git a/tests/tools/test_image_generate_schema.py b/tests/tools/test_image_generate_schema.pyindex f2698b26a1c..f4fb5893ee0 100644--- a/tests/tools/test_image_generate_schema.py+++ b/tests/tools/test_image_generate_schema.py@@ -131,6 +131,17 @@ class TestDynamicParamGating(unittest.TestCase):for model in (self._t2i_only(), self._edit_multi_ref()):self.assertFalse(set(ig._CREATIVE_CONTROL_PARAMS) & set(self._schema_for(model)["parameters"]["properties"]))+ def test_style_reference_backend_describes_image_inputs_as_style_not_edit(self):+ """A backend declaring source_image_role "style" gets the style wording; FAL keeps the edit wording."""+ with patch.object(ig, "_read_configured_image_provider", return_value="nous"), \+ patch.object(ig, "_read_configured_image_model", return_value="krea-2-medium"):+ krea = _build_dynamic_image_schema()+ fal = self._schema_for(self._edit_multi_ref())+ self.assertIs(krea["parameters"]["properties"]["image_url"], ig._STYLE_IMAGE_URL_PARAM)+ self.assertIs(fal["parameters"]["properties"]["image_url"], ig._IMAGE_URL_PARAM)+ self.assertNotIn("edit", krea["parameters"]["properties"]["reference_image_urls"]["description"])+ self.assertIn("edit", fal["parameters"]["properties"]["reference_image_urls"]["description"])+def test_static_schema_carries_no_capability_args(self):"""The registration-time placeholder must stay minimal — dynamicoverrides own the capability args (do-not-re-add guard)."""diff --git a/tools/image_generation_tool.py b/tools/image_generation_tool.pyindex 883898fbd2c..d5271a70787 100644--- a/tools/image_generation_tool.py+++ b/tools/image_generation_tool.py@@ -830,6 +830,8 @@ def _active_image_capabilities() -> dict[str, Any]:info["supports_upscale"] = bool(caps.get("supports_upscale"))if caps.get("creative_controls"):info["creative_controls"] = list(caps["creative_controls"])+ if caps.get("source_image_role") == "style":+ info["source_image_role"] = "style"return infoexcept Exception:pass@@ -876,6 +878,15 @@ _CREATIVE_CONTROL_PARAMS = {},}+_STYLE_IMAGE_URL_PARAM = {+ "type": "string",+ "description": (+ "Style reference: its look is copied, the image itself is not edited. "+ "A public URL or an absolute local file path. Describe the subject in "+ "the prompt. Omit for text-to-image."+ ),+}+_UPSCALE_PARAM = {"type": "boolean","description": (@@ -902,19 +913,26 @@ def _build_dynamic_image_schema() -> dict[str, Any]:static_props = IMAGE_GENERATE_SCHEMA["parameters"]["properties"]properties: dict[str, Any] = {"prompt": static_props["prompt"], "aspect_ratio": static_props["aspect_ratio"]}+ style_refs = info.get("source_image_role") == "style"if can_edit:- edit_clause = ", or edit / transform an existing image by passing image_url"- properties["image_url"] = _IMAGE_URL_PARAM+ if style_refs:+ edit_clause = ", or copy the look of reference images passed in image_url"+ properties["image_url"] = _STYLE_IMAGE_URL_PARAM+ refs_desc = f"Up to {max_refs} more style references. URLs or absolute local paths."+ else:+ edit_clause = ", or edit / transform an existing image by passing image_url"+ properties["image_url"] = _IMAGE_URL_PARAM+ refs_desc = (+ f"Up to {max_refs} additional reference images (style, "+ "character, or composition) guiding an edit. URLs or "+ "absolute local paths."+ )if max_refs > 1:properties["reference_image_urls"] = {"type": "array","items": {"type": "string"},"maxItems": max_refs,- "description": (- f"Up to {max_refs} additional reference images (style, "- "character, or composition) guiding an edit. URLs or "- "absolute local paths."- ),+ "description": refs_desc,}else:edit_clause = " (text-to-image only — the active model cannot edit existing images)"diff --git a/website/docs/developer-guide/image-gen-provider-plugin.md b/website/docs/developer-guide/image-gen-provider-plugin.mdindex 47684b8cbda..3f8a603c279 100644--- a/website/docs/developer-guide/image-gen-provider-plugin.md+++ b/website/docs/developer-guide/image-gen-provider-plugin.md@@ -121,7 +121,8 @@ class MyBackendImageGenProvider(ImageGenProvider):# Optional keys: "supports_upscale" (bool) adds an `upscale` param, and# "creative_controls" lists the controls you honor from `creativity`,# `intensity`, `complexity`, `movement`. Only declared controls appear- # in the schema and reach generate() as kwargs.+ # in the schema and reach generate() as kwargs. "source_image_role": "style"+ # tells the model that image inputs set the look and are not edited.return {"modalities": ["text", "image"], "max_reference_images": 4}def generate(