$npx -y skills add agentscope-ai/QwenPaw --skill cron-zh仅在需要未来定时执行或周期执行任务时,使用本 skill。使用 qwenpaw cron list/create/get/state/update/pause/resume/delete/run 管理任务,并始终显式传入 --agent-id。
| 1 | # 定时任务管理 |
| 2 | |
| 3 | ## 什么时候用 |
| 4 | |
| 5 | 只有在需要**未来某个时间自动执行**,或**按周期重复执行**时,使用本 skill。 |
| 6 | |
| 7 | ### 应该使用 |
| 8 | - 用户要求"每天 / 每周 / 每小时"执行某事 |
| 9 | - 用户要求"明天 9 点 / 下周一 / 某个时间"自动提醒或执行 |
| 10 | - 需要长期周期性通知、检查、汇报 |
| 11 | |
| 12 | ### 不应使用 |
| 13 | - 只是要**现在立即执行一次** |
| 14 | - 只是当前会话中的正常回复 |
| 15 | - 用户没有明确执行时间或周期 |
| 16 | - 目标 channel / user / session 还不明确 |
| 17 | |
| 18 | ## 决策规则 |
| 19 | |
| 20 | 1. **只有在未来定时执行或周期执行时才使用 cron** |
| 21 | 2. **如果只是立即做一次,通常不要创建 cron** |
| 22 | 3. **创建前必须确认执行时间/周期、目标 channel、target-user、target-session** |
| 23 | 4. **所有 cron 命令都必须显式传 `--agent-id`** |
| 24 | 5. **不要依赖默认 agent,否则任务可能落到 default workspace** |
| 25 | 6. **如果 agent 任务只需后台执行、不向渠道输出,添加 `--silent`;执行、会话历史、追踪和可选收件箱记录仍会继续** |
| 26 | |
| 27 | --- |
| 28 | |
| 29 | ## 硬规则 |
| 30 | |
| 31 | ### 必须显式指定 `--agent-id` |
| 32 | |
| 33 | 所有 `qwenpaw cron` 命令都**必须**传: |
| 34 | |
| 35 | ```bash |
| 36 | --agent-id <your_agent_id> |
| 37 | ``` |
| 38 | |
| 39 | 你的 agent_id 在系统提示中的 Agent Identity 部分(Your agent id is ...)。 |
| 40 | 不得省略,否则任务可能错误创建到 default agent 的 workspace。 |
| 41 | |
| 42 | --- |
| 43 | |
| 44 | ## 常用命令 |
| 45 | |
| 46 | ```bash |
| 47 | # 列出任务 |
| 48 | qwenpaw cron list --agent-id <agent_id> |
| 49 | |
| 50 | # 查看任务详情 |
| 51 | qwenpaw cron get <job_id> --agent-id <agent_id> |
| 52 | |
| 53 | # 查看任务状态 |
| 54 | qwenpaw cron state <job_id> --agent-id <agent_id> |
| 55 | |
| 56 | # 创建任务 |
| 57 | qwenpaw cron create --agent-id <agent_id> ... |
| 58 | |
| 59 | # 删除任务 |
| 60 | qwenpaw cron delete <job_id> --agent-id <agent_id> |
| 61 | |
| 62 | # 暂停 / 恢复任务 |
| 63 | qwenpaw cron pause <job_id> --agent-id <agent_id> |
| 64 | qwenpaw cron resume <job_id> --agent-id <agent_id> |
| 65 | |
| 66 | # 立即执行一次已有任务 |
| 67 | qwenpaw cron run <job_id> --agent-id <agent_id> |
| 68 | |
| 69 | # 更新已有任务 |
| 70 | qwenpaw cron update <job_id> --agent-id <agent_id> ... |
| 71 | ``` |
| 72 | |
| 73 | --- |
| 74 | |
| 75 | ## 创建任务 |
| 76 | |
| 77 | 支持两种类型: |
| 78 | - **text**:定时发送固定消息 |
| 79 | - **agent**:定时向 agent 提问,并把回复发送到目标 channel |
| 80 | |
| 81 | 支持两种调度形态: |
| 82 | - **cron**(`--schedule-type cron`):经典 cron 周期(如每天 9 点、每 2 小时),与循环任务相对应 |
| 83 | - **scheduled**(`--schedule-type scheduled`):日程任务(从 `--run-at` 开始,可一次性或按天重复) |
| 84 | |
| 85 | ### 调度选择规则(必须遵守) |
| 86 | - 用户表达“每小时/每天/每周”且不强调具体起始日时,优先用 `cron` |
| 87 | - 用户表达“明天/下周一/从某天开始/未来两周/有明确截止时间”时,优先用 `scheduled` |
| 88 | - `scheduled` 不重复时(即一次性任务):只传 `--run-at`,不要传 `--repeat-*` |
| 89 | - `scheduled` 重复时:传 `--repeat-every-days`,并根据结束条件传: |
| 90 | - 限定次数:`--repeat-end-type count --repeat-count N` |
| 91 | - 限定结束时间:`--repeat-end-type until --repeat-until <ISO8601>` |
| 92 | - 不设结束:`--repeat-end-type never` |
| 93 | |
| 94 | ### 超时设置 |
| 95 | |
| 96 | 默认超时 120 秒(2 分钟)。对于较长的 agent 任务,应显式设置更大的超时时间,避免任务被提前取消: |
| 97 | |
| 98 | ```bash |
| 99 | --timeout 600 # 10 分钟 |
| 100 | --timeout 3600 # 1 小时 |
| 101 | ``` |
| 102 | |
| 103 | **核心规则**: |
| 104 | 1. 如果 agent 任务涉及联网搜索、代码执行或多步工具调用,建议设置 `--timeout 600` 或更高 |
| 105 | 2. **timeout 必须小于调度周期**,避免前一次执行未完成时下一次已触发,导致任务重叠运行。例如: |
| 106 | - 每 15 分钟执行:`--timeout` 不应超过 900 秒 |
| 107 | - 每 10 分钟执行:`--timeout` 建议不超过间隔的 80%(即 480 秒) |
| 108 | - 每天执行:`--timeout` 可以设置较大,不需要特别限制 |
| 109 | 3. 对于高频任务(间隔 ≤ 10 分钟),遵循 **timeout ≤ 调度间隔的 80%**;低频任务(每小时及以上)按实际需要设置即可 |
| 110 | |
| 111 | ### 创建前最少要确认 |
| 112 | - `--type` |
| 113 | - `--name` |
| 114 | - `--schedule-type` |
| 115 | - `--cron`(当 `--schedule-type cron`) |
| 116 | - `--run-at`(当 `--schedule-type scheduled`) |
| 117 | - `--channel` |
| 118 | - `--target-user` |
| 119 | - `--target-session` |
| 120 | - `--text` |
| 121 | - `--agent-id` |
| 122 | - `--timeout`(对于 agent 类型任务,根据预期执行时间设置合适的超时) |
| 123 | |
| 124 | 如果缺少这些信息,应先向用户确认,再创建任务。 |
| 125 | |
| 126 | ### 创建示例 |
| 127 | |
| 128 | ```bash |
| 129 | # 循环任务(对应 --schedule-type cron) |
| 130 | qwenpaw cron create \ |
| 131 | --agent-id <agent_id> \ |
| 132 | --type text \ |
| 133 | --schedule-type cron \ |
| 134 | --name "每日早安" \ |
| 135 | --cron "0 9 * * *" \ |
| 136 | --channel imessage \ |
| 137 | --target-user "CHANGEME" \ |
| 138 | --target-session "CHANGEME" \ |
| 139 | --text "早上好!" |
| 140 | ``` |
| 141 | |
| 142 | ```bash |
| 143 | # 循环任务(对应 --schedule-type cron) |
| 144 | qwenpaw cron create \ |
| 145 | --agent-id <agent_id> \ |
| 146 | --type agent \ |
| 147 | --schedule-type cron \ |
| 148 | --name "检查待办" \ |
| 149 | --cron "0 */2 * * *" \ |
| 150 | --channel dingtalk \ |
| 151 | --target-user "CHANGEME" \ |
| 152 | --target-session "CHANGEME" \ |
| 153 | --text "我有什么待办事项?" \ |
| 154 | --timeout 600 |
| 155 | ``` |
| 156 | |
| 157 | 如果是后台 agent 任务,可在上面的命令中添加 `--silent`。`text` 任务不能使用该参数。 |
| 158 | |
| 159 | ```bash |
| 160 | # 日程一次性:明天 9 点提醒(不重复) |
| 161 | qwenpaw cron create \ |
| 162 | --agent-id <agent_id> \ |
| 163 | --type text \ |
| 164 | --schedule-type scheduled \ |
| 165 | --name "明早提醒" \ |
| 166 | --run-at "2026-05-13T09:00:00+08:00" \ |
| 167 | --channel dingtalk \ |
| 168 | --target-user "CHANGEME" \ |
| 169 | --target-session "CHANGEME" \ |
| 170 | --text "9 点开组会" \ |
| 171 | --save-result-to-inbox |
| 172 | ``` |
| 173 | |
| 174 | ```bash |
| 175 | # 日程重复:未来两周每天 9 点(共 14 次) |
| 176 | qwenpaw cron create \ |
| 177 | --agent-id <agent_id> \ |
| 178 | --type text \ |
| 179 | --schedule-type scheduled \ |
| 180 | --name "未来两周组会提醒" \ |
| 181 | --run-at "2026-05-13T09:00:00+08:00" \ |
| 182 | --repeat-every-days 1 \ |
| 183 | --repeat-end-type count \ |
| 184 | --repeat-count 14 \ |
| 185 | --channel dingtalk \ |
| 186 | --target-user "CHANGEME" \ |
| 187 | --target-session "CHANGEME" \ |
| 188 | --text "9 点开组会" \ |
| 189 | --save-result-to-inbox |
| 190 | ``` |
| 191 | |
| 192 | ### 从 JSON 创建 |
| 193 | |
| 194 | ```bash |
| 195 | qwenpaw cron create --agent-id <agent_id> -f job_spec.json |
| 196 | ``` |
| 197 | |
| 198 | --- |
| 199 | |
| 200 | ## 最小工作流 |
| 201 | |
| 202 | ``` |
| 203 | 1. 判断是否真的是"未来定时"或"周期执行" |
| 204 | 2. 确认执行时间/周期 |
| 205 | 3. 确认 channel、target-user、target-session |
| 206 | 4. 显式带上 --agent-id |
| 207 | 5. qwenpaw cron create 创建任务 |
| 208 | 6. 后续用 list / state / pause / resume / delete 管理 |
| 209 | ``` |
| 210 | |
| 211 | --- |
| 212 | |
| 213 | ## Cron 表达式示例 |
| 214 | |
| 215 | ``` |
| 216 | 0 9 * * * 每天 9:00 |
| 217 | 0 */2 * * * 每 2 小时 |
| 218 | 30 8 * * 1-5 工作日 8:30 |
| 219 | 0 0 * * 0 每周日零点 |
| 220 | */15 * * * * 每 15 分钟 |
| 221 | ``` |
| 222 | |
| 223 | --- |
| 224 | |
| 225 | ## 常见错误 |
| 226 | |
| 227 | ### 错误 1:把一次性立即执行当成 cron |
| 228 | |
| 229 | 如果只是现在执行一次,通常不要创建 cron。 |
| 230 | |
| 231 | ### 错误 2:没传 --agent-id |
| 232 | |
| 233 | 这会导致任务落到错误的 agent / workspace。所有 cron 命令都必须显式传 `--agent-id`。 |
| 234 | |
| 235 | ### 错误 3:信息没补全就创建 |
| 236 | |
| 237 | 如果用户没说明时间、周期、目标 channel 或目标 session,应先追问。 |
| 238 | |
| 239 | ### 错误 4:操作已有任务前不先查 |
| 240 | |
| 241 | 暂停、恢复、删除前,先用: |
| 242 | |
| 243 | ```bash |
| 244 | qwenpaw cron list --agent-id <agent_id> |
| 245 | ``` |
| 246 | |
| 247 | 找到正确的 `job_id`。 |
| 248 | |
| 249 | --- |
| 250 | |
| 251 | ## 使用建议 |
| 252 | |
| 253 | - 缺少参数时,先问用户再创建 |
| 254 | - 修 |