qwen-audio-agent 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,7 +23,13 @@ Agent 也应该始终在场。
23
23
 
24
24
  “已经好了。”
25
25
 
26
- ## 核心特色
26
+ ## 对话继续,任务也在继续
27
+
28
+ 对话不会因为后台任务而停下;任务完成后,结果会自然回到当前对话:
29
+
30
+ https://github.com/user-attachments/assets/42022655-36d1-46b2-9c26-ff0765284000
31
+
32
+ ### 核心特色
27
33
 
28
34
  - 全双工实时语音交互、自然打断和持续多轮对话
29
35
  - 一键连接你喜欢的各种 Agent,使用已有的模型、工具、MCP、Skill
@@ -32,7 +38,7 @@ Agent 也应该始终在场。
32
38
  - 支持 WebUI、终端 TUI 和 macOS 桌面悬浮球
33
39
  - 支持本地用户档案与跨会话个人记忆
34
40
 
35
- ## 对话继续,任务也在继续
41
+ ## 参考架构
36
42
 
37
43
  ![qwen-audio-agent 原理图](docs/architecture-overview.png)
38
44
 
@@ -121,35 +127,26 @@ npm install -g git+https://github.com/QwenAudio/qwen-audio-agent.git
121
127
  qwenaudio config
122
128
  ```
123
129
 
124
- 2. 打开命令显示的 `config.env`,填写 DashScope API Key,并选择 OpenClaw:
130
+ 2. 打开命令显示的 `config.env`,填写 DashScope API Key。需要执行后台任务时,
131
+ 再选择 OpenClaw 或其他后台 Agent:
125
132
 
126
133
  ```dotenv
127
134
  DASHSCOPE_API_KEY=your-key
135
+ # 语音前台模型:qwen-audio-3.0-realtime-flash 或 qwen-audio-3.0-realtime-plus(默认)
136
+ QWEN_AUDIO_REALTIME_MODEL=qwen-audio-3.0-realtime-plus
137
+ # 后台Agent:可选,不设置或设置为 none 时,启动仅前台模式
128
138
  AGENT_PROTOCOL=openclaw
139
+ # 后台模型:可为空,留空则沿用 Agent 自身的用户配置
129
140
  QWEN_AUDIO_AGENT_BACKEND_MODEL=qwen3.7-max
130
141
  ```
131
142
 
132
- 3. 只读检查后台 Agent 是否已经准备好:
133
-
134
- ```bash
135
- qwenaudio setup
136
- ```
137
-
138
- 该命令不会安装 Agent、触发登录或修改配置。也可以只检查一个后台,或输出供
139
- 桌面版和脚本使用的结构化结果:
140
-
141
- ```bash
142
- qwenaudio setup --backend openclaw
143
- qwenaudio setup --json
144
- ```
145
-
146
- 4. 在一个终端中启动 Gateway:
143
+ 3. 在一个终端中启动 Gateway:
147
144
 
148
145
  ```bash
149
146
  qwenaudio
150
147
  ```
151
148
 
152
- 5. 另开一个终端,启动 TUI:
149
+ 4. 另开一个终端,启动 TUI:
153
150
 
154
151
  ```bash
155
152
  qwenaudio tui
@@ -216,10 +213,22 @@ qwenaudio gateway uninstall
216
213
 
217
214
  ## 选择后台 Agent
218
215
 
219
- 通过 `AGENT_PROTOCOL` 选择后台 Agent(必填,没有默认值)。OpenCode 和 OpenClaw
220
- 支持自动下载;配置 `DASHSCOPE_API_KEY` 和 `QWEN_AUDIO_AGENT_BACKEND_MODEL`
221
- 后即可自动接入百炼模型。未指定后台模型且用户已经安装并配置对应 Agent 时,则
222
- 完整复用用户环境。使用 OpenClaw:
216
+ `AGENT_PROTOCOL` 是可选配置。留空时,Gateway 以仅前台模式运行,实时语音聊天
217
+ 保持可用;如果请求需要后台执行,前台会明确说明当前没有可用的后台 Agent。
218
+ 也可以在命令行中使用 `qwenaudio --backend none`,明确要求仅启动前台模式。
219
+
220
+ 通过 `AGENT_PROTOCOL` 环境变量或 `--backend` 参数选择后台 Agent。选择后,
221
+ OpenCode 和 OpenClaw 支持自动下载安装;配置
222
+ `DASHSCOPE_API_KEY` 和 `QWEN_AUDIO_AGENT_BACKEND_MODEL` 后即可自动接入百炼
223
+ 模型。未指定后台模型且用户已经安装并配置对应 Agent 时,则完整复用用户环境。
224
+
225
+ 查看当前可用的后台 Agent:
226
+
227
+ ```bash
228
+ qwenaudio setup
229
+ ```
230
+
231
+ 使用 OpenClaw:
223
232
 
