> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/gitbook-agent/write-and-edit-with-ai.md).

# 使用 GitBook Agent 写作

{% hint style="info" %}
此功能适用于 [专业版和企业版方案](https://www.gitbook.com/pricing).
{% endhint %}

GitBook Agent 是一款强大的工具，可用于在 GitBook 中为你的文档生成内容。

Agent 可以完成各种任务，从在页面上撰写简短文本，到编辑现有块、创建新页面，以及在变更请求中执行更多操作。

{% hint style="info" %}

#### GitBook Agent 会遵循你的风格指南

在以下位置定义团队的写作规则： [风格指南](/docs/documentation/zh/creating-content/styleguide.md)，每当你请求 Agent 协助时，它都会将其视为唯一可信来源。它会加载你的风格指南的 **第一页** 到每项任务的上下文中，因此请将主要规则放在那里。

你还可以 [添加简短的自定义指令](/docs/documentation/zh/gitbook-agent/what-is-gitbook-agent.md#add-a-style-guide-and-custom-instructions) 在站点级别。
{% endhint %}

### GitBook Agent 可以做什么？

GitBook Agent 深度集成于 GitBook 应用，因此它了解你可以在编辑器中创建的内容块，以及所在分区的更广泛内容。

这意味着你可以使用 Agent 来：

* 根据你的提示撰写新内容
* 搜索现有页面并更新特定内容
* 重新格式化内容，以充分利用 GitBook 的不同内容块
* 更新代码示例
* 在页面之间移动内容
* 在指定位置添加新页面

### 如何与 GitBook Agent 交互

有几种使用 GitBook Agent 的方式：

* 在现有变更请求中打开 Agent，并告诉它你需要什么
* 使用 GitBook Agent 规划并实施新的变更请求
* 在内容块的评论中提及 Agent
* 在页面的空白行中创建新内容

让我们逐一了解这些方式的工作原理。

#### 在任何变更请求中打开 GitBook Agent 聊天窗口

你可以随时在变更请求中点击 **GitBook Agent** 按钮（位于分区标题栏中）。这会在应用右侧打开 Agent 的聊天窗口。

<div data-with-frame="true"><figure><img src="/files/ed694a75831bd5e493311b80aaaf93e945fa2a5a" alt=""><figcaption><p>在变更请求中打开 GitBook Agent</p></figcaption></figure></div>

你可以在这里编写供 Agent 遵循的提示——它会在执行你的指令时说明自己正在做什么，同时更改会在它工作时显示在你的分区中。

你可以提供后续指令、澄清步骤，或随时直接编辑分区内容，从而与 GitBook Agent 协同工作。

#### 使用 GitBook Agent 实施变更请求

点击 **GitBook Agent** 的 **编辑** 部分，该按钮位于分区右上角，可打开一个模态窗口。

你可以在这里编写提示，告诉 Agent 你希望变更请求包含什么内容，然后添加可能作为变更上下文而有用的参考页面。

点击 **开始变更请求** 后，Agent 会为你打开一个变更请求并开始执行你的指令。在每个阶段，Agent 都会在应用右侧的聊天窗口中告诉你它正在做什么。

完成后，你可以直接在页面上自行编辑内容，或向 Agent 提供更多指令以继续完善变更。

#### 在评论中提及 GitBook Agent

如果你希望 Agent 审查页面上的某个特定内容块，可以在评论中提及它并告诉它你的需求。只需点击 **对内容块发表评论** 并通过提及 @gitbook 来提及 Agent，然后告诉它你希望它做什么。

GitBook Agent 会根据你的提示更新内容，然后回复你的评论，告知它完成了什么操作。

#### 使用 GitBook Agent 改进页面内容

<figure><img src="/files/894b73d49495db12cb3612d62e57cd6d52cdf9b4" alt=""><figcaption></figcaption></figure>

“ **改进** ”菜单提供多种预设选项，用于指示 GitBook Agent 执行常见操作以改进页面内容。

你可以访问 **改进** 菜单：在编辑器中将鼠标悬停在页面标题上，或打开页面的 **操作菜单** <picture><source srcset="/files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="/files/d05670ba93b683794fb3fe95a9fc7ab5c7fceafd" alt=""></picture>.

在“改进”菜单中，你可以让 Agent：

* 为页面添加图标
* 根据页面内容生成页面描述
* 修复拼写和语法错误
* 重写内容以与其他页面保持一致
* 针对 SEO 进行优化
* 添加摘要和后续步骤部分
* 链接到相关主题和页面
* 将单个页面拆分为多个页面

前两个选项是条件性的——它们会根据你的页面内容而变化。因此，如果你的页面已有图标和描述，菜单中就不会显示这些选项。

点击任意选项，Agent 就会立即开始处理你的任务。

#### 在空白内容块中创建新内容

你可以使用 GitBook Agent 在页面的任何空白行中创建内容。它可以创建各种以 Markdown 格式编写的内容——包括代码示例、模板、页面摘要等。

按下 `空格键` 在任意空白行上，或输入 `/` 并选择 **使用 AI 写作** 以启动 GitBook Agent。

你可以立即开始输入任何想要的提示。GitBook Agent 会分析提示并据此生成内容。例如：

> 请为我写一段两段式概述，说明文档为何对产品团队很重要。

或者，你可以从建议的提示或提示开头中选择一个：

* **继续写作** ——GitBook Agent 会分析当前页面的内容，然后据此生成更多内容。
* **解释……** ——选择此项，然后告诉 GitBook Agent 你希望它解释什么。这不限于页面上的内容，因此你可以让它解释任何内容。
* **总结** ——总结页面上的所有内容。这非常适合在详细文档底部撰写 TL;DR，或在顶部添加简短摘要，供只是快速查看的读者阅读。
* **解释此内容** ——这会用更简单的语言解释页面上的复杂信息，包括解释缩写和其他术语。如果你阅读的页面涉及大量复杂信息，或者想为技术背景较少的读者添加说明，这将非常合适。
* **翻译** ——将当前页面翻译为若干指定语言之一。如果你想翻译成列表中没有的语言，只需在提示框中输入该语言。

### 为 GitBook Agent 编写有效提示 <a href="#write-effective-prompts" id="write-effective-prompts"></a>

GitBook Agent 就像一位善于执行指示的队友。你需要向它提供清晰的指令和上下文，才能获得最佳结果。

以下是编写优质提示的一些快速技巧：

* **分解任务** ——Agent 最擅长完成聚焦的任务。将复杂项目分解为较小步骤，并让 Agent 一次完成一个步骤。
* **明确具体** ——诸如 `@gitbook 改进此页面` 这样的通用提示会应用一般最佳实践，但如果没有更具体的指导，Agent 可能无法实现你心中的目标。
* **关注结果** ——如果你了解到客户正在遇到某个具体问题，请告诉 Agent 这些问题，或者告诉它你希望实现的结果。它会根据这些结果建议改进措施。
* **给出直接指令** ——如果你希望 Agent 使用步骤内容块来创建分步指南，或添加包含多个可展开内容块的常见问题部分，请精确告诉它要做什么，以便首次就获得正确结果。
* **使用宽泛提示进行更广泛的改进** ——对于修复错别字、跨页面更新功能名称，或从文档中移除特定内容块类型等维护任务，你可以使用如下命令： `@gitbook 将所有 v2.3.9 替换为 v2.4.0`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/gitbook-agent/write-and-edit-with-ai.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
