refactor(agent): compose image tools in application runtimes (#6172)

* refactor(agent): move image configuration ownership into tools

* refactor(agent): compose image tools in application runtimes
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-12 17:42:45 +08:00
1 parent e148296d5c
commit 105b772203
22 files changed
+269 -236

No files matched your search

+2
View File
@@ -77,6 +77,7 @@ def build_gateway_services(
channel_runtime_status: Callable[[], dict[str, Any]] | None = None,
mcp_runtime_status: Callable[[], Mapping[str, str]] | None = None,
mcp_reload: Callable[[], Awaitable[dict[str, Any]]] | None = None,
image_generation_reload: Callable[[], Awaitable[dict[str, Any]]] | None = None,
skill_state_action: Callable[[set[str]], None] | None = None,
recovery_action: Callable[[str, dict[str, Any]], Awaitable[dict[str, Any]]] | None = None,
subagent_manager: SubagentManager | None = None,
@@ -145,6 +146,7 @@ def build_gateway_services(
channel_runtime_status=channel_runtime_status,
mcp_runtime_status=mcp_runtime_status,
mcp_reload=mcp_reload,
image_generation_reload=image_generation_reload,
skill_state_action=skill_state_action,
recovery_action=recovery_action,
subagent_manager=subagent_manager,
+32 -3
View File
@@ -11,7 +11,6 @@ from typing import Any, cast
from websockets.http11 import Request as WsRequest
from websockets.http11 import Response
from nanobot.agent.tools.image_generation import request_image_generation_reload
from nanobot.agent.tools.mcp_oauth import MCP_OAUTH_CALLBACK_PATH
from nanobot.api.runtime import ApiRuntime, api_runtime_paths
from nanobot.bus.queue import MessageBus
@@ -73,6 +72,7 @@ _WEBUI_MUTATION_REQUEST_ATTR = "_nanobot_webui_mutation_request"
_CHANNEL_CONNECT_ACTIONS = frozenset({"start", "poll", "cancel"})
_MCP_OAUTH_CALLBACK_URL_MAX_BYTES = 8 * 1024
_MCP_RELOAD_TIMEOUT_SECONDS = 15.0
_IMAGE_GENERATION_RELOAD_TIMEOUT_SECONDS = 5.0
_query_first = contracts.query_first
@@ -233,6 +233,7 @@ class WebUISettingsRouter:
channel_runtime_status: Callable[[], dict[str, Any]] | None = None,
mcp_runtime_status: Callable[[], Mapping[str, str]] | None = None,
mcp_reload: Callable[[], Awaitable[dict[str, Any]]] | None = None,
image_generation_reload: Callable[[], Awaitable[dict[str, Any]]] | None = None,
mcp_oauth_redirect_uri: Callable[[WsRequest], str] | None = None,
) -> None:
self.settings = settings
@@ -248,6 +249,7 @@ class WebUISettingsRouter:
self._channel_runtime_status = channel_runtime_status
self._mcp_runtime_status = mcp_runtime_status
self._mcp_reload = mcp_reload
self._image_generation_reload = image_generation_reload
self._mcp_oauth_redirect_uri = mcp_oauth_redirect_uri
self._mcp_oauth = McpOAuthManager()
self._restart_sections: set[str] = set()
@@ -504,7 +506,7 @@ class WebUISettingsRouter:
update_network=update_network_safety_settings,
nanobot_features_action=nanobot_features_action,
api_runtime=self._api_runtime,
reload_image=lambda: request_image_generation_reload(self.bus),
reload_image=self._reload_image_generation_runtime,
)
def _system_operations(self) -> system_domain.SystemSettingsOperations:
@@ -534,9 +536,36 @@ class WebUISettingsRouter:
) -> tuple[dict[str, Any], bool]:
return await self._capabilities.apply_image_runtime_change(
payload,
lambda: request_image_generation_reload(self.bus),
self._reload_image_generation_runtime,
)
async def _reload_image_generation_runtime(self) -> dict[str, Any]:
if self._image_generation_reload is None:
return {
"ok": False,
"message": "Image generation runtime reload is unavailable. Restart nanobot to apply changes.",
"requires_restart": True,
}
try:
return await asyncio.wait_for(
self._image_generation_reload(),
timeout=_IMAGE_GENERATION_RELOAD_TIMEOUT_SECONDS,
)
except asyncio.TimeoutError:
return {
"ok": False,
"message": "Image generation hot reload timed out.",
"requires_restart": True,
}
except Exception as exc:
self.logger.exception("Image generation hot reload failed")
return {
"ok": False,
"message": "Image generation hot reload failed.",
"requires_restart": True,
"error": str(exc),
}
async def _reload_mcp_runtime(self) -> dict[str, Any]:
if self._mcp_reload is None:
return {
+2
View File
@@ -376,6 +376,7 @@ class GatewayHTTPHandler:
channel_runtime_status: Callable[[], dict[str, Any]] | None = None,
mcp_runtime_status: Callable[[], Mapping[str, str]] | None = None,
mcp_reload: Callable[[], Awaitable[dict[str, Any]]] | None = None,
image_generation_reload: Callable[[], Awaitable[dict[str, Any]]] | None = None,
skill_state_action: Callable[[set[str]], None] | None = None,
recovery_action: (
Callable[[str, dict[str, Any]], Awaitable[dict[str, Any]]] | None
@@ -434,6 +435,7 @@ class GatewayHTTPHandler:
channel_runtime_status=channel_runtime_status,
mcp_runtime_status=mcp_runtime_status,
mcp_reload=mcp_reload,
image_generation_reload=image_generation_reload,
mcp_oauth_redirect_uri=self._mcp_oauth_redirect_uri,
)