224
233
  ```dotenv
225
234
  AGENT_PROTOCOL=openclaw
@@ -257,15 +266,6 @@ ACP_ARGS=["--acp"]
257
266
 
258
267
  通用 ACP 入口不需要修改 Gateway 代码。命令、参数、显示名称和工作目录可分别通过 `ACP_COMMAND`、`ACP_ARGS`、`ACP_LABEL` 和 `ACP_WORKSPACE` 配置。
259
268
 
260
- 后台模型遵循以下规则:
261
-
262
- - 未指定模型:Gateway 不传模型、不调用 ACP 模型设置接口,也不猜测默认模型。
263
- - 新建 Session:完全由所选 Agent 根据用户自己的配置选择模型。
264
- - 恢复 Session:完全由所选 Agent 保留该 Session 原来的模型。
265
- - 显式设置唯一的后台模型变量 `QWEN_AUDIO_AGENT_BACKEND_MODEL`:Gateway 才通过
266
- ACP 强制覆盖 qwen-audio-agent 管理的 Session,并验证设置结果;不支持或无法
267
- 确认生效时会明确报错。
268
-
269
269
  后台权限默认使用 `native`,由后台 Agent 在需要时询问。只有在可信项目中,并且
270
270
  明确接受自动执行命令和修改文件时,才应启用:
271
271
 
package/README_EN.md CHANGED
@@ -27,7 +27,14 @@ task is complete, naturally tells you:
27
27
 
28
28
  “It’s ready.”
29
29
 
30
- ## Core Features
30
+ ## Keep Talking While Tasks Keep Running
31
+
32
+ Conversation continues while the Agent works in the background. When the task
33
+ is done, the result returns naturally to the conversation:
34
+
35
+ https://github.com/user-attachments/assets/42022655-36d1-46b2-9c26-ff0765284000
36
+
37
+ ### Core Features
31
38
 
32
39
  - Full-duplex realtime voice interaction, natural interruption, and continuous
33
40
  multi-turn conversation
@@ -40,7 +47,7 @@ task is complete, naturally tells you:
40
47
  - WebUI, terminal TUI, and a macOS desktop orb
41
48
  - Local user profile and personal memory across sessions
42
49
 
43
- ## Keep Talking While Tasks Keep Running
50
+ ## Reference Architecture
44
51
 
45
52
  ![qwen-audio-agent architecture](docs/architecture-overview-en.png)
46
53
 
@@ -141,37 +148,26 @@ for details.
141
148
  qwenaudio config
142
149
  ```
143
150
 
144
- 2. Open the displayed `config.env` file, add your DashScope API Key, and select
145
- OpenClaw:
151
+ 2. Open the displayed `config.env` file and add your DashScope API Key. Select
152
+ OpenClaw or another backend Agent only when you need background tasks:
146
153
 
147
154
  ```dotenv
148
155
  DASHSCOPE_API_KEY=your-key
149
- AGENT_PROTOCOL=openclaw
150
- QWEN_AUDIO_AGENT_BACKEND_MODEL=qwen3.7-max
156
+ # Voice model: qwen-audio-3.0-realtime-flash or qwen-audio-3.0-realtime-plus (default)
157
+ QWEN_AUDIO_REALTIME_MODEL=qwen-audio-3.0-realtime-plus
158
+ # Optional; uncomment when background tasks are needed
159
+ # AGENT_PROTOCOL=openclaw
160
+ # Backend model: can be left empty; the Agent uses its own user configuration
161
+ # QWEN_AUDIO_AGENT_BACKEND_MODEL=qwen3.7-max
151
162
  ```
152
163
 
153
- 3. Check that the backend Agent is ready without changing it:
154
-
155
- ```bash
156
- qwenaudio setup
157
- ```
158
-
159
- This command does not install an Agent, start authentication, or modify
160
- configuration. You can inspect one backend or produce structured output for
161
- the desktop app and scripts:
162
-
163
- ```bash
164
- qwenaudio setup --backend openclaw
165
- qwenaudio setup --json
166
- ```
167
-
168
- 4. Start the Gateway in one terminal:
164
+ 3. Start the Gateway in one terminal:
169
165
 
170
166
  ```bash
171
167
  qwenaudio
172
168
  ```
173
169
 
174
- 5. Open another terminal and start the TUI:
170
+ 4. Open another terminal and start the TUI:
175
171
 
