refactor(tools): streamline Tool class and add JSON Schema for parameters

Refactor Tool methods and type handling; introduce JSON Schema support for tool parameters (schema module, validation tests).

Made-with: Cursor
This commit is contained in:
Jack Lu
2026-04-04 19:58:44 +08:00
committed by Xubin Ren
parent 9ef5b1e145
commit e7798a28ee
10 changed files with 632 additions and 321 deletions
+9 -18
View File
@@ -2,12 +2,20 @@
from typing import TYPE_CHECKING, Any
from nanobot.agent.tools.base import Tool
from nanobot.agent.tools.base import Tool, tool_parameters
from nanobot.agent.tools.schema import StringSchema, tool_parameters_schema
if TYPE_CHECKING:
from nanobot.agent.subagent import SubagentManager
@tool_parameters(
tool_parameters_schema(
task=StringSchema("The task for the subagent to complete"),
label=StringSchema("Optional short label for the task (for display)"),
required=["task"],
)
)
class SpawnTool(Tool):
"""Tool to spawn a subagent for background task execution."""
@@ -37,23 +45,6 @@ class SpawnTool(Tool):
"and use a dedicated subdirectory when helpful."
)
@property
def parameters(self) -> dict[str, Any]:
return {
"type": "object",
"properties": {
"task": {
"type": "string",
"description": "The task for the subagent to complete",
},
"label": {
"type": "string",
"description": "Optional short label for the task (for display)",
},
},
"required": ["task"],
}
async def execute(self, task: str, label: str | None = None, **kwargs: Any) -> str:
"""Spawn a subagent to execute the given task."""
return await self._manager.spawn(