refactor(tools): streamline built-in tool descriptions (#6201)

* refactor(tools): streamline built-in tool descriptions

* refactor(tools): retain actionable schema details
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-14 10:34:07 +08:00
1 parent 30e43aec82
commit 6b90e400e4
13 files changed
+68 -136

No files matched your search

+5 -8
View File
@@ -51,11 +51,11 @@ def _append_text(content: str, addition: str) -> str:
"workspace; absolute paths and '..' obey the workspace access policy." "workspace; absolute paths and '..' obey the workspace access policy."
), ),
action=StringSchema( action=StringSchema(
"Operation type: replace or add.", "replace updates a unique text match; add creates a file or appends to an existing one.",
enum=["replace", "add"], enum=["replace", "add"],
), ),
old_text=StringSchema( old_text=StringSchema(
"Exact text to search for in the file. Required for replace.", "Exact text occurring once in the file; required for replace.",
nullable=True, nullable=True,
), ),
new_text=StringSchema( new_text=StringSchema(
@@ -64,7 +64,7 @@ def _append_text(content: str, addition: str) -> str:
), ),
required=["path", "action"], required=["path", "action"],
), ),
description="List of edits to apply. Each edit specifies a file and the change to make.", description="File edits, applied in order.",
min_items=1, min_items=1,
max_items=20, max_items=20,
), ),
@@ -86,11 +86,8 @@ class ApplyPatchTool(_FsTool):
@property @property
def description(self) -> str: def description(self) -> str:
return ( return (
"Default tool for code edits. Supports multi-file changes in a single call. " "Default tool for code edits, including multi-file changes. "
"Provide a list of structured edits, each specifying a file path, action " "Returns a file-change summary. "
"(replace/add), and the exact text to change. "
"Paths are resolved by the current workspace access policy. "
"Set dry_run=true to validate and preview without writing files. "
"Use edit_file only for small exact replacements on a single file." "Use edit_file only for small exact replacements on a single file."
) )
+5 -15
View File
@@ -22,25 +22,19 @@ from nanobot.session.keys import UNIFIED_SESSION_KEY
_CRON_PARAMETERS = tool_parameters_schema( _CRON_PARAMETERS = tool_parameters_schema(
action=StringSchema("Action to perform", enum=["add", "list", "remove"]), action=StringSchema("Action to perform", enum=["add", "list", "remove"]),
name=StringSchema( name=StringSchema("Job label; generated from message if omitted."),
"Optional short human-readable label for the job "
"(e.g., 'weather-monitor', 'daily-standup'). Defaults to first 30 chars of message."
),
message=StringSchema( message=StringSchema(
"REQUIRED when action='add'. Instruction for the agent to execute when the job triggers " "REQUIRED when action='add': non-empty instruction to execute when the job triggers. "
"(e.g., 'Remind me to drink water' or 'Check system status and report'). "
"The final reply goes to the task's saved chat automatically. " "The final reply goes to the task's saved chat automatically. "
"Do not copy the current channel/chat ID or require a message tool call for that reply. " "Do not copy the current channel/chat ID or require a message tool call for that reply. "
"Include other recipients only when the user requests separate sends. " "Include other recipients only when the user requests separate sends."
"Not used for action='list' or action='remove'."
), ),
every_seconds=IntegerSchema( every_seconds=IntegerSchema(
description="Interval in seconds (for recurring tasks)", minimum=1 description="Interval in seconds (for recurring tasks)", minimum=1
), ),
cron_expr=StringSchema("Cron expression like '0 9 * * *' (for scheduled tasks)"), cron_expr=StringSchema("Cron expression like '0 9 * * *' (for scheduled tasks)"),
tz=StringSchema( tz=StringSchema(
"Optional IANA timezone for cron expressions (e.g. 'America/Vancouver'). " "IANA timezone for cron_expr only, e.g. 'America/Vancouver'."
"When omitted with cron_expr, the tool's default timezone applies."
), ),
at=StringSchema( at=StringSchema(
"ISO datetime for one-time execution (e.g. '2026-02-12T10:30:00'). " "ISO datetime for one-time execution (e.g. '2026-02-12T10:30:00'). "
@@ -49,11 +43,7 @@ _CRON_PARAMETERS = tool_parameters_schema(
job_id=StringSchema("REQUIRED when action='remove'. Job ID to remove (obtain via action='list')."), job_id=StringSchema("REQUIRED when action='remove'. Job ID to remove (obtain via action='list')."),
required=["action"], required=["action"],
description=( description=(
"Action-specific parameters: add requires a non-empty message plus one schedule " "add requires exactly one schedule: every_seconds, cron_expr, or at."
"(every_seconds, cron_expr, or at); remove requires job_id; list only needs action. "
"Per-action requirements are enforced at runtime (see field descriptions) so the "
"top-level schema stays compatible with providers (e.g. OpenAI Codex/Responses) that "
"reject oneOf/anyOf/allOf/enum/not at the root of function parameters."
), ),
) )
+5 -7
View File
@@ -559,10 +559,9 @@ class WriteFileTool(_FsTool):
@property @property
def description(self) -> str: def description(self) -> str:
return ( return (
"Create a new file or intentionally replace an entire file with " "Create a file or replace an entire file. "
"the provided content. Overwrites existing files and creates parent " "Overwrites existing files and creates parent directories. "
"directories as needed. For code changes or partial edits, prefer " "Prefer apply_patch for partial edits."
"apply_patch; use edit_file only for small exact replacements."
) )
async def execute(self, path: str | None = None, content: str | None = None, **kwargs: Any) -> str: async def execute(self, path: str | None = None, content: str | None = None, **kwargs: Any) -> str:
@@ -1140,9 +1139,8 @@ class ListDirTool(_FsTool):
@property @property
def description(self) -> str: def description(self) -> str:
return ( return (
"List the contents of a directory. " "List directory contents, skipping common noise directories "
"Set recursive=true to explore nested structure. " "(.git, node_modules, __pycache__, etc.)."
"Common noise directories (.git, node_modules, __pycache__, etc.) are auto-ignored."
) )
@property @property
+6 -8
View File
@@ -41,18 +41,18 @@ if TYPE_CHECKING:
@tool_parameters( @tool_parameters(
tool_parameters_schema( tool_parameters_schema(
prompt=StringSchema( prompt=StringSchema(
"Detailed image generation or edit prompt. Include style, subject, composition, colors, and constraints.", "Detailed image generation or edit instructions.",
min_length=1, min_length=1,
), ),
reference_images=ArraySchema( reference_images=ArraySchema(
StringSchema("Local path of an existing image artifact or user-provided image to use as an edit reference."), StringSchema(""),
description="Optional local image paths. Use generated artifact paths for iterative edits.", description="Existing local image paths for edits, including prior generated artifacts.",
), ),
aspect_ratio=StringSchema( aspect_ratio=StringSchema(
"Optional output aspect ratio, e.g. 1:1, 16:9, 9:16, 4:3.", "Output aspect ratio, e.g. 1:1 or 16:9.",
), ),
image_size=StringSchema( image_size=StringSchema(
"Optional output size hint supported by the configured provider, e.g. 1K, 2K, 4K, or 1024x1024.", "Provider-supported output size hint, e.g. 1K or 1024x1024.",
), ),
count=IntegerSchema( count=IntegerSchema(
description="Number of images to generate in this turn.", description="Number of images to generate in this turn.",
@@ -104,9 +104,7 @@ class ImageGenerationTool(Tool):
@property @property
def description(self) -> str: def description(self) -> str:
return ( return (
"Generate or edit images and store them as persistent artifacts. " "Generate or edit images as persistent artifacts. Returns artifact IDs and local paths."
"Returns artifact ids and local paths. For edits, pass prior generated image paths "
"or user image paths as reference_images."
) )
def _provider_config(self) -> ProviderConfig | None: def _provider_config(self) -> ProviderConfig | None:
+5 -8
View File
@@ -116,14 +116,13 @@ class _GoalToolsMixin:
@tool_parameters( @tool_parameters(
tool_parameters_schema( tool_parameters_schema(
objective=StringSchema( objective=StringSchema(
"The sustained objective for this session. It may consolidate a plan from earlier " "Self-contained goal with explicit completion criteria, bounded and safe to repeat. "
"discussion, but must be self-contained, bounded, safe under repetition, and " "May incorporate prior discussion.",
"explicit about done-ness.",
min_length=1, min_length=1,
max_length=MAX_GOAL_OBJECTIVE_CHARS, max_length=MAX_GOAL_OBJECTIVE_CHARS,
), ),
ui_summary=StringSchema( ui_summary=StringSchema(
"Optional one-line display label for session lists and logs. It is not load-bearing.", "One-line display label for session lists and logs; objective defines the goal.",
max_length=120, max_length=120,
nullable=True, nullable=True,
), ),
@@ -161,10 +160,8 @@ class CreateGoalTool(Tool, _GoalToolsMixin):
@property @property
def description(self) -> str: def description(self) -> str:
return ( return (
"Create one sustained goal for the current session when Goal Runtime Guidance asks " "Create one sustained goal for the current session only when Goal Runtime Guidance "
"you to record it. Consolidate relevant prior discussion into a durable objective " "asks you to record it. Do not retry after successful creation."
"that is self-contained, bounded, safe under repetition, and explicit about "
"completion criteria. Do not retry after a successful creation."
) )
def runtime_context_provider(self): def runtime_context_provider(self):
+8 -16
View File
@@ -38,18 +38,15 @@ def capture_message_deliveries() -> Generator[set[tuple[str, str]], None, None]:
@tool_parameters( @tool_parameters(
tool_parameters_schema( tool_parameters_schema(
content=StringSchema( content=StringSchema(
"Message content for proactive or cross-channel delivery. " "Message content."
"Do not use this for a normal reply in the current chat."
), ),
channel=StringSchema( channel=StringSchema(
"Optional target channel for cross-channel/proactive delivery. " "Target channel; defaults to the current channel."
"Do not set this to the current runtime channel for a normal reply."
), ),
chat_id=StringSchema( chat_id=StringSchema(
"Optional target chat/user ID for cross-channel/proactive delivery. " "Target chat/user ID; defaults to the current chat. "
"On WebSocket/WebUI turns: omit chat_id to use the server's conversation id " "On WebSocket/WebUI turns: omit chat_id to use the server's conversation id "
"(never pass client_id values like anon-…). " "(never pass client_id values like anon-…)."
"Do not set this to the current runtime chat for a normal reply."
), ),
media=ArraySchema( media=ArraySchema(
StringSchema(""), StringSchema(""),
@@ -119,15 +116,10 @@ class MessageTool(Tool):
@property @property
def description(self) -> str: def description(self) -> str:
return ( return (
"Proactively send a message to a user/channel, optionally with file attachments. " "Send separate messages requested by the user or task, optionally with attachments. "
"Use this for separate sends requested by the user or task, including sends to multiple chats. " "For normal replies, including scheduled reminders and reports, answer directly; "
"For a normal reply, including a scheduled reminder or report, answer naturally instead: " "the final reply is delivered to the current chat automatically. "
"nanobot delivers the final reply to the current chat. " "Use this tool to deliver generated images via media."
"Follow explicit task instructions that require this tool or name other recipients. "
"When generate_image creates images in the current chat, use the message tool "
"with the artifact paths in the media parameter to deliver the images to the user. "
"For proactive attachment delivery, use the 'media' parameter with file paths. "
"Do NOT use read_file to send files — that only reads content for your own analysis."
) )
def _resolve_media(self, media: list[str]) -> list[str]: def _resolve_media(self, media: list[str]) -> list[str]:
+11 -33
View File
@@ -127,38 +127,17 @@ class MyTool(Tool):
@property @property
def description(self) -> str: def description(self) -> str:
base = ( base = (
"Check and set your own runtime state.\n" "Inspect runtime state with check: omit key for an overview or use a dot-path. "
"Actions: check, set.\n" "set changes runtime parameters or stores scratchpad keys across turns, not restarts. "
"- check (no key): full config overview — start here.\n" "Use model_preset for session model/context switching; direct model and "
"- check (key): drill into a value. Dot-paths allowed " "context_window_tokens writes are disabled during active sessions. "
"(e.g. 'web_config.enable').\n" "Read-only access info: workspace_sandbox shows the current project and restriction; "
"- set (key, value): change config or store notes in your scratchpad. " "exec_config shows shell sandbox settings and binds. Shell binds do not grant "
"Scratchpad keys persist across turns but not restarts.\n" "file-tool access; OS permissions still apply. workspace is a legacy agent-directory "
"Current routing metadata is available read-only via request.channel, " "display, not the current project or an access grant. web_config is also read-only."
"request.chat_id, and request.sender_id.\n"
"For path access, check workspace_sandbox for the current project and "
"workspace restriction. Check exec_config for shell sandbox settings and extra binds. "
"Shell binds do not grant file-tool access. OS permissions still apply.\n"
"workspace is the legacy agent-directory display, not the current project or an access grant.\n"
"Use model_preset for session-scoped model or context changes; direct "
"model/context_window_tokens writes are disabled during active sessions.\n"
"Note: web_config and exec_config are readable but read-only.\n"
"\n"
"When to use:\n"
"- User asks about your model or settings → check that key.\n"
"- User asks to switch to a named model preset → set model_preset to that preset name.\n"
"- A tool fails or behaves unexpectedly → check the related config to diagnose.\n"
"- User asks you to remember a preference for this session → set to store it in your scratchpad.\n"
"- About to start a large task → check context_window_tokens and max_iterations first."
) )
if not self._modify_allowed: if not self._modify_allowed:
base += "\nREAD-ONLY MODE: set is disabled." base += "\nREAD-ONLY MODE: set is disabled."
else:
base += (
"\nIMPORTANT: Before setting state, predict the potential impact. "
"If the operation could cause crashes or instability "
"(e.g. changing model), warn the user first."
)
return base return base
@property @property
@@ -173,11 +152,10 @@ class MyTool(Tool):
}, },
"key": { "key": {
"type": "string", "type": "string",
"description": "Dot-path for check/set. Examples: 'max_iterations', 'workspace', 'provider_retry_mode'. " "description": "Dot-path for check; top-level runtime or scratchpad key for set. "
"Use 'request.channel', 'request.chat_id', or 'request.sender_id' for current routing metadata. " "Read-only routing metadata: request.channel, request.chat_id, request.sender_id.",
"Use 'model_preset' to switch named model presets. For check without key, shows all config values.",
}, },
"value": {"description": "New value (for set). Type must match target (int for max_iterations/context_window_tokens, str for model/model_preset)."}, "value": {"description": "New value for set; match the setting's type. Scratchpad accepts JSON values."},
}, },
"required": ["action"], "required": ["action"],
} }
+8 -14
View File
@@ -31,17 +31,16 @@ if TYPE_CHECKING:
enum=("create", "send", "cancel", "check"), enum=("create", "send", "cancel", "check"),
), ),
task=StringSchema("Required for create: the task for the subagent to complete.", min_length=1), task=StringSchema("Required for create: the task for the subagent to complete.", min_length=1),
label=StringSchema("Optional short label for create (for display)."), label=StringSchema("Display label for create."),
temperature=NumberSchema( temperature=NumberSchema(
description="Optional sampling temperature for create. Defaults to the parent's model runtime.", description="Sampling temperature for create; inherits the parent's runtime if omitted.",
minimum=0.0, minimum=0.0,
maximum=2.0, maximum=2.0,
), ),
wait=BooleanSchema( wait=BooleanSchema(
description=( description=(
"For create: wait for the result directly when it must inform the current turn. " "For create: true waits for the result; false runs in background with a completion notification. "
"Defaults to false for background execution with a completion notification. " "Temporary sessions and hosts unable to receive background results always wait."
"Ephemeral requests and hosts without a background consumer always wait."
), ),
default=False, default=False,
), ),
@@ -76,15 +75,10 @@ class SubagentTool(Tool):
@property @property
def description(self) -> str: def description(self) -> str:
return ( return (
"Create, message, cancel, or check your session's private subagent tasks. " "Manage the current session's private subagent tasks. "
"Use create for independent work; set wait=true for a blocking consultation. " "Background results arrive automatically; avoid repeated polling. "
"Use send for follow-up instructions, cancel to stop one task, and check to read " "Check with a known task_id to read older results. "
"progress, message receipts, and results. Check without task_id lists active and recent tasks; " "Partial results or iteration limits do not mean completion."
"use a known task_id to read an older result. "
"Background results arrive automatically; do not repeatedly poll check while waiting. "
"A partial result or iteration limit does not mean the task completed. "
"For deliverables or existing projects, inspect the workspace first "
"and use a dedicated subdirectory when helpful."
) )
@property @property
+6 -9
View File
@@ -322,7 +322,7 @@ def _normalize_volcengine_auth_level(value: Any) -> int | None:
@tool_parameters( @tool_parameters(
tool_parameters_schema( tool_parameters_schema(
query=StringSchema("Search query"), query=StringSchema("Search query"),
count=IntegerSchema(description="Results (1-10)", minimum=1, maximum=10), count=IntegerSchema(description="Maximum results; uses the configured default if omitted.", minimum=1, maximum=10),
timeRange=StringSchema( timeRange=StringSchema(
"Optional time filter for providers that support it: " "Optional time filter for providers that support it: "
"OneDay, OneWeek, OneMonth, OneYear, or YYYY-MM-DD..YYYY-MM-DD", "OneDay, OneWeek, OneMonth, OneYear, or YYYY-MM-DD..YYYY-MM-DD",
@@ -344,10 +344,8 @@ class WebSearchTool(Tool):
name = "web_search" # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType] name = "web_search" # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType]
description = ( # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType] description = ( # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType]
"Search the web. Returns titles, URLs, and snippets. " "Search the web for titles, URLs, and snippets. "
"count defaults to 5 (max 10). " "Use web_fetch to read a specific page."
"Some providers support timeRange, authLevel, and queryRewrite. "
"Use web_fetch to read a specific page in full."
) )
config_key = "web" config_key = "web"
@@ -1086,7 +1084,7 @@ class WebSearchTool(Tool):
"enum": ["markdown", "text"], "enum": ["markdown", "text"],
"default": "markdown", "default": "markdown",
}, },
maxChars=IntegerSchema(minimum=100), maxChars=IntegerSchema(description="Maximum output characters; defaults to 50000.", minimum=100),
required=["url"], required=["url"],
) )
) )
@@ -1096,9 +1094,8 @@ class WebFetchTool(Tool):
name = "web_fetch" # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType] name = "web_fetch" # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType]
description = ( # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType] description = ( # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType]
"Fetch a URL and extract readable content (HTML → markdown/text). " "Fetch a URL as readable markdown/text. "
"Output is capped at maxChars (default 50 000). " "May fail on login-walled or JavaScript-heavy pages."
"Works for most web pages and docs; may fail on login-walled or JS-heavy sites."
) )
config_key = "web" config_key = "web"
+3 -7
View File
@@ -200,17 +200,13 @@ async def test_default_allow_set_and_public_parameter_schema_are_unchanged(
"key": { "key": {
"type": "string", "type": "string",
"description": ( "description": (
"Dot-path for check/set. Examples: 'max_iterations', 'workspace', " "Dot-path for check; top-level runtime or scratchpad key for set. "
"'provider_retry_mode'. Use 'request.channel', 'request.chat_id', or " "Read-only routing metadata: request.channel, request.chat_id, request.sender_id."
"'request.sender_id' for current routing metadata. Use 'model_preset' "
"to switch named model presets. For check without key, shows all "
"config values."
), ),
}, },
"value": { "value": {
"description": ( "description": (
"New value (for set). Type must match target (int for " "New value for set; match the setting's type. Scratchpad accepts JSON values."
"max_iterations/context_window_tokens, str for model/model_preset)."
), ),
}, },
}, },
-5
View File
@@ -732,11 +732,6 @@ class TestReadOnlyMode:
tool = self._make_readonly_tool() tool = self._make_readonly_tool()
assert "READ-ONLY MODE" in tool.description assert "READ-ONLY MODE" in tool.description
def test_description_shows_warning_when_modify_allowed(self):
tool = _make_tool()
assert "IMPORTANT" in tool.description
assert "READ-ONLY" not in tool.description
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# scratchpad inspection # scratchpad inspection
+5 -5
View File
@@ -204,10 +204,10 @@ class TestMessageToolSchema:
def test_schema_discourages_current_chat_replies(self) -> None: def test_schema_discourages_current_chat_replies(self) -> None:
tool = MessageTool() tool = MessageTool()
assert "For a normal reply, including a scheduled reminder or report, answer naturally instead" in tool.description assert "For normal replies, including scheduled reminders and reports, answer directly" in tool.description
assert "nanobot delivers the final reply to the current chat" in tool.description assert "the final reply is delivered to the current chat automatically" in tool.description
assert "generate_image creates images in the current chat" in tool.description assert "deliver generated images via media" in tool.description
assert ( assert (
"Do not use this for a normal reply in the current chat" "Use artifact paths returned by generate_image"
in tool.parameters["properties"]["content"]["description"] in tool.parameters["properties"]["media"]["description"]
) )
+1 -1
View File
@@ -16,7 +16,7 @@ def test_coding_tool_descriptions_steer_editing_priority() -> None:
assert "default tool for code edits" in apply_patch assert "default tool for code edits" in apply_patch
assert "multi-file" in apply_patch assert "multi-file" in apply_patch
assert "dry_run=true" in apply_patch assert "without writing files" in ApplyPatchTool().parameters["properties"]["dry_run"]["description"]
assert "edit_file only for small exact replacements" in apply_patch assert "edit_file only for small exact replacements" in apply_patch
assert "small, exact replacement" in edit_file assert "small, exact replacement" in edit_file