$npx -y skills add agentscope-ai/QwenPaw --skill multi_agent_collaboration-zh当需要其他 agent 的专长、上下文或协作支持,或用户明确要求调用其他 agent 时,使用本 skill。先查询可用 agents,再用 qwenpaw agents chat 进行双向沟通。
| 1 | # 多智能体协作 |
| 2 | |
| 3 | ## 什么时候用 |
| 4 | |
| 5 | 当你**需要其他 agent 的专业能力、上下文、workspace 内容或协作支持**时,使用本 skill。 |
| 6 | 如果**用户明确要求某个 agent 参与/协助/回答**,也应使用本 skill。 |
| 7 | |
| 8 | ### 应该使用 |
| 9 | - 当前任务明显更适合某个专用 agent |
| 10 | - 需要另一个 agent 的 workspace / 文件 / 上下文 |
| 11 | - 需要第二意见或专业复核 |
| 12 | - 用户明确要求某个 agent 参与或调用其他 agent |
| 13 | |
| 14 | ### 不应使用 |
| 15 | - 你自己可以直接完成,且用户没有明确要求调用其他 agent |
| 16 | - 只是普通问答,不需要专门 agent |
| 17 | - 信息不足,应先追问用户 |
| 18 | - 刚收到 Agent B 的消息,**不要再调用 Agent B**,避免循环 |
| 19 | |
| 20 | ## 决策规则 |
| 21 | |
| 22 | 1. **如果用户明确要求调用其他 agent,优先按要求执行** |
| 23 | 2. **否则,能自己做,就不要调用** |
| 24 | 3. **调用前先查 agent,不要猜 ID** |
| 25 | 4. **需要上下文续聊时,必须传 `--session-id`** |
| 26 | 5. **不要回调消息来源 agent** |
| 27 | |
| 28 | --- |
| 29 | |
| 30 | ## 最常用命令 |
| 31 | |
| 32 | ### 1) 先查询可用 agents |
| 33 | |
| 34 | ```bash |
| 35 | qwenpaw agents list |
| 36 | ``` |
| 37 | |
| 38 | ### 2) 发起新对话(实时模式) |
| 39 | |
| 40 | ```bash |
| 41 | qwenpaw agents chat \ |
| 42 | --from-agent <your_agent> \ |
| 43 | --to-agent <target_agent> \ |
| 44 | --text "[Agent <your_agent> requesting] ..." |
| 45 | ``` |
| 46 | |
| 47 | ### 3) 发起复杂任务(后台模式) |
| 48 | |
| 49 | **复杂任务**包括:数据分析、报告生成、批量处理、外部API调用等。 |
| 50 | |
| 51 | ```bash |
| 52 | qwenpaw agents chat --background \ |
| 53 | --from-agent <your_agent> \ |
| 54 | --to-agent <target_agent> \ |
| 55 | --text "[Agent <your_agent> requesting] ..." |
| 56 | ``` |
| 57 | |
| 58 | **输出**: |
| 59 | ``` |
| 60 | [TASK_ID: xxx-xxx-xxx] |
| 61 | [SESSION: ...] |
| 62 | ``` |
| 63 | |
| 64 | ### 4) 查询后台任务状态 |
| 65 | |
| 66 | ```bash |
| 67 | qwenpaw agents chat --background --task-id <task_id> |
| 68 | ``` |
| 69 | |
| 70 | **重要**:不要频繁查询!提交任务后: |
| 71 | 1. **不要硬等** - 继续处理其他任务或工作 |
| 72 | 2. **等待合理时间后再查** - 根据任务复杂度选择: |
| 73 | - 简单分析:10-20 秒后查询 |
| 74 | - 复杂分析:30-60 秒后查询 |
| 75 | - 批量处理:1-3 分钟后查询 |
| 76 | 3. **在等待期间** - 可以回复用户、处理其他请求、或执行其他任务 |
| 77 | |
| 78 | ### 5) 继续已有对话 |
| 79 | |
| 80 | ```bash |
| 81 | qwenpaw agents chat \ |
| 82 | --from-agent <your_agent> \ |
| 83 | --to-agent <target_agent> \ |
| 84 | --session-id "<session_id>" \ |
| 85 | --text "[Agent <your_agent> requesting] ..." |
| 86 | ``` |
| 87 | |
| 88 | **重点**: |
| 89 | - 不传 `--session-id` = 新对话 |
| 90 | - 传 `--session-id` = 续聊(保留上下文) |
| 91 | - 复杂任务用 `--background`,提交后记录 task_id |
| 92 | |
| 93 | --- |
| 94 | |
| 95 | ## 任务模式选择 |
| 96 | |
| 97 | ### 实时模式 vs 后台模式 |
| 98 | |
| 99 | | 任务类型 | 使用模式 | 命令 | |
| 100 | |---------|---------|------| |
| 101 | | 简单快速查询 | 实时模式 | `qwenpaw agents chat` | |
| 102 | | 复杂任务(数据分析、批量处理等) | 后台模式 | `qwenpaw agents chat --background` | |
| 103 | |
| 104 | **复杂任务示例**: |
| 105 | - 分析大量数据或日志文件 |
| 106 | - 生成详细报告 |
| 107 | - 批量处理文件(10+ 个文件) |
| 108 | - 调用慢速外部 API |
| 109 | - 需要并行执行的独立任务 |
| 110 | |
| 111 | **判断标准**:如果不确定任务会花多长时间,或者任务很复杂,优先使用后台模式。 |
| 112 | |
| 113 | --- |
| 114 | |
| 115 | ## 最小工作流 |
| 116 | |
| 117 | ### 实时模式工作流 |
| 118 | |
| 119 | ``` |
| 120 | 1. 判断是否需要其他 agent,或用户是否明确要求调用 |
| 121 | 2. qwenpaw agents list |
| 122 | 3. qwenpaw agents chat 发起对话 |
| 123 | 4. 从输出中记录 [SESSION: ...] |
| 124 | 5. 后续需要上下文时带上 --session-id |
| 125 | ``` |
| 126 | |
| 127 | ### 后台模式工作流 |
| 128 | |
| 129 | ``` |
| 130 | 1. 判断任务是否复杂(数据分析、报告生成等) |
| 131 | 2. qwenpaw agents list |
| 132 | 3. qwenpaw agents chat --background 提交任务 |
| 133 | 4. 从输出中记录 [TASK_ID: ...] |
| 134 | 5. 继续处理其他工作 |
| 135 | 6. 等待合理时间(30-60秒)后查询状态 |
| 136 | 7. 使用 --background --task-id 查询结果 |
| 137 | ``` |
| 138 | |
| 139 | --- |
| 140 | |
| 141 | ## 关键规则 |
| 142 | |
| 143 | ### 必填参数 |
| 144 | |
| 145 | `qwenpaw agents chat` 必须同时提供: |
| 146 | - `--from-agent` |
| 147 | - `--to-agent` |
| 148 | - `--text` |
| 149 | |
| 150 | ### 身份前缀 |
| 151 | |
| 152 | 消息建议以以下前缀开头: |
| 153 | |
| 154 | ```text |
| 155 | [Agent my_agent requesting] ... |
| 156 | ``` |
| 157 | |
| 158 | ### 会话复用 |
| 159 | |
| 160 | 首次调用会返回: |
| 161 | |
| 162 | ```text |
| 163 | [SESSION: your_agent:to:target_agent:...] |
| 164 | ``` |
| 165 | |
| 166 | 后续续聊必须复制这个 session_id 传入 `--session-id`。 |
| 167 | |
| 168 | --- |
| 169 | |
| 170 | ## 简短示例 |
| 171 | |
| 172 | ### 用户明确要求调用其他 agent |
| 173 | |
| 174 | ```bash |
| 175 | qwenpaw agents list |
| 176 | |
| 177 | qwenpaw agents chat \ |
| 178 | --from-agent scheduler_bot \ |
| 179 | --to-agent finance_bot \ |
| 180 | --text "[Agent scheduler_bot requesting] User explicitly asked to consult finance_bot. 请回答当前待处理的财务任务。" |
| 181 | ``` |
| 182 | |
| 183 | ### 新对话 |
| 184 | |
| 185 | ```bash |
| 186 | qwenpaw agents chat \ |
| 187 | --from-agent scheduler_bot \ |
| 188 | --to-agent finance_bot \ |
| 189 | --text "[Agent scheduler_bot requesting] 今天有哪些待处理的财务任务?" |
| 190 | ``` |
| 191 | |
| 192 | ### 续聊 |
| 193 | |
| 194 | ```bash |
| 195 | qwenpaw agents chat \ |
| 196 | --from-agent scheduler_bot \ |
| 197 | --to-agent finance_bot \ |
| 198 | --session-id "scheduler_bot:to:finance_bot:1710912345:a1b2c3d4" \ |
| 199 | --text "[Agent scheduler_bot requesting] 展开第2项" |
| 200 | ``` |
| 201 | |
| 202 | --- |
| 203 | |
| 204 | ## 常见错误 |
| 205 | |
| 206 | ### 错误 1:没先查 agent |
| 207 | |
| 208 | 不要猜 agent ID,先执行: |
| 209 | |
| 210 | ```bash |
| 211 | qwenpaw agents list |
| 212 | ``` |
| 213 | |
| 214 | ### 错误 2:想续聊但没传 session-id |
| 215 | |
| 216 | 这会创建新对话,丢失上下文。 |
| 217 | |
| 218 | ### 错误 3:回调来源 agent |
| 219 | |
| 220 | 如果你刚收到 Agent B 的消息,不要再调用 Agent B。 |
| 221 | |
| 222 | --- |
| 223 | |
| 224 | ## 可选命令 |
| 225 | |
| 226 | ### 查看已有会话 |
| 227 | |
| 228 | ```bash |
| 229 | qwenpaw chats list --agent-id <your_agent> |
| 230 | ``` |
| 231 | |
| 232 | ### 流式输出 |
| 233 | |
| 234 | ```bash |
| 235 | qwenpaw agents chat \ |
| 236 | --from-agent <your_agent> \ |
| 237 | --to-agent <target_agent> \ |
| 238 | --mode stream \ |
| 239 | --text "[Agent <your_agent> requesting] ..." |
| 240 | ``` |
| 241 | |
| 242 | ### JSON 输出 |
| 243 | |
| 244 | ```bash |
| 245 | qwenpaw agents chat \ |
| 246 | --from-agent <your_agent> \ |
| 247 | --to-agent <target_agent> \ |
| 248 | --json-output \ |
| 249 | --text "[Agent <your_agent> requesting] ..." |
| 250 | ``` |
| 251 | |
| 252 | --- |
| 253 | |
| 254 | ## 完整参数说明 |
| 255 | |
| 256 | ### qwenpaw agents list |
| 257 | |
| 258 | **参数**: |
| 259 | - `--base-url`(可选):覆盖API地址 |
| 260 | |
| 261 | **无必填参数**,直接运行即可。 |
| 262 | |
| 263 | ### qwenpaw agents chat |
| 264 | |
| 265 | **必填参数**(实时模式): |
| 266 | - `--from-agent`:发起方agent ID |
| 267 | - `--to-agent`:目标agent ID |
| 268 | - `--text`:消息内容 |
| 269 | |
| 270 | **后台任务参数**(新增): |
| 271 | - `--background`:后台任务模式 |
| 272 | - `--task-id`:查询任务状态(与 --background 一起使用) |
| 273 | |
| 274 | **可选参数**: |
| 275 | - `--session-id`:复用会话上下文(从之前的输出中复制) |
| 276 | - `--new-session`:强制创建新会话(即使传了session-id) |
| 277 | - `--mode`:stream(流式)或 final(完整,默认) |
| 278 | - `--timeout`:超时时间(秒,默认300) |
| 279 | - `--json-output`:输出完整JSON而非纯文本 |
| 280 | - `--base-url`:覆盖API地址 |
| 281 | |
| 282 | --- |
| 283 | |
| 284 | ## 后台任务模式详解(Background Task) |
| 285 | |
| 286 | ### 什么时候用后台模式? |
| 287 | |
| 288 | 当任务是**复杂任务**时,使用 `--background` 提交到后台: |
| 289 | |
| 290 | ✅ **应该使用后台模式**: |
| 291 | - 数据分析(分析日志、统计数据) |
| 292 | - 报告生成(生成长篇报告、文档) |
| 293 | - 批量处理(处理多个文件) |
| 294 | - 外部 API 调用(调用慢速服务) |
| 295 | - 不确定任务时长的复杂任务 |
| 296 | |
| 297 | ❌ **不需要后台模式**: |
| 298 | - 简单快速查询 |
| 299 | - 明确知道很快完成的任务 |
| 300 | |
| 301 | ### 后台任务示例 |
| 302 | |
| 303 | #### 提交复杂任务 |
| 304 | |
| 305 | ```bash |
| 306 | qwenpaw agents chat --background \ |
| 307 | --from-agent scheduler \ |
| 308 | --to-agent data_analyst \ |
| 309 | --text "[Agent scheduler requesting] 分析 /data/logs/2026-03-26.log 中的用户行为,生成详细报告" |
| 310 | ``` |
| 311 | |
| 312 | **输出**: |
| 313 | ``` |
| 314 | [TASK_ID: 20802ea3-832d-4fb4-86f0-666ad79fcc80] |
| 315 | [S |