> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/zh/ji-cheng/openclaw.md).

# 如何使用 OpenClaw 运行本地 AI 模型

使用 OpenClaw 运行本地 LLM 的指南。

本指南将展示如何在本地使用开源 LLM，并通过 **将 OpenClaw 连接到 Unsloth。**。OpenClaw 是一个 **开源 AI 代理** 接口，它连接到模型以在你的项目中执行任务。OpenClaw 能够通过 **Unsloth 的 OpenAI 兼容 API**：包括 DeepSeek、Qwen、Gemma 等。

OpenClaw 充当客户端，而 Unsloth 则通过一个 **本地 API**。设置完成后，OpenClaw 将通过 Unsloth 在你的本地模型上运行，让你可以直接将其用作 **AI 代理。** 在本教程中，我们将使用 [Qwen3.6](/docs/zh/mo-xing/qwen3.6.md).

<a href="/docs/zh/ji-cheng/openclaw.md#connecting-to-openclaw" class="button primary" data-icon="lobster">连接到 OpenClaw</a><a href="/docs/zh/ji-cheng/openclaw.md#quickstart" class="button primary">快速开始</a>

{% hint style="info" %}
在本教程中，我们将使用 `unsloth/Qwen3.6-27B-GGUF` 在 Unsloth 中并通过 OpenClaw 访问它。想用其他模型？只需在 Unsloth 中加载其他模型并更新配置即可。
{% endhint %}

### 安装 OpenClaw

{% tabs %}
{% tab title="macOS、Linux、WSL" %}
使用官方安装程序安装 OpenClaw：

`curl -fsSL https://openclaw.ai/install.sh | bash`

这会安装 OpenClaw 并引导你完成初始设置。
{% endtab %}

{% tab title="Windows（PowerShell）" %}
使用官方安装程序安装 OpenClaw：

`iwr -useb https://openclaw.ai/install.ps1 | iex`

这会安装 OpenClaw 并引导你完成初始设置。
{% endtab %}
{% endtabs %}

### ⚡ 快速开始

安装 OpenClaw 后，我们还需要安装 [Unsloth Desktop](/docs/zh/desktop.md) 以便让 OpenClaw 能够托管并对本地模型进行推理。

{% stepper %}
{% step %}

#### 下载 Unsloth

最快的入门方式是安装 Unsloth Desktop 应用。它支持 [macOS](/docs/zh/kai-shi-shi-yong/install/mac.md)、Linux、 [Windows](/docs/zh/kai-shi-shi-yong/install/windows-installation.md), [NVIDIA](/docs/zh/kai-shi-shi-yong/install/pip-install.md), [AMD](/docs/zh/kai-shi-shi-yong/install/amd.md)、Intel 和 CPU 配置。

<a href="https://unsloth.ai/download" class="button primary" data-icon="down-to-bracket">下载 Unsloth</a>

