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."
),
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"],
),
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,
),
new_text=StringSchema(
@@ -64,7 +64,7 @@ def _append_text(content: str, addition: str) -> str:
),
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,
max_items=20,
),
@@ -86,11 +86,8 @@ class ApplyPatchTool(_FsTool):
@property
def description(self) -> str:
return (
"Default tool for code edits. Supports multi-file changes in a single call. "
"Provide a list of structured edits, each specifying a file path, action "
"(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. "
"Default tool for code edits, including multi-file changes. "
"Returns a file-change summary. "
"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(
action=StringSchema("Action to perform", enum=["add", "list", "remove"]),
name=StringSchema(
"Optional short human-readable label for the job "
"(e.g., 'weather-monitor', 'daily-standup'). Defaults to first 30 chars of message."
),
name=StringSchema("Job label; generated from message if omitted."),
message=StringSchema(
"REQUIRED when action='add'. Instruction for the agent to execute when the job triggers "
"(e.g., 'Remind me to drink water' or 'Check system status and report'). "
"REQUIRED when action='add': non-empty instruction to execute when the job triggers. "
"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. "
"Include other recipients only when the user requests separate sends. "
"Not used for action='list' or action='remove'."
"Include other recipients only when the user requests separate sends."
),
every_seconds=IntegerSchema(
description="Interval in seconds (for recurring tasks)", minimum=1
),
cron_expr=StringSchema("Cron expression like '0 9 * * *' (for scheduled tasks)"),
tz=StringSchema(
"Optional IANA timezone for cron expressions (e.g. 'America/Vancouver'). "
"When omitted with cron_expr, the tool's default timezone applies."
"IANA timezone for cron_expr only, e.g. 'America/Vancouver'."
),
at=StringSchema(
"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')."),
required=["action"],
description=(
"Action-specific parameters: add requires a non-empty message plus one schedule "
"(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."
"add requires exactly one schedule: every_seconds, cron_expr, or at."
),
)
+5 -7
View File
@@ -559,10 +559,9 @@ class WriteFileTool(_FsTool):
@property
def description(self) -> str:
return (
"Create a new file or intentionally replace an entire file with "
"the provided content. Overwrites existing files and creates parent "
"directories as needed. For code changes or partial edits, prefer "
"apply_patch; use edit_file only for small exact replacements."
"Create a file or replace an entire file. "
"Overwrites existing files and creates parent directories. "
"Prefer apply_patch for partial edits."
)
async def execute(self, path: str | None = None, content: str | None = None, **kwargs: Any) -> str:
@@ -1140,9 +1139,8 @@ class ListDirTool(_FsTool):
@property
def description(self) -> str:
return (
"List the contents of a directory. "
"Set recursive=true to explore nested structure. "
"Common noise directories (.git, node_modules, __pycache__, etc.) are auto-ignored."
"List directory contents, skipping common noise directories "
"(.git, node_modules, __pycache__, etc.)."
)
@property
+6 -8
View File
@@ -41,18 +41,18 @@ if TYPE_CHECKING:
@tool_parameters(
tool_parameters_schema(
prompt=StringSchema(
"Detailed image generation or edit prompt. Include style, subject, composition, colors, and constraints.",
"Detailed image generation or edit instructions.",
min_length=1,
),
reference_images=ArraySchema(
StringSchema("Local path of an existing image artifact or user-provided image to use as an edit reference."),
description="Optional local image paths. Use generated artifact paths for iterative edits.",
StringSchema(""),
description="Existing local image paths for edits, including prior generated artifacts.",
),
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(
"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(
description="Number of images to generate in this turn.",
@@ -104,9 +104,7 @@ class ImageGenerationTool(Tool):
@property
def description(self) -> str:
return (
"Generate or edit images and store them as persistent artifacts. "
"Returns artifact ids and local paths. For edits, pass prior generated image paths "
"or user image paths as reference_images."
"Generate or edit images as persistent artifacts. Returns artifact IDs and local paths."
)
def _provider_config(self) -> ProviderConfig | None:
+5 -8
View File
@@ -116,14 +116,13 @@ class _GoalToolsMixin:
@tool_parameters(
tool_parameters_schema(
objective=StringSchema(
"The sustained objective for this session. It may consolidate a plan from earlier "
"discussion, but must be self-contained, bounded, safe under repetition, and "
"explicit about done-ness.",
"Self-contained goal with explicit completion criteria, bounded and safe to repeat. "
"May incorporate prior discussion.",
min_length=1,
max_length=MAX_GOAL_OBJECTIVE_CHARS,
),
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,
nullable=True,
),
@@ -161,10 +160,8 @@ class CreateGoalTool(Tool, _GoalToolsMixin):
@property
def description(self) -> str:
return (
"Create one sustained goal for the current session when Goal Runtime Guidance asks "
"you to record it. Consolidate relevant prior discussion into a durable objective "
"that is self-contained, bounded, safe under repetition, and explicit about "
"completion criteria. Do not retry after a successful creation."
"Create one sustained goal for the current session only when Goal Runtime Guidance "
"asks you to record it. Do not retry after successful creation."
)
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_schema(
content=StringSchema(
"Message content for proactive or cross-channel delivery. "
"Do not use this for a normal reply in the current chat."
"Message content."
),
channel=StringSchema(
"Optional target channel for cross-channel/proactive delivery. "
"Do not set this to the current runtime channel for a normal reply."
"Target channel; defaults to the current channel."
),
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 "
"(never pass client_id values like anon-…). "
"Do not set this to the current runtime chat for a normal reply."
"(never pass client_id values like anon-…)."
),
media=ArraySchema(
StringSchema(""),
@@ -119,15 +116,10 @@ class MessageTool(Tool):
@property
def description(self) -> str:
return (
"Proactively send a message to a user/channel, optionally with file attachments. "
"Use this for separate sends requested by the user or task, including sends to multiple chats. "
"For a normal reply, including a scheduled reminder or report, answer naturally instead: "
"nanobot delivers the final reply to the current chat. "
"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."
"Send separate messages requested by the user or task, optionally with attachments. "
"For normal replies, including scheduled reminders and reports, answer directly; "
"the final reply is delivered to the current chat automatically. "
"Use this tool to deliver generated images via media."
)
def _resolve_media(self, media: list[str]) -> list[str]:
+11 -33
View File
@@ -127,38 +127,17 @@ class MyTool(Tool):
@property
def description(self) -> str:
base = (
"Check and set your own runtime state.\n"
"Actions: check, set.\n"
"- check (no key): full config overview — start here.\n"
"- check (key): drill into a value. Dot-paths allowed "
"(e.g. 'web_config.enable').\n"
"- set (key, value): change config or store notes in your scratchpad. "
"Scratchpad keys persist across turns but not restarts.\n"
"Current routing metadata is available read-only via request.channel, "
"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."
"Inspect runtime state with check: omit key for an overview or use a dot-path. "
"set changes runtime parameters or stores scratchpad keys across turns, not restarts. "
"Use model_preset for session model/context switching; direct model and "
"context_window_tokens writes are disabled during active sessions. "
"Read-only access info: workspace_sandbox shows the current project and restriction; "
"exec_config shows shell sandbox settings and binds. Shell binds do not grant "
"file-tool access; OS permissions still apply. workspace is a legacy agent-directory "
"display, not the current project or an access grant. web_config is also read-only."
)
if not self._modify_allowed:
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
@property
@@ -173,11 +152,10 @@ class MyTool(Tool):
},
"key": {
"type": "string",
"description": "Dot-path for check/set. Examples: 'max_iterations', 'workspace', 'provider_retry_mode'. "
"Use 'request.channel', 'request.chat_id', or 'request.sender_id' for current routing metadata. "
"Use 'model_preset' to switch named model presets. For check without key, shows all config values.",
"description": "Dot-path for check; top-level runtime or scratchpad key for set. "
"Read-only routing metadata: request.channel, request.chat_id, request.sender_id.",
},
"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"],
}
+8 -14
View File
@@ -31,17 +31,16 @@ if TYPE_CHECKING:
enum=("create", "send", "cancel", "check"),
),
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(
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,
maximum=2.0,
),
wait=BooleanSchema(
description=(
"For create: wait for the result directly when it must inform the current turn. "
"Defaults to false for background execution with a completion notification. "
"Ephemeral requests and hosts without a background consumer always wait."
"For create: true waits for the result; false runs in background with a completion notification. "
"Temporary sessions and hosts unable to receive background results always wait."
),
default=False,
),
@@ -76,15 +75,10 @@ class SubagentTool(Tool):
@property
def description(self) -> str:
return (
"Create, message, cancel, or check your session's private subagent tasks. "
"Use create for independent work; set wait=true for a blocking consultation. "
"Use send for follow-up instructions, cancel to stop one task, and check to read "
"progress, message receipts, and results. Check without task_id lists active and recent tasks; "
"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."
"Manage the current session's private subagent tasks. "
"Background results arrive automatically; avoid repeated polling. "
"Check with a known task_id to read older results. "
"Partial results or iteration limits do not mean completion."
)
@property
+6 -9
View File
@@ -322,7 +322,7 @@ def _normalize_volcengine_auth_level(value: Any) -> int | None:
@tool_parameters(
tool_parameters_schema(
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(
"Optional time filter for providers that support it: "
"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]
description = ( # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType]
"Search the web. Returns titles, URLs, and snippets. "
"count defaults to 5 (max 10). "
"Some providers support timeRange, authLevel, and queryRewrite. "
"Use web_fetch to read a specific page in full."
"Search the web for titles, URLs, and snippets. "
"Use web_fetch to read a specific page."
)
config_key = "web"
@@ -1086,7 +1084,7 @@ class WebSearchTool(Tool):
"enum": ["markdown", "text"],
"default": "markdown",
},
maxChars=IntegerSchema(minimum=100),
maxChars=IntegerSchema(description="Maximum output characters; defaults to 50000.", minimum=100),
required=["url"],
)
)
@@ -1096,9 +1094,8 @@ class WebFetchTool(Tool):
name = "web_fetch" # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType]
description = ( # pyright: ignore[reportIncompatibleMethodOverride, reportAssignmentType]
"Fetch a URL and extract readable content (HTML → markdown/text). "
"Output is capped at maxChars (default 50 000). "
"Works for most web pages and docs; may fail on login-walled or JS-heavy sites."
"Fetch a URL as readable markdown/text. "
"May fail on login-walled or JavaScript-heavy pages."
)
config_key = "web"