> ## Documentation Index
> Fetch the complete documentation index at: https://docs2.openclaw.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 代理傳送

`openclaw agent` 可從命令列執行單次代理程式回合，不需要收到
傳入的聊天訊息。可用於指令碼工作流程、測試及
程式化傳送。完整旗標與行為參考：
[代理程式命令列介面參考](/zh-TW/cli/agent)。

## 快速開始

<Steps>
  <Step title="執行簡單的代理程式回合">
    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    openclaw agent --agent main --message "今天天氣如何？"
    ```

    透過閘道傳送訊息並印出回覆。
  </Step>

  <Step title="從檔案傳送多行提示">
    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    openclaw agent --agent ops --message-file ./task.md
    ```

    讀取有效的 UTF-8 檔案，作為代理程式訊息本文。
  </Step>

  <Step title="指定特定代理程式或工作階段">
    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    # 指定特定代理程式
    openclaw agent --agent ops --message "摘要記錄"

    # 指定電話號碼（衍生工作階段金鑰）
    openclaw agent --to +15555550123 --message "狀態更新"

    # 重複使用現有工作階段
    openclaw agent --session-id abc123 --message "繼續執行工作"

    # 指定確切的工作階段金鑰
    openclaw agent --session-key agent:ops:incident-42 --message "摘要狀態"
    ```
  </Step>

  <Step title="將回覆傳送至頻道">
    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    # 傳送至 WhatsApp（預設頻道）
    openclaw agent --to +15555550123 --message "報告已就緒" --deliver

    # 傳送至 Slack
    openclaw agent --agent ops --message "產生報告" \
      --deliver --reply-channel slack --reply-to "#reports"
    ```
  </Step>
</Steps>

## 旗標

| 旗標                          | 說明                                     |
| --------------------------- | -------------------------------------- |
| `--message <text>`          | 要傳送的行內訊息                               |
| `--message-file <path>`     | 從有效的 UTF-8 檔案讀取訊息（上限 4 MiB）            |
| `--to <dest>`               | 從目標（電話、聊天 ID）衍生工作階段金鑰                  |
| `--session-key <key>`       | 使用明確的工作階段金鑰                            |
| `--agent <id>`              | 指定已設定的代理程式（使用其 `main` 工作階段）            |
| `--session-id <id>`         | 依 ID 重複使用現有工作階段                        |
| `--model <id>`              | 覆寫此回合的模型（`provider/model` 或模型 ID）      |
| `--local`                   | 強制使用本機嵌入式執行環境（略過閘道）                    |
| `--deliver`                 | 將回覆傳送至聊天頻道                             |
| `--channel <name>`          | 傳送頻道；與 `--agent` + `--to` 搭配時，也會套用私訊範圍 |
| `--reply-to <target>`       | 覆寫傳送目標                                 |
| `--reply-channel <name>`    | 覆寫傳送頻道                                 |
| `--reply-account <id>`      | 覆寫傳送帳號 ID                              |
| `--thinking <level>`        | 設定所選模型設定檔的思考層級                         |
| `--verbose <on\|full\|off>` | 將詳細程度保存至工作階段（`full` 也會記錄工具輸出）          |
| `--timeout <seconds>`       | 覆寫代理程式逾時（預設為 600 或設定值）                 |
| `--json`                    | 輸出結構化 JSON                             |

## 行為

* 命令列介面預設會**透過閘道**執行。加入 `--local` 可強制使用
  目前機器上的嵌入式執行環境。
* `--message` 或 `--message-file` 必須且只能傳入其中一項。移除選用的 UTF-8 BOM 後，
  檔案訊息會保留多行內容。超過
  4 MiB 的檔案會在派送前遭拒。
* 暫時性握手重試後，若閘道逾時或連線關閉，
  命令將失敗並在 stderr 顯示提示；命令列介面絕不會靜默地改以
  嵌入式環境重新執行該回合。閘道仍可能完成已接受的回合，因此在重試或使用 `--local` 重新執行前，
  請先確認閘道與工作階段狀態。
* 工作階段選取：`--to` 會衍生工作階段金鑰（群組／頻道目標
  會維持隔離；直接聊天則會合併至 `main`）。同時使用 `--agent`、
  `--channel` 與 `--to` 時，路由會依循該頻道的標準
  收件者與 `session.dmScope`。穩定且僅限傳出的身分會使用
  由供應商擁有、與代理程式主要工作階段隔離的工作階段。
* `--session-key` 會選取明確的金鑰。以代理程式為前綴的金鑰必須使用
  `agent:<agent-id>:<session-key>`，而同時提供兩者時，`--agent` 必須與該代理程式 ID 相符。
  若有提供 `--agent`，不含前綴且非哨兵值的金鑰會限定在其範圍內；
  例如，`--agent ops --session-key incident-42` 會路由至
  `agent:ops:incident-42`。若沒有 `--agent`，不含前綴且非哨兵值的金鑰會限定在
  已設定的預設代理程式範圍內。只有在未提供 `--agent` 時，
  字面值 `global` 與 `unknown` 才會維持不限定範圍。
* `--reply-channel` 與 `--reply-account` 僅影響傳送。
* 思考與詳細程度旗標會保存至工作階段儲存區。
* 輸出：預設為純文字，或使用 `--json` 輸出結構化承載資料與中繼資料。
* 使用 `--json --deliver` 時，JSON 會包含已傳送、
  已抑制、部分完成及傳送失敗的傳送狀態。請參閱
  [JSON 傳送狀態](/zh-TW/cli/agent#json-delivery-status)。

## 範例

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# 輸出 JSON 的簡單回合
openclaw agent --to +15555550123 --message "追蹤記錄" --verbose on --json

# 覆寫模型的回合
openclaw agent --agent ops --model openai/gpt-5.4 --message "摘要記錄"

# 設定思考層級的回合
openclaw agent --session-id 1234 --message "摘要收件匣" --thinking medium

# 從檔案讀取多行提示
openclaw agent --agent ops --message-file ./task.md

# 確切的工作階段金鑰
openclaw agent --session-key agent:ops:incident-42 --message "摘要狀態"

# 限定於代理程式的舊版金鑰
openclaw agent --agent ops --session-key incident-42 --message "摘要狀態"

# 傳送至不同於工作階段的頻道
openclaw agent --agent ops --message "警示" --deliver --reply-channel telegram --reply-to "@admin"
```

## 相關內容

<CardGroup cols={2}>
  <Card title="代理程式命令列介面參考" href="/zh-TW/cli/agent" icon="terminal">
    完整的 `openclaw agent` 旗標與選項參考。
  </Card>

  <Card title="子代理程式" href="/zh-TW/tools/subagents" icon="users">
    在背景中建立子代理程式。
  </Card>

  <Card title="工作階段" href="/zh-TW/concepts/session" icon="comments">
    工作階段金鑰的運作方式，以及 `--to`、`--agent` 與 `--session-id` 如何解析這些金鑰。
  </Card>

  <Card title="斜線命令" href="/zh-TW/tools/slash-commands" icon="slash">
    代理程式工作階段內使用的原生命令目錄。
  </Card>
</CardGroup>