176
172
  ```bash
177
173
  qwenaudio tui
@@ -243,12 +239,27 @@ qwenaudio gateway uninstall
243
239
 
244
240
  ## Choose a Backend Agent
245
241
 
246
- Select the backend Agent with `AGENT_PROTOCOL` (required, no default value).
247
- OpenCode and OpenClaw can be downloaded automatically. Configure
248
- `DASHSCOPE_API_KEY` and `QWEN_AUDIO_AGENT_BACKEND_MODEL` to connect them to a
249
- Bailian model automatically. When no backend model is specified and the Agent
250
- is already installed and configured, qwen-audio-agent fully reuses the user's
251
- existing environment. Use OpenClaw:
242
+ `AGENT_PROTOCOL` is optional. When it is empty, the Gateway runs in
243
+ frontend-only mode and realtime voice chat remains available. If a request
244
+ requires background execution, the frontend clearly explains that no backend
245
+ Agent is available. You can also run `qwenaudio --backend none` to explicitly
246
+ start in frontend-only mode.
247
+
248
+ Select the backend Agent with `AGENT_PROTOCOL` or `--backend`. After selecting
249
+ one, OpenCode and OpenClaw can be downloaded automatically. Configure
250
+ `DASHSCOPE_API_KEY` and
251
+ `QWEN_AUDIO_AGENT_BACKEND_MODEL` to connect them to a Bailian model
252
+ automatically. When no backend model is specified and the Agent is already
253
+ installed and configured, qwen-audio-agent fully reuses the user's existing
254
+ environment.
255
+
256
+ Check which backends are available:
257
+
258
+ ```bash
259
+ qwenaudio setup
260
+ ```
261
+
262
+ Use OpenClaw:
252
263
 
253
264
  ```dotenv
254
265
  AGENT_PROTOCOL=openclaw
@@ -287,19 +298,6 @@ ACP_ARGS=["--acp"]
287
298
 
288
299
  The generic ACP entry point requires no Gateway code changes. Configure its command, arguments, display label, and workspace with `ACP_COMMAND`, `ACP_ARGS`, `ACP_LABEL`, and `ACP_WORKSPACE`.
289
300
 
290
- Backend model selection follows these rules:
291
-
292
- - With no model configured, the Gateway sends no model, never calls the ACP
293
- model-setting interface, and does not guess a default.
294
- - For a new Session, the selected Agent chooses the model entirely from the
295
- user's own configuration.
296
- - For a resumed Session, the selected Agent preserves that Session's existing
297
- model.
298
- - Only the single backend model setting, `QWEN_AUDIO_AGENT_BACKEND_MODEL`,
299
- makes the Gateway force the model for Sessions managed by qwen-audio-agent
300
- and verify the result. A clear error is returned when the Agent does not
301
- support the model or the override cannot be verified.
302
-
303
301
  Backend permissions default to `native`, so the backend Agent asks when
304
302
  permission is required. Enable the following option only in trusted projects
305
303
  and only if you explicitly accept automatic command execution and file
package/cli/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qwen-audio-agent/cli",
3
3
  "private": true,
4
- "version": "0.11.0",
4
+ "version": "0.12.0",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "qwenaudio": "./bin/qwenaudio.mjs"
@@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto'
2
2
  import {
3
3
  backendDefinition,
4
4
  backendNames,
5
+ normalizeBackendProtocol,
5
6
  } from '../../shared/backend-catalog.mjs'
6
7
 
