> ## Documentation Index
> Fetch the complete documentation index at: https://dify-6c0370d8-docs-new-agent-experience.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 常见任务

> 复制即用的命令，涵盖最常运行的 difyctl 任务

> 本文档由 AI 自动翻译。如有任何不准确之处，请参考 [英文原版](/en/cli/common-tasks)。

以下所有命令均假设你已 [登录](/zh/cli/authenticate)。

## 发送消息

把消息作为位置参数传给 [`difyctl run app`](/zh/cli/reference/apps#运行应用)，即可向聊天助手、对话流、Agent 或文本生成应用发送消息。回复会打印到 stdout。

```bash theme={null}
difyctl run app 0a1b2c3d-4e5f-6789-abcd-ef0123456789 "What are your business hours?"

# save just the reply to a file; hints and errors go to stderr, not stdout
difyctl run app 0a1b2c3d-4e5f-6789-abcd-ef0123456789 "Summarize this week's tickets" > reply.txt
```

## 运行工作流

用 [`--inputs`](/zh/cli/reference/apps#运行应用) 把输入作为单个 JSON 对象传入，而不是传位置消息参数。输出会以 JSON 形式打印到 stdout。

```bash theme={null}
difyctl run app 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --inputs '{"topic":"quarterly report"}'

# read large input sets from a file instead
difyctl run app 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --inputs-file inputs.json
```

## 查找应用

用 [`difyctl get app`](/zh/cli/reference/apps#列出应用) 列出工作空间中的应用。用 `--name` 或 `--mode` 缩小范围。

```bash theme={null}
difyctl get app

# filter by name substring or mode
difyctl get app --name report --mode workflow

# list apps from every workspace you belong to
difyctl get app -A
```

## 流式输出长响应

加上 [`--stream`](/zh/cli/reference/apps#运行应用)，响应会边生成边打印，而不是在最后一次性输出。

```bash theme={null}
difyctl run app 0a1b2c3d-4e5f-6789-abcd-ef0123456789 "Draft a launch announcement" --stream
```

## 继续对话

从每条聊天助手或对话流回复后的提示中复制对话 ID，再用 [`--conversation`](/zh/cli/reference/apps#运行应用) 把它传回，即可继续同一段对话。

```bash theme={null}
difyctl run app 0a1b2c3d-4e5f-6789-abcd-ef0123456789 "What are your business hours?"
# hint: continue this conversation with --conversation 4f7d8c2a-9b1e-4c6d-8a3f-5e2b7c9d0a1f

difyctl run app 0a1b2c3d-4e5f-6789-abcd-ef0123456789 "And on weekends?" --conversation 4f7d8c2a-9b1e-4c6d-8a3f-5e2b7c9d0a1f
```

## 获取 JSON 输出用于脚本

为任意命令加上 [`-o json`](/zh/cli/reference/output-formats-and-exit-codes)，即可获得便于管道处理的原始 JSON 响应。

```bash theme={null}
difyctl run app 0a1b2c3d-4e5f-6789-abcd-ef0123456789 "What are your business hours?" -o json | jq -r '.answer'

# extract fields from list output the same way
difyctl get app -o json | jq -r '.data[].id'

# get just the IDs, one per line, no jq needed
difyctl get app -o name
```

## 切换工作空间 <Badge color="blue">Cloud</Badge>

用 [`difyctl use workspace`](/zh/cli/reference/workspaces#切换工作空间-cloud) 切换当前工作空间。用 `get workspace` 列出可用的工作空间。

```bash theme={null}
difyctl get workspace

difyctl use workspace 9c2f4e6a-8b1d-4f3e-a5c7-0d9e2b4f6a8c
# ✓ Switched to Marketing (9c2f4e6a-8b1d-4f3e-a5c7-0d9e2b4f6a8c)

# one-off: run a single command against another workspace without switching
difyctl get app --workspace 9c2f4e6a-8b1d-4f3e-a5c7-0d9e2b4f6a8c
```

## 查看应用的输入

运行一个不熟悉的应用前，用 [`difyctl describe app`](/zh/cli/reference/apps#查看应用) 查看它的应用类型和输入结构：各输入的名称、类型，以及哪些是必填项。

```bash theme={null}
difyctl describe app 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b

# get the schema as JSON to build --inputs programmatically
difyctl describe app 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b -o json
```
