refactor(agent): remove legacy image mode prompt injection
This commit is contained in:
@@ -8,7 +8,6 @@ from typing import TYPE_CHECKING, Any
|
||||
from pydantic import Field
|
||||
|
||||
from nanobot.agent.tools.base import Tool, ToolResult, tool_parameters
|
||||
from nanobot.agent.tools.context import RequestContext
|
||||
from nanobot.agent.tools.schema import (
|
||||
ArraySchema,
|
||||
IntegerSchema,
|
||||
@@ -22,7 +21,6 @@ from nanobot.providers.image_generation import (
|
||||
ImageGenerationProvider,
|
||||
get_image_gen_provider,
|
||||
)
|
||||
from nanobot.runtime_context import RuntimeContextBlock
|
||||
from nanobot.security.workspace_access import current_tool_workspace
|
||||
from nanobot.security.workspace_policy import WorkspaceBoundaryError, resolve_allowed_path
|
||||
from nanobot.utils.artifacts import (
|
||||
@@ -31,7 +29,6 @@ from nanobot.utils.artifacts import (
|
||||
store_generated_image_artifact,
|
||||
)
|
||||
from nanobot.utils.helpers import detect_image_mime
|
||||
from nanobot.utils.image_generation_intent import image_generation_runtime_context
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nanobot.config.schema import ProviderConfig
|
||||
@@ -119,18 +116,6 @@ class ImageGenerationTool(Tool):
|
||||
"or user image paths as reference_images."
|
||||
)
|
||||
|
||||
def runtime_context_provider(self):
|
||||
return self._provide_runtime_context
|
||||
|
||||
async def _provide_runtime_context(
|
||||
self,
|
||||
request: RequestContext,
|
||||
) -> RuntimeContextBlock | None:
|
||||
content = image_generation_runtime_context(request.metadata)
|
||||
if not content:
|
||||
return None
|
||||
return RuntimeContextBlock(source="image_generation", content=content)
|
||||
|
||||
def _provider_config(self) -> ProviderConfig | None:
|
||||
return self.provider_configs.get(self.config.provider)
|
||||
|
||||
|
||||
@@ -782,13 +782,6 @@ class WebSocketChannel(BaseChannel):
|
||||
metadata["mcp_presets"] = mcp_presets
|
||||
metadata[WORKSPACE_SCOPE_METADATA_KEY] = scope.metadata()
|
||||
self._workspaces.persist_scope(cid, scope)
|
||||
image_generation = envelope.get("image_generation")
|
||||
if isinstance(image_generation, dict) and image_generation.get("enabled") is True:
|
||||
aspect_ratio = image_generation.get("aspect_ratio")
|
||||
metadata["image_generation"] = {
|
||||
"enabled": True,
|
||||
"aspect_ratio": aspect_ratio if isinstance(aspect_ratio, str) else None,
|
||||
}
|
||||
if metadata.get("webui") is True and self.is_allowed(client_id):
|
||||
self._transcripts.append_user_message(
|
||||
cid,
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
"""Helpers for WebUI image-generation intent metadata."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
IMAGE_GENERATION_METADATA_KEY = "image_generation"
|
||||
|
||||
|
||||
def image_generation_prompt(content: str, metadata: dict[str, Any] | None) -> str:
|
||||
"""Decorate a user prompt when WebUI image mode is enabled."""
|
||||
runtime_context = image_generation_runtime_context(metadata)
|
||||
return f"{content}\n\n{runtime_context}" if runtime_context else content
|
||||
|
||||
|
||||
def image_generation_runtime_context(metadata: dict[str, Any] | None) -> str:
|
||||
"""Return the model-only instruction for WebUI image generation mode."""
|
||||
raw = (metadata or {}).get(IMAGE_GENERATION_METADATA_KEY)
|
||||
if not isinstance(raw, dict) or raw.get("enabled") is not True:
|
||||
return ""
|
||||
|
||||
aspect_ratio = raw.get("aspect_ratio")
|
||||
if isinstance(aspect_ratio, str) and aspect_ratio.strip():
|
||||
instruction = (
|
||||
"The user selected WebUI image generation mode. Use the generate_image tool. "
|
||||
f"When calling generate_image, pass aspect_ratio={aspect_ratio!r}."
|
||||
)
|
||||
else:
|
||||
instruction = (
|
||||
"The user selected WebUI image generation mode. Use the generate_image tool. "
|
||||
"Choose the most suitable aspect_ratio yourself from the prompt and intended use."
|
||||
)
|
||||
return f"[WebUI image generation instruction: {instruction}]"
|
||||
Reference in New Issue
Block a user