7
8
  const COMMANDS = new Set([
@@ -69,7 +70,7 @@ export function parseArguments(argv, env = process.env) {
69
70
  audioMode: String(
70
71
  env.QWEN_AUDIO_AGENT_TUI_AUDIO_MODE || 'half',
71
72
  ).toLowerCase(),
72
- backend: String(env.AGENT_PROTOCOL || '').toLowerCase(),
73
+ backend: normalizeBackendProtocol(env.AGENT_PROTOCOL),
73
74
  backendPermissionMode: String(
74
75
  env.QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE || 'native',
75
76
  ).toLowerCase(),
@@ -91,7 +92,9 @@ export function parseArguments(argv, env = process.env) {
91
92
  options.url = nextValue(args, index++, '--url')
92
93
  options.gatewayConfigurationSpecified = true
93
94
  } else if (argument === '--backend') {
94
- options.backend = nextValue(args, index++, '--backend').toLowerCase()
95
+ options.backend = normalizeBackendProtocol(
96
+ nextValue(args, index++, '--backend'),
97
+ )
95
98
  options.backendSpecified = true
96
99
  options.gatewayConfigurationSpecified = true
97
100
  } else if (argument === '--backend-agent') {
@@ -127,7 +130,10 @@ export function parseArguments(argv, env = process.env) {
127
130
  `不支持的后台:${options.backend}(可选 ${backendNames().join('、')})`,
128
131
  )
129
132
  }
130
- if (!BACKEND_PERMISSION_MODES.has(options.backendPermissionMode)) {
133
+ if (
134
+ options.backend
135
+ && !BACKEND_PERMISSION_MODES.has(options.backendPermissionMode)
136
+ ) {
131
137
  throw new Error(
132
138
  `不支持的后台权限模式:${options.backendPermissionMode}`
133
139
  + '(可选 native、full)',
@@ -177,16 +183,6 @@ export function parseArguments(argv, env = process.env) {
177
183
  `${definition.label} 不支持 Gateway 统一最高权限模式`,
178
184
  )
179
185
  }
180
- if (
181
- command === 'gateway'
182
- && options.gatewayAction === 'run'
183
- && !options.backend
184
- ) {
185
- throw new Error(
186
- '必须指定后台 Agent:在 config.env 设置 AGENT_PROTOCOL,'
187
- + `或使用 --backend(可选 ${backendNames().join('、')})`,
188
- )
189
- }
190
186
  options.sessionId = String(options.sessionId || '').trim()
191
187
  if (!options.sessionId) throw new Error('--session 不能为空')
192
188
  return options
@@ -212,7 +208,7 @@ export function helpText() {
212
208
  '',
213
209
  'Gateway 选项:',
214
210
  ' --url URL Gateway 地址(默认 http://127.0.0.1:3101)',
215
- ' --backend NAME 必填:openclaw、opencode、qoder、hermes、codebuddy、codex、claude 或 acp(也可在 config.env 设置 AGENT_PROTOCOL)',
211
+ ' --backend NAME 可选:openclaw、opencode、qoder、hermes、codebuddy、codex、claude、acp 或 none;不设置或使用 none 时仅前台聊天',
216
212
  ' --backend-permission-mode MODE native(默认)或 full(最高权限)',
217
213
  ' --backend-url URL 后台 Server 地址',
218
214
  ' --backend-agent ID 指定协调 Agent',
@@ -32,10 +32,17 @@ async function runMinimal(options) {
32
32
  }
33
33
 
34
34
  function applyGatewayOptions(env, options) {
35
- env.AGENT_PROTOCOL = options.backend
35
+ // Keep an explicit empty value so the environment loader cannot restore a
36
+ // backend from config.env after --backend none selected frontend-only mode.
37
+ env.AGENT_PROTOCOL = options.backend || ''
36
38
  const definition = backendDefinition(options.backend)
37
- env.QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE = options.backendPermissionMode
38
- if (options.backendAgent) {
39
+ if (options.backend) {
40
+ env.QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE =
41
+ options.backendPermissionMode
42
+ } else {
43
+ delete env.QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE
44
+ }
45
+ if (options.backend && options.backendAgent) {
39
46
  env.QWEN_AUDIO_AGENT_BACKEND_AGENT = options.backendAgent
40
47
  } else {
41
48
  delete env.QWEN_AUDIO_AGENT_BACKEND_AGENT
@@ -46,6 +53,7 @@ function applyGatewayOptions(env, options) {
46
53
  }
47
54
 
48
55
  function gatewaySummary(health) {
56
+ if (health?.backend?.enabled === false) return '仅前台聊天模式'
49
57
  const label = health?.backend?.label
50
58
  || health?.backend?.kind
51
59
  || health?.backend?.protocol
@@ -84,7 +92,8 @@ export async function main(argv, {
84
92
  prepareRuntime = options => ensureRuntime(options, { root, env }),
85
93
  inspectGateway = url => readGatewayHealth(url),
86
94
  manageService = (action, options) => manageGatewayService(action, options),
87
- waitForService = url => waitForGateway(url, { requireBackend: true }),
95
+ waitForService = (url, { requireBackend = false } = {}) =>
96
+ waitForGateway(url, { requireBackend }),
88
97
  waitForServiceStop = url => waitForGatewayStop(url, { inspectGateway }),
89
98
  runWebUi = options => launchWebUi(options),
90
99
  acquireInstance = directory => acquireCliInstance(directory),
@@ -156,7 +165,9 @@ export async function main(argv, {
156
165
  )
157
166
  const serviceUrl = service.installedMetadata?.url || currentUrl
158
167
  if (['install', 'start', 'restart'].includes(options.gatewayAction)) {
159
- const ready = await waitForService(serviceUrl)
168
+ const ready = await waitForService(serviceUrl, {
169
+ requireBackend: Boolean(options.backend),
170
+ })
160
171
  stdout.write(
161
172
  `Gateway 后台服务已${
162
173
  options.gatewayAction === 'restart' ? '重启' : '启动'
@@ -3,6 +3,7 @@ import { resolve } from 'node:path'
3
3
  import {
4
4
  backendDefinition,
5
5
  backendNames,
6
+ normalizeBackendProtocol,
6
7
  } from '../../shared/backend-catalog.mjs'
7
8
  import {
8
9
  loadRuntimeEnvironment,
@@ -27,13 +28,19 @@ function normalizedOrigin(value) {
27
28
  }
28
29
 
29
30
  export function resolveBackend(options = {}, env = process.env) {
30
- const protocol = String(
31
- options.backend || env.AGENT_PROTOCOL || '',
32
- ).toLowerCase()
33
- if (!protocol) throw new Error(
34
- '必须指定后台 Agent:在 config.env 设置 AGENT_PROTOCOL,'
35
- + `或使用 --backend(可选 ${backendNames().join('、')})`,
31
+ const protocol = normalizeBackendProtocol(
32
+ options.backend || env.AGENT_PROTOCOL,
36
33
  )
34
+ if (!protocol) {
35
+ return {
36
+ enabled: false,
37
+ protocol: null,
38
+ ownership: null,
39
+ permissionMode: null,
40
+ agentId: '',
41
+ baseUrl: null,
42
+ }
43
+ }
37
44
  const definition = backendDefinition(protocol)
38
45
  if (!definition) throw new Error(
39
46
  `不支持的后台 Agent:${protocol}(可选 ${backendNames().join('、')})`,
@@ -70,6 +77,15 @@ export function resolveBackend(options = {}, env = process.env) {
70
77
  }
71
78
 
72
79
  export function assertGatewayCompatibility(health, backend) {
80
+ const actualEnabled = health?.backend?.enabled !== false
81
+ if (!backend.protocol) {
82
+ if (!actualEnabled) return
83
+ const actualProtocol = health?.backend?.kind || health?.backend?.protocol
84
+ throw new Error(
85
+ `现有 Gateway 使用 ${actualProtocol || '后台 Agent'},`
86
+ + '与当前仅前台聊天配置不一致',
87
+ )
88
+ }
73
89
  const actualProtocol = health?.backend?.kind || health?.backend?.protocol
74
90
  const actualBaseUrl = health?.backend?.baseUrl
75
91
  const actualOwnership = health?.backend?.ownership
@@ -169,6 +185,17 @@ function waitForReadiness(child, readiness, label) {
169
185
  }
170
186
 
171
187
  function backendEnvironment(env, backend) {
188
+ if (!backend.protocol) {
189
+ const next = {
190
+ ...env,
191
+ // An empty value is an intentional override. Deleting it would let the
192
+ // child Gateway reload AGENT_PROTOCOL from config.env.
193
+ AGENT_PROTOCOL: '',
194
+ }
195
+ delete next.QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE
196
+ delete next.QWEN_AUDIO_AGENT_BACKEND_AGENT
197
+ return next
198
+ }
172
199
  const definition = backendDefinition(backend.protocol)
173
200
  const next = {
174
201
  ...env,
@@ -285,8 +312,9 @@ export async function ensureRuntime(options, {
285
312
  const runtime = new ManagedRuntime([], { platform })
286
313
  const local = isLocalGateway(options.url)
287
314
  const backend = resolveBackend(options, env)
288
- const backendLabel = backendDefinition(backend.protocol)?.label
289
- || backend.protocol
315
+ const backendLabel = backend.protocol
316
+ ? backendDefinition(backend.protocol)?.label || backend.protocol
317
+ : '后台 Agent'
290
318
  let health = await readGatewayHealth(options.url, fetchImpl)
291
319
  const existingGateway = Boolean(health)
292
320
 
@@ -312,7 +340,9 @@ export async function ensureRuntime(options, {
312
340
  gateway,
313
341
  waitForGateway(options.url, {
314
342
  fetchImpl,
315
- requireBackend: options.waitForBackend !== false,
343
+ requireBackend: Boolean(
344
+ backend.protocol && options.waitForBackend !== false
345
+ ),
316
346
  }),
317
347
  'Gateway',
318
348
  )
@@ -323,11 +353,17 @@ export async function ensureRuntime(options, {
323
353
  if (existingGateway || backend.ownership === 'external') {
324
354
  assertGatewayCompatibility(health, backend)
325
355
  } else {
326
- const actualProtocol = health?.backend?.kind || health?.backend?.protocol
327
- if (actualProtocol !== backend.protocol) {
356
+ const actualProtocol = (
357
+ health?.backend?.kind || health?.backend?.protocol || null
358
+ )
359
+ const actualEnabled = health?.backend?.enabled !== false
360
+ if (
361
+ actualProtocol !== backend.protocol
362
+ || actualEnabled !== Boolean(backend.protocol)
363
+ ) {
328
364
  throw new Error(
329
- `Gateway 启动了 ${actualProtocol || '未知'} 后台,`
330
- + `与当前配置 ${backend.protocol} 不一致`,
365
+ `Gateway 启动了 ${actualProtocol || '仅前台聊天模式'},`
366
+ + `与当前配置 ${backend.protocol || '仅前台聊天模式'} 不一致`,
331
367
  )
332
368
  }
333
369
  }
@@ -340,7 +376,11 @@ export async function ensureRuntime(options, {
340
376
  )
341
377
  }
342
378
 
343
- if (health.backend?.ok !== true && options.waitForBackend !== false) {
379
+ if (
380
+ backend.protocol
381
+ && health.backend?.ok !== true
382
+ && options.waitForBackend !== false
383
+ ) {
344
384
  throw new Error(
345
385
  backend.ownership === 'external'
346
386
  ? `未连接到已有 ${backendLabel} 后台服务,请先启动并检查 ${backend.baseUrl}`
@@ -45,10 +45,15 @@ JSON 输出与 CLI 使用同一个共享检测模块,可供桌面版和其他
45
45
 
46
46
  ## 最小配置
47
47
 
48
- 最小配置需要填写实时语音凭据,并显式选择后台 Agent(以 OpenClaw 为例):
48
+ 最小配置只需要填写实时语音凭据:
49
49
 
50
50
  ```dotenv
51
51
  DASHSCOPE_API_KEY=your-key
52
+ ```
53
+
54
+ 需要执行后台任务时,再选择后台 Agent(以 OpenClaw 为例):
55
+
56
+ ```dotenv
52
57
  AGENT_PROTOCOL=openclaw
53
58
  QWEN_AUDIO_AGENT_BACKEND_MODEL=qwen3.7-max
54
59
  ```
@@ -101,7 +106,11 @@ tasks.json # 后台任务、结果和待播报通知的恢复状态
101
106
 
102
107
  ## 选择后台
103
108
 
104
- `AGENT_PROTOCOL` 没有默认值,必须显式指定。OpenClaw 默认地址为 `http://127.0.0.1:18789`:
109
+ `AGENT_PROTOCOL` 没有默认值,也是可选配置。留空时 Gateway 仅提供前台实时语音
110
+ 聊天;需要后台执行的请求会返回明确错误,不会创建任务或猜测执行结果。
111
+ 也可以使用 `qwenaudio --backend none` 显式启动仅前台模式。
112
+
113
+ OpenClaw 默认地址为 `http://127.0.0.1:18789`:
105
114
 
106
115
  ```dotenv
107
116
  AGENT_PROTOCOL=openclaw
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qwen-audio-agent",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "A realtime voice frontend for mainstream AI agents.",
5
5
  "author": "qwen-audio-agent contributors",
6
6
  "license": "Apache-2.0",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qwen-audio-agent/server",
3
3
  "private": true,
4
- "version": "0.11.0",
4
+ "version": "0.12.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "node --watch src/index.mjs",
@@ -187,17 +187,14 @@ export class AgentClient {
187
187
  }
188
188
  }
189
189
 
190
- // The shared client is created lazily so that importing this module never
191
- // fails in environments without AGENT_PROTOCOL, such as unit tests. The
192
- // Gateway itself fails fast in resolveManagedBackend before this point.
193
190
  let sharedAgent = null
194
191
 
195
192
  function requireAgent() {
196
193
  if (!sharedAgent) {
197
194
  if (!config.agentProtocol) {
198
- throw new Error(
199
- '必须指定后台 Agent:请在 config.env 中设置 AGENT_PROTOCOL',
200
- )
195
+ throw new AgentError('当前未配置后台 Agent', {
196
+ protocol: '',
197
+ })
201
198
  }
202
199
  sharedAgent = new AgentClient()
203
200
  }
@@ -205,14 +202,34 @@ function requireAgent() {
205
202
  }
206
203
 
207
204
  export const agent = {
205
+ get enabled() {
206
+ return Boolean(config.agentProtocol)
207
+ },
208
208
  get protocol() {
209
- return requireAgent().protocol
209
+ return config.agentProtocol || null
210
210
  },
211
211
  get label() {
212
- return requireAgent().label
212
+ return config.agentProtocol ? requireAgent().label : '仅前台聊天'
213
213
  },
214
- describe: () => requireAgent().describe(),
215
- health: () => requireAgent().health(),
214
+ describe: () => config.agentProtocol
215
+ ? requireAgent().describe()
216
+ : {
217
+ enabled: false,
218
+ protocol: null,
219
+ kind: null,
220
+ label: '仅前台聊天',
221
+ status: 'not_configured',
222
+ capabilities: {
223
+ backendUi: false,
224
+ },
225
+ },
226
+ health: () => config.agentProtocol
227
+ ? requireAgent().health()
228
+ : Promise.resolve({
229
+ enabled: false,
230
+ ok: true,
231
+ status: 'not_configured',
232
+ }),
216
233
  runCoordinator: (message, options = {}) =>
217
234
  requireAgent().runCoordinator(message, options),
218
235
  respondPermission: (id, decision, options = {}) =>
@@ -221,8 +238,9 @@ export const agent = {
221
238
  requireAgent().cancelDelegatedWork(workId, options),
222
239
  queryDelegatedWork: (workId, question, options = {}) =>
223
240
  requireAgent().queryDelegatedWork(workId, question, options),
224
- canRecoverDelegatedWork: task =>
225
- requireAgent().canRecoverDelegatedWork(task),
241
+ canRecoverDelegatedWork: task => config.agentProtocol
242
+ ? requireAgent().canRecoverDelegatedWork(task)
243
+ : false,
226
244
  recoverDelegatedWork: (task, options = {}) =>
227
245
  requireAgent().recoverDelegatedWork(task, options),
228
246
  uiUrl: (options = {}) => requireAgent().uiUrl(options),
@@ -233,7 +233,10 @@ realtimeGateway = attachRealtimeGateway(server, {
233
233
  identityManager,
234
234
  memoryStore: frontendMemory,
235
235
  coordinator,
236
- coordinatorAvailable: async () => (await agent.health()).ok === true,
236
+ coordinatorAvailable: async () => ({
237
+ enabled: agent.enabled,
238
+ ok: agent.enabled && (await agent.health()).ok === true,
239
+ }),
237
240
  respondPermission: (id, decision, options) => (
238
241
  agent.respondPermission(id, decision, options)
239
242
  ),
@@ -4,6 +4,7 @@ import { loadRuntimeEnvironment } from '../../../shared/runtime-environment.mjs'
4
4
  import {
5
5
  backendDefinition,
6
6
  backendNames,
7
+ normalizeBackendProtocol,
7
8
  } from '../../../shared/backend-catalog.mjs'
8
9
 
9
10
  const here = dirname(fileURLToPath(import.meta.url))
@@ -134,9 +135,9 @@ export function resolveBackendModels(env = process.env) {
134
135
  }
135
136
  }
136
137
 
137
- const configuredAgentProtocol = String(
138
- process.env.AGENT_PROTOCOL || '',
139
- ).toLowerCase()
138
+ const configuredAgentProtocol = normalizeBackendProtocol(
139
+ process.env.AGENT_PROTOCOL,
140
+ )
140
141
  const backendOwnership = 'owned'
141
142
  const backendModels = resolveBackendModels()
142
143
  const managedOpenClawBailian = (
@@ -148,7 +149,10 @@ const managedOpenClawBailian = (
148
149
  const backendPermissionMode = String(
149
150
  process.env.QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE || 'native',
150
151
  ).toLowerCase()
151
- if (!['native', 'full'].includes(backendPermissionMode)) {
152
+ if (
153
+ configuredAgentProtocol
154
+ && !['native', 'full'].includes(backendPermissionMode)
155
+ ) {
152
156
  throw new Error(
153
157
  `不支持的后台权限模式:${backendPermissionMode}(可选 native、full)`,
154
158
  )
@@ -18,8 +18,13 @@ const drivers = new Map([
18
18
  genericAcpRuntimeDriver,
19
19
  ].map(driver => [driver.id, driver]))
20
20
 
21
- export function backendRuntimeDriver(protocol) {
21
+ export function normalizeBackendRuntimeProtocol(protocol) {
22
22
  const id = String(protocol || '').trim().toLowerCase()
23
+ return id === 'none' ? '' : id
24
+ }
25
+
26
+ export function backendRuntimeDriver(protocol) {
27
+ const id = normalizeBackendRuntimeProtocol(protocol)
23
28
  const driver = drivers.get(id)
24
29
  if (!driver) throw new Error(`不支持的后台 Agent:${id}`)
25
30
  return driver
@@ -1,7 +1,10 @@
1
1
  import { spawn } from 'node:child_process'
2
2
  import { createConnection, createServer } from 'node:net'
3
3
  import { resolve } from 'node:path'
4
- import { backendRuntimeDriver } from './backend-drivers/registry.mjs'
4
+ import {
5
+ backendRuntimeDriver,
6
+ normalizeBackendRuntimeProtocol,
7
+ } from './backend-drivers/registry.mjs'
5
8
 
6
9
  const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '::1', '[::1]'])
7
10
 
@@ -16,12 +19,8 @@ function permissionMode(env) {
16
19
  }
17
20
 
18
21
  export function resolveManagedBackend(env = process.env) {
19
- const protocol = String(env.AGENT_PROTOCOL || '').toLowerCase()
20
- if (!protocol) {
21
- throw new Error(
22
- '必须指定后台 Agent:请在 config.env 中设置 AGENT_PROTOCOL',
23
- )
24
- }
22
+ const protocol = normalizeBackendRuntimeProtocol(env.AGENT_PROTOCOL)
23
+ if (!protocol) return null
25
24
  const driver = backendRuntimeDriver(protocol)
26
25
  const resolvedPermissionMode = permissionMode(env)
27
26
  const ownership = driver.resolveOwnership?.({ env }) || 'owned'
@@ -177,6 +176,7 @@ export async function startManagedBackend({
177
176
  findFreeAddress = allocateBackendAddress,
178
177
  } = {}) {
179
178
  const backend = resolveManagedBackend(env)
179
+ if (!backend) return new ManagedBackendRuntime(null, { platform })
180
180
  const driver = backendRuntimeDriver(backend.protocol)
181
181
  applyBackendPermissionMode(env, backend)
182
182
  if (!driver.separateManagedProcess) {
@@ -309,20 +309,44 @@ export class ToolCallHandler {
309
309
  }
310
310
 
311
311
  let coordinatorReady = false
312
+ let coordinatorConfigured = true
312
313
  try {
313
- coordinatorReady = await this.coordinatorAvailable()
314
+ const availability = await this.coordinatorAvailable()
315
+ if (availability && typeof availability === 'object') {
316
+ coordinatorConfigured = availability.enabled !== false
317
+ coordinatorReady = (
318
+ coordinatorConfigured && availability.ok === true
319
+ )
320
+ } else {
321
+ coordinatorReady = availability === true
322
+ }
314
323
  } catch {
315
324
  coordinatorReady = false
316
325
  }
317
326
  if (!coordinatorReady) {
327
+ const userMessage = coordinatorConfigured
328
+ ? '后台 Agent 当前未连接。你仍然可以继续普通聊天,后台恢复后再执行这项工作。'
329
+ : '当前未配置后台 Agent,无法执行需要后台处理的任务。你仍然可以继续普通聊天。'
318
330
  await this.sendOutput(
319
331
  callId,
320
332
  failure(
321
333
  'backend_unavailable',
322
- '后台 Agent 当前未连接。可以继续语音交流,连接 OpenCode 或 OpenClaw 后再执行这项工作。',
323
- { retryable: true },
334
+ userMessage,
335
+ { retryable: coordinatorConfigured },
324
336
  ),
325
337
  turnId,
338
+ null,
339
+ {
340
+ response: {
341
+ instructions: [
342
+ coordinatorConfigured
343
+ ? '直接向用户说明后台 Agent 当前未连接,暂时无法执行这项后台任务。'
344
+ : '直接向用户说明当前未配置后台 Agent,无法执行这项后台任务。',
345
+ '不要再次调用后台工具,也不要声称任务已经创建或正在执行。',
346
+ '可以继续完成不需要后台 Agent 的聊天和回答。',
347
+ ].join('\n'),
348
+ },
349
+ },
326
350
  )
327
351
  return
328
352
  }
@@ -46,9 +46,14 @@ const definitions = new Map([
46
46
  ])
47
47
 
48
48
  export function backendDefinition(protocol) {
49
- return definitions.get(String(protocol || '').trim().toLowerCase()) || null
49
+ return definitions.get(normalizeBackendProtocol(protocol)) || null
50
50
  }
51
51
 
52
52
  export function backendNames() {
53
53
  return [...definitions.keys()]
54
54
  }
55
+
56
+ export function normalizeBackendProtocol(value) {
57
+ const protocol = String(value || '').trim().toLowerCase()
58
+ return protocol === 'none' ? '' : protocol
59
+ }
@@ -20,7 +20,8 @@ const USER_CONFIG_TEMPLATE = [
20
20
  'DASHSCOPE_API_KEY=',
21
21
  'QWEN_AUDIO_REALTIME_PROVIDER=dashscope',
22
22
  '',
23
- '# 必填:选择后台 Agent(openclaw、opencode、qoder、hermes、codebuddy、codex、claude 或 acp)',
23
+ '# 可选:选择后台 Agent;留空时仅使用前台实时语音聊天',
24
+ '# 可选 openclaw、opencode、qoder、hermes、codebuddy、codex、claude、acp 或 none',
24
25
  'AGENT_PROTOCOL=',
25
26
  '# 权限模式:native(后台自行询问)或 full(最高权限;仅支持安全映射的后端)',
26
27
  '# QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE=native',
package/tui/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qwen-audio-agent/tui",
3
3
  "private": true,
4
- "version": "0.11.0",
4
+ "version": "0.12.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "node src/index.mjs",