Gemini CLI 工具
¥Gemini CLI tools
Gemini CLI 包含内置工具,Gemini 模型可使用这些工具与本地环境交互、访问信息并执行操作。这些工具增强了 CLI 的功能,使其能够超越文本生成,并协助完成各种任务。
¥The Gemini CLI includes built-in tools that the Gemini model uses to interact with your local environment, access information, and perform actions. These tools enhance the CLI's capabilities, enabling it to go beyond text generation and assist with a wide range of tasks.
Gemini CLI 工具概述
¥Overview of Gemini CLI tools
在 Gemini CLI 的上下文中,工具是指 Gemini 模型可以请求执行的特定函数或模块。例如,如果您要求 Gemini “总结以下内容”my_document.txt”模型可能会识别出读取该文件的需要,并请求执行read_file工具。
¥In the context of the Gemini CLI, tools are specific functions or modules that the Gemini model can request to be executed. For example, if you ask Gemini to "Summarize the contents of my_document.txt," the model will likely identify the need to read that file and will request the execution of the read_file tool.
核心组件(packages/core) 管理这些工具,将它们的定义(模式)呈现给 Gemini 模型,在请求时执行它们,并将结果返回给模型以便进一步处理为面向用户的响应。
¥The core component (packages/core) manages these tools, presents their definitions (schemas) to the Gemini model, executes them when requested, and returns the results to the model for further processing into a user-facing response.
这些工具提供以下功能:
¥These tools provide the following capabilities:
访问本地信息:工具允许 Gemini 访问您的本地文件系统、读取文件内容、列出目录等。
¥Access local information: Tools allow Gemini to access your local file system, read file contents, list directories, etc.
执行命令:使用类似工具
run_shell_command,Gemini 可以运行 shell 命令(具有适当的安全措施和用户确认)。¥Execute commands: With tools like
run_shell_command, Gemini can run shell commands (with appropriate safety measures and user confirmation).与网络互动:工具可以从 URL 获取内容。
¥Interact with the web: Tools can fetch content from URLs.
采取行动:工具可以修改文件、写入新文件或在您的系统上执行其他操作(同样,通常带有安全措施)。
¥Take actions: Tools can modify files, write new files, or perform other actions on your system (again, typically with safeguards).
地面响应:通过使用工具获取实时或特定的本地数据,Gemini 的响应可以更加准确、相关且更符合您的实际情况。
¥Ground responses: By using tools to fetch real-time or specific local data, Gemini's responses can be more accurate, relevant, and grounded in your actual context.
如何使用 Gemini CLI 工具
¥How to use Gemini CLI tools
要使用 Gemini CLI 工具,请向 Gemini CLI 提供提示符。该过程如下:
¥To use Gemini CLI tools, provide a prompt to the Gemini CLI. The process works as follows:
您向 Gemini CLI 提供提示。
¥You provide a prompt to the Gemini CLI.
CLI 将提示发送到核心。
¥The CLI sends the prompt to the core.
核心与您的提示和对话历史记录一起将可用工具及其描述/模式的列表发送到 Gemini API。
¥The core, along with your prompt and conversation history, sends a list of available tools and their descriptions/schemas to the Gemini API.
Gemini 模型会分析您的请求。如果它确定需要某个工具,它的响应将包含一个请求,该请求会使用特定的参数来执行特定的工具。
¥The Gemini model analyzes your request. If it determines that a tool is needed, its response will include a request to execute a specific tool with certain parameters.
核心接收此工具请求,验证它,并且(通常在用户确认敏感操作后)执行该工具。
¥The core receives this tool request, validates it, and (often after user confirmation for sensitive operations) executes the tool.
该工具的输出被发送回 Gemini 模型。
¥The output from the tool is sent back to the Gemini model.
Gemini 模型使用该工具的输出来制定最终答案,然后通过核心发送回 CLI 并显示给您。
¥The Gemini model uses the tool's output to formulate its final answer, which is then sent back through the core to the CLI and displayed to you.
您通常会在 CLI 中看到消息,指示何时调用工具以及调用是否成功或失败。
¥You will typically see messages in the CLI indicating when a tool is being called and whether it succeeded or failed.
安全和确认
¥Security and confirmation
许多工具,特别是那些可以修改文件系统或执行命令的工具(write_file,edit,run_shell_command) 的设计充分考虑了安全性。Gemini CLI 通常将:
¥Many tools, especially those that can modify your file system or execute commands (write_file, edit, run_shell_command), are designed with safety in mind. The Gemini CLI will typically:
需要确认:在执行潜在的敏感操作之前提示您,向您展示即将采取的操作。
¥Require confirmation: Prompt you before executing potentially sensitive operations, showing you what action is about to be taken.
利用沙盒:所有工具均受沙盒强制限制(见Gemini CLI 中的沙盒)。这意味着在沙盒中操作时,您希望使用的任何工具(包括 MCP 服务器)都必须可用里面沙盒环境。例如,要通过
npx, 这npx可执行文件必须安装在沙盒的 Docker 镜像中,或者在sandbox-exec环境。¥Utilize sandboxing: All tools are subject to restrictions enforced by sandboxing (see Sandboxing in the Gemini CLI). This means that when operating in a sandbox, any tools (including MCP servers) you wish to use must be available inside the sandbox environment. For example, to run an MCP server through
npx, thenpxexecutable must be installed within the sandbox's Docker image or be available in thesandbox-execenvironment.
在允许工具继续运行之前,务必仔细检查确认提示。
¥It's important to always review confirmation prompts carefully before allowing a tool to proceed.
了解有关 Gemini CLI 工具的更多信息
¥Learn more about Gemini CLI's tools
Gemini CLI 的内置工具大致可以分为以下几类:
¥Gemini CLI's built-in tools can be broadly categorized as follows:
文件系统工具:用于与文件和目录交互(读取、写入、列出、搜索等)。
¥File System Tools: For interacting with files and directories (reading, writing, listing, searching, etc.).
Shell 工具(
run_shell_command):用于执行 shell 命令。¥Shell Tool (
run_shell_command): For executing shell commands.Web 获取工具(
web_fetch):用于从 URL 检索内容。¥Web Fetch Tool (
web_fetch): For retrieving content from URLs.网络搜索工具(
web_search):用于搜索网络。¥Web Search Tool (
web_search): For searching the web.多文件读取工具(
read_many_files):用于从多个文件或目录读取内容的专用工具,通常由@命令。¥Multi-File Read Tool (
read_many_files): A specialized tool for reading content from multiple files or directories, often used by the@command.记忆工具(
save_memory):用于在会话之间保存和调用信息。¥Memory Tool (
save_memory): For saving and recalling information across sessions.
此外,这些工具还包括:
¥Additionally, these tools incorporate:
MCP 服务器:MCP 服务器充当 Gemini 模型与您的本地环境或其他服务(如 API)之间的桥梁。
¥MCP servers: MCP servers act as a bridge between the Gemini model and your local environment or other services like APIs.
沙盒:沙盒将模型及其变化与您的环境隔离,以降低潜在风险。
¥Sandboxing: Sandboxing isolates the model and its changes from your environment to reduce potential risk.