AssistantTool PRO
Assistant Tool is a system extension mechanism within the Scripting application that enhances the capabilities of an intelligent assistant (Assistant). By defining and implementing an Assistant Tool, developers can provide the Assistant with auxiliary functionalities such as device capability access, file reading/writing, and data analysis. This improves both the intelligence and practicality of the Assistant.
This document uses an example tool, "Request Current Location", to illustrate the full implementation process, including tool creation, configuration file explanation, execution logic, and detailed descriptions of various functions.
1. Tool Creation Process
- Open any scripting project and click the “Add Assistant Tool” button in the file manager interface.
- Fill in the relevant information about the Assistant Tool in the configuration popup window.
- After clicking “Save,” the system will automatically generate two files in the script:
assistant_tool.json: Describes the tool’s metadata and parameter information.assistant_tool.tsx: Implements the tool’s execution logic.
2. Configuration File: assistant_tool.json
This file declares the basic information and behavior settings of the tool. Below is a sample content and explanation of each field:
Field Descriptions:
3. Execution Logic Example: assistant_tool.tsx
4. AssistantTool Registration Functions Explained
1. registerApprovalRequest
Registers a function to request user approval before executing the tool.
Parameters:
requestFn(params, scriptEditorProvider?): Returns a prompt with messages and button labels.params: Input parameters for the tool.scriptEditorProvider: Available only whenscriptEditorOnlyis set to true, provides file access for the script.
Return Value:
A test function for simulating approval requests in the script editor.
2. registerExecuteToolWithApproval
Registers an execution function that requires user approval.
Parameters:
params: Input parameters for execution.userAction: User's choice in the approval prompt:
scriptEditorProvider: Same as above.
Return Value:
Returns an object:
success: Whether execution succeeded.message: Message returned to the Assistant.
3. registerExecuteTool
Registers a tool that does not require user approval.
Use Case: Suitable for non-sensitive operations or those that don’t involve device permissions.
4. Testing Functions
Each registration function returns a test function that can be used in the script:
5. ScriptEditorProvider Interface
When scriptEditorOnly: true is set, the system provides a ScriptEditorProvider interface that allows access to the script project’s file system and syntax info.
Capabilities include:
- File read/write (read, update, write, insert, replace)
- Diff comparison (
openDiffEditor) - Linting results (
getLintErrors) - List all files/folders in the project
Useful for tools that edit scripts, perform formatting, or batch modifications.
6. Execution and User Experience Flow
- The Assistant determines whether to invoke a tool during a conversation.
- If the tool requires approval, a dialog box is displayed:
- The prompt is provided by
registerApprovalRequest. - Once the user clicks “Allow,” the tool logic is executed.
- The prompt is provided by
- Execution results are returned to the Assistant through the
messagefield, and shown to the user.
7. Tools That Don’t Require Approval
If you don’t want to show an approval prompt, simply use registerExecuteTool and set requireApproval: false in assistant_tool.json.
8. Summary
Assistant Tool is an extensible module provided by the Scripting application, supporting scenarios such as user authorization, file manipulation, and system-level access. The development process includes:
- Creating the tool in a scripting project;
- Configuring its metadata;
- Implementing and registering the logic functions;
- Testing tool behavior with test functions;
- Triggering tool execution automatically or manually within Assistant conversations.
