qwen_agent/skills/schedule-job/SKILL.md
朱潮 3b9c7165a9 feat: 添加定时任务调度系统(schedule-job)
- 新增 schedule-job skill,支持 cron 周期任务和一次性定时任务
- 新增 schedule_manager.py CLI 工具(list/add/edit/delete/toggle/logs)
- 新增 ScheduleExecutor 全局异步调度器,每 60s 扫描到期任务并调用 agent 执行
- 任务数据存储在 projects/robot/{bot_id}/users/{user_id}/tasks.yaml
- 执行结果写入 task_logs/execution.log
- 集成到 FastAPI lifespan 生命周期管理
- 添加 croniter、pyyaml 依赖

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 23:17:47 +08:00

145 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: schedule-job
description: 定时任务管理 - 为用户创建、管理和查看定时任务(支持 cron 周期任务和一次性任务)
---
# Schedule Job - 定时任务管理
管理用户的定时任务,支持 cron 周期性任务和一次性定时任务。任务到期后系统自动执行 AI 对话。
## Quick Start
用户请求创建定时任务时:
1. 确认任务类型(周期 cron / 一次性 once
2. 确定时间cron 表达式或具体时间)和时区
3. 确定发送给 AI 的消息内容
4. 调用 schedule_manager.py 创建任务
## Instructions
### 工具路径
所有操作通过 shell 命令执行:
```bash
python {skill_dir}/scripts/schedule_manager.py <command> [options]
```
### 可用命令
#### 列出任务
```bash
python {skill_dir}/scripts/schedule_manager.py list
python {skill_dir}/scripts/schedule_manager.py list --format brief
```
#### 添加 Cron 周期任务
```bash
python {skill_dir}/scripts/schedule_manager.py add \
--name "任务名称" \
--type cron \
--schedule "0 9 * * *" \
--timezone "Asia/Tokyo" \
--message "请帮我总结今天的科技新闻"
```
#### 添加一次性任务
```bash
python {skill_dir}/scripts/schedule_manager.py add \
--name "会议提醒" \
--type once \
--scheduled-at "2026-04-01T10:00:00+09:00" \
--message "提醒我10点有会议"
```
#### 编辑任务
```bash
python {skill_dir}/scripts/schedule_manager.py edit <task_id> \
--schedule "0 10 * * 1-5" \
--message "新的消息内容"
```
#### 删除任务
```bash
python {skill_dir}/scripts/schedule_manager.py delete <task_id>
```
#### 暂停/恢复任务
```bash
python {skill_dir}/scripts/schedule_manager.py toggle <task_id>
```
#### 查看执行日志
```bash
python {skill_dir}/scripts/schedule_manager.py logs --limit 10
python {skill_dir}/scripts/schedule_manager.py logs --task-id <task_id>
```
### 时区映射
根据用户语言自动推荐时区:
- 中文 (zh) → Asia/Shanghai (UTC+8)
- 日语 (ja/jp) → Asia/Tokyo (UTC+9)
- 英语 (en) → UTC
### Cron 表达式说明
标准 5 字段格式:`分 时 日 月 星期`
常用示例:
| 表达式 | 含义 |
|--------|------|
| `0 9 * * *` | 每天 9:00 |
| `0 9 * * 1-5` | 周一到周五 9:00 |
| `30 8 * * 1` | 每周一 8:30 |
| `0 */2 * * *` | 每 2 小时 |
| `0 9,18 * * *` | 每天 9:00 和 18:00 |
**注意**: cron 表达式的时间基于 --timezone 指定的时区。
### 一次性任务时间格式
支持 ISO 8601 格式(推荐带时区偏移):
- `2026-04-01T10:00:00+09:00` (日本时间)
- `2026-04-01T01:00:00Z` (UTC)
- `2026-04-01T08:00:00+08:00` (中国时间)
## Examples
**用户**: "帮我设置一个每天早上9点的新闻总结任务"
```bash
python {skill_dir}/scripts/schedule_manager.py add \
--name "每日新闻总结" \
--type cron \
--schedule "0 9 * * *" \
--timezone "Asia/Tokyo" \
--message "请帮我搜索并总结今天的重要科技新闻,用简洁的方式列出 Top 5"
```
**用户**: "提醒我明天下午3点开会"
```bash
python {skill_dir}/scripts/schedule_manager.py add \
--name "开会提醒" \
--type once \
--scheduled-at "2026-03-31T15:00:00+09:00" \
--message "提醒:你现在有一个会议要参加"
```
**用户**: "把每日新闻任务改到早上10点"
```bash
# 先查看任务列表获取 task_id
python {skill_dir}/scripts/schedule_manager.py list
# 然后编辑
python {skill_dir}/scripts/schedule_manager.py edit <task_id> --schedule "0 10 * * *"
```
## Guidelines
- 创建任务前先用 `list` 确认用户已有的任务,避免创建重复任务
- 根据用户语言自动设置合适的时区
- message 内容应该是完整的、可独立执行的指令,因为 AI 执行时没有对话上下文
- 一次性任务的时间不能是过去的时间
- 编辑任务时只修改用户要求改的字段,不要改动其他字段