qwen-audio-agent 0.11.0 → 0.12.1
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 +33 -32
- package/README_EN.md +41 -42
- package/cli/package.json +1 -1
- package/cli/src/arguments.mjs +10 -14
- package/cli/src/launcher.mjs +16 -5
- package/cli/src/runtime.mjs +54 -14
- package/config/frontend-agent/PROMPT.md +11 -29
- package/docs/configuration.md +11 -2
- package/package.json +1 -1
- package/server/package.json +1 -1
- package/server/src/agent/agent-client.mjs +30 -12
- package/server/src/app/bootstrap.mjs +4 -1
- package/server/src/core/config.mjs +8 -4
- package/server/src/process/backend-drivers/registry.mjs +6 -1
- package/server/src/process/managed-backend.mjs +7 -7
- package/server/src/voice/realtime-provider.mjs +6 -11
- package/server/src/voice/tools/tool-call-handler.mjs +31 -24
- package/shared/backend-catalog.mjs +6 -1
- package/shared/runtime-environment.mjs +2 -1
- package/tui/package.json +1 -1
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
|

|
|
38
44
|
|
|
@@ -52,6 +58,7 @@ Agent 也应该始终在场。
|
|
|
52
58
|
|
|
53
59
|
| 后台 Agent | 接入方式 | 接入准备 | 推荐指数 |
|
|
54
60
|
| --- | --- | --- | --- |
|
|
61
|
+
| 无 | N/A | 仅前台模式,无需配置 | ★★★★★ |
|
|
55
62
|
| OpenCode | 原生 ACP | 支持自动安装和百炼配置 | ★★★★★ |
|
|
56
63
|
| OpenClaw | 内置 ACP 桥接 | 支持自动安装和百炼配置 | ★★★★★ |
|
|
57
64
|
| Qoder | 原生 ACP | 用户自行安装和配置 | ★★★★★ |
|
|
@@ -121,35 +128,26 @@ npm install -g git+https://github.com/QwenAudio/qwen-audio-agent.git
|
|
|
121
128
|
qwenaudio config
|
|
122
129
|
```
|
|
123
130
|
|
|
124
|
-
2. 打开命令显示的 `config.env`,填写 DashScope API Key
|
|
131
|
+
2. 打开命令显示的 `config.env`,填写 DashScope API Key。需要执行后台任务时,
|
|
132
|
+
再选择 OpenClaw 或其他后台 Agent:
|
|
125
133
|
|
|
126
134
|
```dotenv
|
|
127
135
|
DASHSCOPE_API_KEY=your-key
|
|
136
|
+
# 语音前台模型:qwen-audio-3.0-realtime-flash 或 qwen-audio-3.0-realtime-plus(默认)
|
|
137
|
+
QWEN_AUDIO_REALTIME_MODEL=qwen-audio-3.0-realtime-plus
|
|
138
|
+
# 后台Agent:可选,不设置或设置为 none 时,启动仅前台模式
|
|
128
139
|
AGENT_PROTOCOL=openclaw
|
|
140
|
+
# 后台模型:可为空,留空则沿用 Agent 自身的用户配置
|
|
129
141
|
QWEN_AUDIO_AGENT_BACKEND_MODEL=qwen3.7-max
|
|
130
142
|
```
|
|
131
143
|
|
|
132
|
-
3.
|
|
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:
|
|
144
|
+
3. 在一个终端中启动 Gateway:
|
|
147
145
|
|
|
148
146
|
```bash
|
|
149
147
|
qwenaudio
|
|
150
148
|
```
|
|
151
149
|
|
|
152
|
-
|
|
150
|
+
4. 另开一个终端,启动 TUI:
|
|
153
151
|
|
|
154
152
|
```bash
|
|
155
153
|
qwenaudio tui
|
|
@@ -216,10 +214,22 @@ qwenaudio gateway uninstall
|
|
|
216
214
|
|
|
217
215
|
## 选择后台 Agent
|
|
218
216
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
217
|
+
`AGENT_PROTOCOL` 是可选配置。留空时,Gateway 以仅前台模式运行,实时语音聊天
|
|
218
|
+
保持可用;如果请求需要后台执行,前台会明确说明当前没有可用的后台 Agent。
|
|
219
|
+
也可以在命令行中使用 `qwenaudio --backend none`,明确要求仅启动前台模式。
|
|
220
|
+
|
|
221
|
+
通过 `AGENT_PROTOCOL` 环境变量或 `--backend` 参数选择后台 Agent。选择后,
|
|
222
|
+
OpenCode 和 OpenClaw 支持自动下载安装;配置
|
|
223
|
+
`DASHSCOPE_API_KEY` 和 `QWEN_AUDIO_AGENT_BACKEND_MODEL` 后即可自动接入百炼
|
|
224
|
+
模型。未指定后台模型且用户已经安装并配置对应 Agent 时,则完整复用用户环境。
|
|
225
|
+
|
|
226
|
+
查看当前可用的后台 Agent:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
qwenaudio setup
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
使用 OpenClaw:
|
|
223
233
|
|
|
224
234
|
```dotenv
|
|
225
235
|
AGENT_PROTOCOL=openclaw
|
|
@@ -257,15 +267,6 @@ ACP_ARGS=["--acp"]
|
|
|
257
267
|
|
|
258
268
|
通用 ACP 入口不需要修改 Gateway 代码。命令、参数、显示名称和工作目录可分别通过 `ACP_COMMAND`、`ACP_ARGS`、`ACP_LABEL` 和 `ACP_WORKSPACE` 配置。
|
|
259
269
|
|
|
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
270
|
后台权限默认使用 `native`,由后台 Agent 在需要时询问。只有在可信项目中,并且
|
|
270
271
|
明确接受自动执行命令和修改文件时,才应启用:
|
|
271
272
|
|
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
|
-
##
|
|
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
|
-
##
|
|
50
|
+
## Reference Architecture
|
|
44
51
|
|
|
45
52
|

|
|
46
53
|
|
|
@@ -63,6 +70,7 @@ module walkthrough.
|
|
|
63
70
|
|
|
64
71
|
| Backend Agent | Integration | Setup | Rating |
|
|
65
72
|
| --- | --- | --- | --- |
|
|
73
|
+
| None | N/A | Frontend-only, no setup required | ★★★★★ |
|
|
66
74
|
| OpenCode | Native ACP | Automatic installation and Bailian setup supported | ★★★★★ |
|
|
67
75
|
| OpenClaw | Built-in ACP Bridge | Automatic installation and Bailian setup supported | ★★★★★ |
|
|
68
76
|
| Qoder | Native ACP | User installation and configuration required | ★★★★★ |
|
|
@@ -141,37 +149,26 @@ for details.
|
|
|
141
149
|
qwenaudio config
|
|
142
150
|
```
|
|
143
151
|
|
|
144
|
-
2. Open the displayed `config.env` file
|
|
145
|
-
OpenClaw:
|
|
152
|
+
2. Open the displayed `config.env` file and add your DashScope API Key. Select
|
|
153
|
+
OpenClaw or another backend Agent only when you need background tasks:
|
|
146
154
|
|
|
147
155
|
```dotenv
|
|
148
156
|
DASHSCOPE_API_KEY=your-key
|
|
149
|
-
|
|
150
|
-
|
|
157
|
+
# Voice model: qwen-audio-3.0-realtime-flash or qwen-audio-3.0-realtime-plus (default)
|
|
158
|
+
QWEN_AUDIO_REALTIME_MODEL=qwen-audio-3.0-realtime-plus
|
|
159
|
+
# Optional; uncomment when background tasks are needed
|
|
160
|
+
# AGENT_PROTOCOL=openclaw
|
|
161
|
+
# Backend model: can be left empty; the Agent uses its own user configuration
|
|
162
|
+
# QWEN_AUDIO_AGENT_BACKEND_MODEL=qwen3.7-max
|
|
151
163
|
```
|
|
152
164
|
|
|
153
|
-
3.
|
|
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:
|
|
165
|
+
3. Start the Gateway in one terminal:
|
|
169
166
|
|
|
170
167
|
```bash
|
|
171
168
|
qwenaudio
|
|
172
169
|
```
|
|
173
170
|
|
|
174
|
-
|
|
171
|
+
4. Open another terminal and start the TUI:
|
|
175
172
|
|
|
176
173
|
```bash
|
|
177
174
|
qwenaudio tui
|
|
@@ -243,12 +240,27 @@ qwenaudio gateway uninstall
|
|
|
243
240
|
|
|
244
241
|
## Choose a Backend Agent
|
|
245
242
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
243
|
+
`AGENT_PROTOCOL` is optional. When it is empty, the Gateway runs in
|
|
244
|
+
frontend-only mode and realtime voice chat remains available. If a request
|
|
245
|
+
requires background execution, the frontend clearly explains that no backend
|
|
246
|
+
Agent is available. You can also run `qwenaudio --backend none` to explicitly
|
|
247
|
+
start in frontend-only mode.
|
|
248
|
+
|
|
249
|
+
Select the backend Agent with `AGENT_PROTOCOL` or `--backend`. After selecting
|
|
250
|
+
one, OpenCode and OpenClaw can be downloaded automatically. Configure
|
|
251
|
+
`DASHSCOPE_API_KEY` and
|
|
252
|
+
`QWEN_AUDIO_AGENT_BACKEND_MODEL` to connect them to a Bailian model
|
|
253
|
+
automatically. When no backend model is specified and the Agent is already
|
|
254
|
+
installed and configured, qwen-audio-agent fully reuses the user's existing
|
|
255
|
+
environment.
|
|
256
|
+
|
|
257
|
+
Check which backends are available:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
qwenaudio setup
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Use OpenClaw:
|
|
252
264
|
|
|
253
265
|
```dotenv
|
|
254
266
|
AGENT_PROTOCOL=openclaw
|
|
@@ -287,19 +299,6 @@ ACP_ARGS=["--acp"]
|
|
|
287
299
|
|
|
288
300
|
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
301
|
|
|
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
302
|
Backend permissions default to `native`, so the backend Agent asks when
|
|
304
303
|
permission is required. Enable the following option only in trusted projects
|
|
305
304
|
and only if you explicitly accept automatic command execution and file
|
package/cli/package.json
CHANGED
package/cli/src/arguments.mjs
CHANGED
|
@@ -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:
|
|
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 =
|
|
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 (
|
|
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
|
|
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',
|
package/cli/src/launcher.mjs
CHANGED
|
@@ -32,10 +32,17 @@ async function runMinimal(options) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function applyGatewayOptions(env, options) {
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
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 =
|
|
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' ? '重启' : '启动'
|
package/cli/src/runtime.mjs
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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:
|
|
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 =
|
|
327
|
-
|
|
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 (
|
|
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}`
|
|
@@ -56,35 +56,17 @@ Session、子 Agent 或执行方式,不要虚构上下文或扩大用户要求
|
|
|
56
56
|
|
|
57
57
|
# Permission requests
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`always`,不得再次要求用户复述“始终允许”。
|
|
71
|
-
|
|
72
|
-
调用 `respond_agent_permission` 时,原样使用运行上下文中的 `authorization_id`,
|
|
73
|
-
并在 `evidence` 中逐字复制本轮用户原话里直接支撑该决定的最短片段。不要改写、
|
|
74
|
-
概括或补造 evidence。
|
|
75
|
-
|
|
76
|
-
权限决定是后台控制信号,不是新的对话内容。判断明确后直接调用
|
|
77
|
-
`respond_agent_permission`,调用前不要先口头确认;工具成功后按照工具结果只做一次
|
|
78
|
-
简短确认,例如“已允许,后台继续执行”或“已拒绝”,不要重述操作或再次询问。
|
|
79
|
-
|
|
80
|
-
只要运行上下文中仍有待确认的 `authorization_id`,就先处理用户对这项权限问题的
|
|
81
|
-
回答,不要把“可以”“怎么说”“继续吧”等短回答提交给 `spawn_thinking` 成为新任务。
|
|
82
|
-
如果误调用 `spawn_thinking` 后收到 `permission_decision_required`,立即回到权限
|
|
83
|
-
判断:能明确判断就调用 `respond_agent_permission`,不能判断就自然追问。
|
|
84
|
-
|
|
85
|
-
没有成功调用权限工具并获得成功结果前,绝对不要说“已授权、已经允许、后台会继续”
|
|
86
|
-
或作出其他成功承诺。不要根据原任务、与权限问题无关的“继续任务”、沉默或你自己的
|
|
87
|
-
判断推断授权。
|
|
59
|
+
存在待确认权限时,优先处理用户对该权限的回答,不要创建新任务。
|
|
60
|
+
|
|
61
|
+
- 用户明确同意时,调用 `respond_agent_permission`,选择 `always`。
|
|
62
|
+
- 用户明确拒绝时,选择 `reject`。
|
|
63
|
+
- 无法确定用户态度时,只用一句自然的话继续确认。
|
|
64
|
+
|
|
65
|
+
原样使用运行上下文中的 `authorization_id`。结合刚才提出的权限问题和用户本轮自然
|
|
66
|
+
表达判断意图,不要求固定口令,也不要求用户原话与某个短语逐字一致。
|
|
67
|
+
|
|
68
|
+
判断明确后直接调用工具,不要先说“好”“收到”“正在授权”或其他确认语。工具成功
|
|
69
|
+
后再用一句话说明已经允许或拒绝;如果工具失败,就简短说明没有成功。
|
|
88
70
|
|
|
89
71
|
# Completed work
|
|
90
72
|
|
package/docs/configuration.md
CHANGED
|
@@ -45,10 +45,15 @@ JSON 输出与 CLI 使用同一个共享检测模块,可供桌面版和其他
|
|
|
45
45
|
|
|
46
46
|
## 最小配置
|
|
47
47
|
|
|
48
|
-
|
|
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`
|
|
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
package/server/package.json
CHANGED
|
@@ -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
|
|
199
|
-
|
|
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
|
|
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: () =>
|
|
215
|
-
|
|
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 () => (
|
|
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 =
|
|
138
|
-
process.env.AGENT_PROTOCOL
|
|
139
|
-
)
|
|
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 (
|
|
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
|
|
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 {
|
|
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 =
|
|
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) {
|
|
@@ -133,7 +133,7 @@ const respondAgentPermissionTool = {
|
|
|
133
133
|
type: 'function',
|
|
134
134
|
function: {
|
|
135
135
|
name: RESPOND_AGENT_PERMISSION_TOOL_NAME,
|
|
136
|
-
description: '
|
|
136
|
+
description: '回复当前正在等待用户决定的后台权限请求。由你结合刚提出的具体权限问题和用户本轮自然表达,智能判断为本会话自动允许、拒绝或尚不明确;不要依赖固定关键词。用户回答“可以”“行”“好”“允许”“同意”“没问题”等自然肯定表达就是明确同意,应调用 always,不得要求复述固定口令。明确拒绝时调用 reject,不明确时不要调用并继续询问。',
|
|
137
137
|
parameters: {
|
|
138
138
|
type: 'object',
|
|
139
139
|
properties: {
|
|
@@ -146,12 +146,8 @@ const respondAgentPermissionTool = {
|
|
|
146
146
|
enum: ['always', 'reject'],
|
|
147
147
|
description: 'always 表示允许当前操作,并由 Gateway 在本次前台会话中自动允许后续权限请求;reject 表示拒绝当前操作,后续请求仍继续询问。',
|
|
148
148
|
},
|
|
149
|
-
evidence: {
|
|
150
|
-
type: 'string',
|
|
151
|
-
description: '从本轮用户原话中逐字复制、直接支撑该决定的最短片段;不得改写、概括或补造。',
|
|
152
|
-
},
|
|
153
149
|
},
|
|
154
|
-
required: ['authorization_id', 'decision'
|
|
150
|
+
required: ['authorization_id', 'decision'],
|
|
155
151
|
additionalProperties: false,
|
|
156
152
|
},
|
|
157
153
|
},
|
|
@@ -180,11 +176,10 @@ function speakResponseInstructions(content) {
|
|
|
180
176
|
}
|
|
181
177
|
|
|
182
178
|
const permissionResponseInstructions = [
|
|
183
|
-
'这是后台 Agent
|
|
184
|
-
'
|
|
185
|
-
'
|
|
186
|
-
'
|
|
187
|
-
'不要朗读 authorization_id、Session ID 或协议字段。',
|
|
179
|
+
'这是后台 Agent 的权限请求。',
|
|
180
|
+
'自然、简短地说明操作,并询问用户是否同意授权。',
|
|
181
|
+
'不要规定具体回答方式,也不要提供或要求复述固定口令。',
|
|
182
|
+
'不要调用工具或朗读内部字段,等待用户回答。',
|
|
188
183
|
].join(' ')
|
|
189
184
|
|
|
190
185
|
export function buildFrontendInstructions(agentContext = {}) {
|
|
@@ -10,10 +10,6 @@ import { currentTimeSnapshot } from '../../conversation/frontend-agent-context.m
|
|
|
10
10
|
|
|
11
11
|
const SENSITIVE_MEMORY = /(?:pass(?:word)?|secret|api[_ -]?key|access[_ -]?token|credential|验证码|密码|密钥|令牌|\bsk-[a-z0-9_-]+)/i
|
|
12
12
|
|
|
13
|
-
function normalizedEvidence(value) {
|
|
14
|
-
return String(value || '').replace(/\s+/g, ' ').trim().toLocaleLowerCase()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
13
|
function failure(errorCode, userMessage, {
|
|
18
14
|
retryable = false,
|
|
19
15
|
status = 'failed',
|
|
@@ -271,7 +267,7 @@ export class ToolCallHandler {
|
|
|
271
267
|
instructions: [
|
|
272
268
|
'当前有一项权限请求正在等待决定,本轮不能调用 spawn_thinking。',
|
|
273
269
|
'重新结合刚才提出的具体权限问题和本轮用户原话判断。',
|
|
274
|
-
'若用户已自然表达同意或拒绝,立即调用 respond_agent_permission
|
|
270
|
+
'若用户已自然表达同意或拒绝,立即调用 respond_agent_permission;按语义判断,不要要求固定口令。',
|
|
275
271
|
'若用户没有作出决定,只用一句自然的话继续确认。',
|
|
276
272
|
'绝对不要代替用户同意,也不要声称权限已经生效。',
|
|
277
273
|
].join(' '),
|
|
@@ -309,20 +305,44 @@ export class ToolCallHandler {
|
|
|
309
305
|
}
|
|
310
306
|
|
|
311
307
|
let coordinatorReady = false
|
|
308
|
+
let coordinatorConfigured = true
|
|
312
309
|
try {
|
|
313
|
-
|
|
310
|
+
const availability = await this.coordinatorAvailable()
|
|
311
|
+
if (availability && typeof availability === 'object') {
|
|
312
|
+
coordinatorConfigured = availability.enabled !== false
|
|
313
|
+
coordinatorReady = (
|
|
314
|
+
coordinatorConfigured && availability.ok === true
|
|
315
|
+
)
|
|
316
|
+
} else {
|
|
317
|
+
coordinatorReady = availability === true
|
|
318
|
+
}
|
|
314
319
|
} catch {
|
|
315
320
|
coordinatorReady = false
|
|
316
321
|
}
|
|
317
322
|
if (!coordinatorReady) {
|
|
323
|
+
const userMessage = coordinatorConfigured
|
|
324
|
+
? '后台 Agent 当前未连接。你仍然可以继续普通聊天,后台恢复后再执行这项工作。'
|
|
325
|
+
: '当前未配置后台 Agent,无法执行需要后台处理的任务。你仍然可以继续普通聊天。'
|
|
318
326
|
await this.sendOutput(
|
|
319
327
|
callId,
|
|
320
328
|
failure(
|
|
321
329
|
'backend_unavailable',
|
|
322
|
-
|
|
323
|
-
{ retryable:
|
|
330
|
+
userMessage,
|
|
331
|
+
{ retryable: coordinatorConfigured },
|
|
324
332
|
),
|
|
325
333
|
turnId,
|
|
334
|
+
null,
|
|
335
|
+
{
|
|
336
|
+
response: {
|
|
337
|
+
instructions: [
|
|
338
|
+
coordinatorConfigured
|
|
339
|
+
? '直接向用户说明后台 Agent 当前未连接,暂时无法执行这项后台任务。'
|
|
340
|
+
: '直接向用户说明当前未配置后台 Agent,无法执行这项后台任务。',
|
|
341
|
+
'不要再次调用后台工具,也不要声称任务已经创建或正在执行。',
|
|
342
|
+
'可以继续完成不需要后台 Agent 的聊天和回答。',
|
|
343
|
+
].join('\n'),
|
|
344
|
+
},
|
|
345
|
+
},
|
|
326
346
|
)
|
|
327
347
|
return
|
|
328
348
|
}
|
|
@@ -420,12 +440,11 @@ export class ToolCallHandler {
|
|
|
420
440
|
async respondAgentPermission(callId, turnId, args) {
|
|
421
441
|
const authorizationId = String(args.authorization_id || '').trim()
|
|
422
442
|
const decision = String(args.decision || '').trim()
|
|
423
|
-
const evidence = normalizedEvidence(args.evidence)
|
|
424
443
|
const transcript = String(await this.transcripts.transcript(turnId)).trim()
|
|
425
444
|
if (
|
|
426
445
|
!authorizationId
|
|
427
446
|
|| !['always', 'reject'].includes(decision)
|
|
428
|
-
|| !
|
|
447
|
+
|| !transcript
|
|
429
448
|
) {
|
|
430
449
|
await this.sendOutput(
|
|
431
450
|
callId,
|
|
@@ -434,18 +453,6 @@ export class ToolCallHandler {
|
|
|
434
453
|
)
|
|
435
454
|
return
|
|
436
455
|
}
|
|
437
|
-
if (!normalizedEvidence(transcript).includes(evidence)) {
|
|
438
|
-
await this.sendOutput(
|
|
439
|
-
callId,
|
|
440
|
-
failure(
|
|
441
|
-
'permission_evidence_mismatch',
|
|
442
|
-
'权限决定没有对应到本轮用户原话,不能提交。',
|
|
443
|
-
{ retryable: false },
|
|
444
|
-
),
|
|
445
|
-
turnId,
|
|
446
|
-
)
|
|
447
|
-
return
|
|
448
|
-
}
|
|
449
456
|
const pendingTask = this.taskManager.list({
|
|
450
457
|
ownerId: this.ownerId,
|
|
451
458
|
sessionId: this.sessionId,
|
|
@@ -495,12 +502,12 @@ export class ToolCallHandler {
|
|
|
495
502
|
? [
|
|
496
503
|
'权限已经成功生效。',
|
|
497
504
|
'只用一句简短自然口语确认“已允许,后台继续执行”。',
|
|
498
|
-
'
|
|
505
|
+
'不要重述操作,不要再次询问或调用工具。',
|
|
499
506
|
].join(' ')
|
|
500
507
|
: [
|
|
501
508
|
'权限已经成功拒绝。',
|
|
502
509
|
'只用一句简短自然口语确认“已拒绝,后台不会执行这项操作”。',
|
|
503
|
-
'
|
|
510
|
+
'不要重述操作,不要再次询问或调用工具。',
|
|
504
511
|
].join(' '),
|
|
505
512
|
},
|
|
506
513
|
})
|
|
@@ -46,9 +46,14 @@ const definitions = new Map([
|
|
|
46
46
|
])
|
|
47
47
|
|
|
48
48
|
export function backendDefinition(protocol) {
|
|
49
|
-
return definitions.get(
|
|
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
|
-
'#
|
|
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',
|