* <i class="fa-apple">:apple:</i> [下载 macOS 版](https://unsloth.ai/download/mac)
* <i class="fa-windows">:windows:</i> [下载 Windows 版](https://unsloth.ai/download/windows)
* <i class="fa-linux">:linux:</i> [下载 Linux 版](https://unsloth.ai/download/linux)

或者，如果你更喜欢手动安装：

**macOS、Linux、WSL：**

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

**Windows PowerShell：**

```bash
irm https://unsloth.ai/install.ps1 | iex
```

{% endstep %}

{% step %}

#### 安装

1. 打开 Unsloth 安装程序（`.dmg`, `.exe` 文件）
2. 在 Mac 上将 Unsloth 拖到 Applications 文件夹，或在 Windows 上完成设置。
3. 启动应用并等待安装完成
   {% endstep %}

{% step %}

#### 选择模型

打开顶部的“Select model”下拉菜单或“Model hub”选项卡，选择适合你设备的模型和量化方式，然后下载它。完成后即可开始聊天——无需额外设置。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FNCEVgKLJI0goPqjgcg9B%2Fmodel%20hub%20models.png?alt=media&amp;token=533b5e3c-a901-4b33-963e-4a703cc9d5a6" alt="" width="563"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Unsloth 已准备就绪

要开始聊天，请输入消息并按 Enter。

**连接 OpenClaw。** 运行 `unsloth start openclaw` 以在单独的受管环境中使用已加载的 Unsloth 模型启动 OpenClaw。你常规的 OpenClaw 配置保持不变。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FpAGvwjGD0iVMZKBoyu7m%2Fgreeennn.png?alt=media&amp;token=d17a5528-8375-444c-9aff-f9e9f7903bcd" alt="" width="563"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### ⚙️ 使用以下方式启动 OpenClaw： `unsloth start`

OpenClaw 可以连接到已在 Unsloth Studio 中运行的模型，也可以在 Unsloth 未运行时自动启动一个模型。

连接到正在运行的 Unsloth 实例

在 Unsloth Studio 中加载模型后，运行：

```bash
unsloth start openclaw
```

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FQm2hy6E5WvSzvmhQX0VL%2Fimage.png?alt=media&amp;token=e87ad9ac-8c43-4d20-9276-10eed404bd89" alt="" width="563"><figcaption></figcaption></figure></div>

Unsloth 会在单独的受管环境中，以已配置好的 Unsloth 提供方、模型和上下文长度，在本地 TUI 模式下启动 OpenClaw。你常规的 OpenClaw 设置保持不变。

OpenClaw 打开后，给它一个任务，例如：

```
检查这个仓库并用一句话总结：https://github.com/unslothai/unsloth
```

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fz93FYVhDJZKkBw3bY5X9%2Fimage.png?alt=media&amp;token=f79db6e8-59ea-4ac7-8008-fe6e6124d977" alt="" width="563"><figcaption></figcaption></figure></div>

#### 自动启动模型

如果 Unsloth 尚未运行，请传入模型 ID：

要直接使用模型启动 OpenClaw，运行：

```bash
unsloth start openclaw \
    --model unsloth/qwen3.8-27B-GGUF-GGUF:UD-Q4_K_XL
    --temp 1.0 \
    --top-p 0.95 \
    --top-k 20 \
    --min-p 0.0 \
    --reasoning-effort medium
```

Unsloth 会自动选择要使用的正确参数，但你仍然可以更改它。

Unsloth 会启动模型、启动 OpenClaw，并在你退出时停止临时服务器。\
\
要保留你的 OpenClaw 状态并在稍后返回同一会话，请添加 `--persist` 并选择一个会话密钥：

```bash
unsloth start openclaw \
  --model unsloth/Qwen3.6-27B-GGUF \
  --persist \
  agent --local \
  --session-key my-session \
  --message "Inspect this repository"
```

稍后使用相同的会话密钥继续：

```bash
unsloth start openclaw \
  --model unsloth/Qwen3.6-27B-GGUF \
  --persist \
  agent --local \
  --session-key my-session \
  --message "Continue"
```

查看完整的 [unsloth start](/docs/zh/ji-cheng/unsloth-start.md) 关于命名会话、模型加载、远程 Unsloth 服务器和高级选项的参考。

本指南其余部分将介绍手动配置 OpenClaw 提供方。

### 手动配置 OpenClaw 提供方

### 🔑 创建 API 密钥

密钥创建于 **Unsloth → 设置 → API 密钥**.

1. 打开侧边栏，点击左下角的 **Unsloth** 头像。
2. 前往 **设置** → **API 密钥**.
3. 输入一个易于识别的名称（例如 `claude-code-macbook`).
4. *（可选）* 设置过期时间。
5. 点击 **创建**.
6. **立即复制该密钥。** Unsloth 只会存储哈希值，你将无法再次查看它。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FrWnqY5PgvZdbWK8pmlD5%2Fimage.png?alt=media&amp;token=3507e7d7-b552-447f-b503-2418802b8f6e" alt="" width="375"><figcaption></figcaption></figure></div>

所有密钥都以 `sk-unsloth-` 前缀开头。你可以随时在同一页面撤销密钥。使用已撤销密钥发出的请求将返回 `401 Unauthorized`.

### 连接到 OpenClaw

OpenClaw 从以下位置读取其配置： `~/.openclaw/openclaw.json`。添加（或合并）一个 `models` 块，包含一个 `unsloth` 指向 Unsloth 的 Anthropic Messages API 的提供方。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fs5g7Epfb2KjiQQf4MJf7%2Fopenclaw_unsloth_chat.png?alt=media&amp;token=c4de5f80-2a99-4527-bde0-c4e05e086f79" alt="" width="375"><figcaption></figcaption></figure></div>

{% code title="\~/.openclaw/openclaw\.json" %}

```json
{
  "models": {
    "mode": "merge",
    "providers": {
      "unsloth": {
        "baseUrl": "http://localhost:8888",
        "apiKey": "sk-unsloth-xxxxxxxxxxxx",
        "api": "anthropic-messages",
        "models": [
          {
            "id": "unsloth/Qwen3.6-27B-GGUF",
            "name": "unsloth/Qwen3.6-27B-GGUF"
          }
        ],
        "authHeader": true
      }
    }
  }
}
```

{% endcode %}

**说明：**

* `baseUrl` 是没有路径的 Unsloth 源地址。OpenClaw 通过 Anthropic Messages API 与 Unsloth 通信，而 Anthropic SDK 会自动追加 `/v1/messages` ，因此不要添加 `/v1` 这里（末尾带有 `/v1` 会将请求发送到 `/v1/v1/messages`).
* `api: "anthropic-messages"` 会告诉 OpenClaw 连接到 Unsloth 的 `/v1/messages` 端点。
* `authHeader: true` 会将你的密钥作为 `Authorization: Bearer …`.
* 将每个模型的 `id` 和 `name` 设置为你在 Unsloth 中加载模型时选择的名称。
* 如果你在远程机器上运行 Unsloth，请将 `localhost:8888` 替换为该机器的地址（例如 `http://10.0.0.42:8888`).

### 可选：配置模型行为

OpenClaw 通过在 Unsloth 中运行的模型进行连接。可以在启动服务器时配置运行时设置。

```bash
# 配置默认生成行为（--disable-tools 会透传 OpenClaw 自己的工具）
unsloth run \
  --model unsloth/gemma-4-26B-A4B-it-GGUF \
  --disable-tools \
  --reasoning off \
  --temp 0.6
```

{% hint style="warning" %}
使用 `--disable-tools` 在驱动 OpenClaw（或任何外部编码代理）时使用。默认情况下，Unsloth Studio 会运行其自己的服务端工具，这会吞掉代理的工具调用，因此 OpenClaw 只会回答，但不会编辑文件。 `--disable-tools` 会切换为透传模式，因此会使用 OpenClaw 自己的工具。
{% endhint %}

使用 `--reasoning off` 将思考关闭，或 `--reasoning on` 将其开启，用于支持推理的模型。

```bash
# 允许其他设备连接
unsloth run \
  --model unsloth/gemma-4-26B-A4B-it-GGUF \
  -H 0.0.0.0 \
  -p 8888
```

这会在 `0.0.0.0:8888`上启动服务器，允许本地网络中的其他设备连接。

有关更高级的运行时配置，请参阅主 [API 调优](https://unsloth.ai/docs/basics/api#unsloth-run-command) 部分。


---

# 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://unsloth.ai/docs/zh/ji-cheng/openclaw.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.
