refactor(tools): use structured tool error results

This commit is contained in:
chengyongru authored and Xubin Ren committed 2026-07-01 13:03:47 +08:00
1 parent 8d2c31eb6a
commit 8493560976
20 files changed
+294 -188

No files matched your search

+4 -4
View File
@@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Any
from pydantic import Field
from nanobot.agent.tools.base import Tool, tool_parameters
from nanobot.agent.tools.base import Tool, ToolResult, tool_parameters
from nanobot.agent.tools.schema import (
ArraySchema,
IntegerSchema,
@@ -172,11 +172,11 @@ class ImageGenerationTool(Tool):
) -> str:
client = self._provider_client()
if client is None:
return f"Error: unsupported image generation provider '{self.config.provider}'"
return ToolResult.error(f"Error: unsupported image generation provider '{self.config.provider}'")
requested = count or 1
if requested > self.config.max_images_per_turn:
return (
return ToolResult.error(
"Error: count exceeds tools.imageGeneration.maxImagesPerTurn "
f"({self.config.max_images_per_turn})"
)
@@ -206,4 +206,4 @@ class ImageGenerationTool(Tool):
break
return generated_image_tool_result(artifacts)
except (ArtifactError, ImageGenerationError, OSError) as exc:
return f"Error: {exc}"
return ToolResult.error(f"Error: {exc}")