跳到主要内容

定时任务(Cron)

Cron 是 Anyy 的常驻调度器。它把 scheduled jobs 存在当前 home 的 state database 中,并通过 gateway runtime 执行。

适合 Cron 的场景包括 recurring 或 delayed work:日报、提醒、定时 skill run、周期检查、脚本维护。被动待办事项应使用 tasks。

Cron 当前能做什么

Anyy 支持这些 cron job kinds:

Kind含义
agent在调度时间启动一次 agent turn。
skill运行面向 skill 的定时工作。
notify运行通知型定时工作。
script通过 CLI 创建的 scripts 目录脚本任务。
reminder模型侧 kind,存储时为 notify 且 source 为 reminder

模型可见 automation 工具暴露 agentskillnotifyreminder。Script jobs 通过 CLI 创建,不通过模型 automation tools 创建。

创建定时任务

从聊天创建

可以直接自然语言要求 Anyy:

Remind me in 30 minutes to check the build.
Every day at 9, summarize today's priority tasks.

模型创建任务时,automation tool 使用 canonical schedule object。Assistant 不应在顶层使用 wheneverycronrecurring 等 legacy 字段。

canonical shape 示例:

{
"kind": "reminder",
"schedule": {"type": "once", "at": "30m"},
"message": "Check the build."
}
{
"kind": "agent",
"name": "Daily task summary",
"schedule": {"type": "every", "mode": "advanced_cron", "cron": "0 9 * * *"},
"prompt": "Summarize today's priority tasks and notify me."
}

从 CLI 创建

需要明确命令时使用 anyy cron

anyy cron create --name "Daily summary" --schedule "0 9 * * *" --prompt "Summarize today's priorities"
anyy cron list
anyy cron update --id cron_123 --disable
anyy cron delete --id cron_123

CLI 还支持 --kind--script--skills--toolsets--workdir--role--workspace--delivery-target--delivery-channel

完整语法见 CLI Commands

从 Dashboard 创建

Dashboard 的 Cron 页面可以列出定时任务、创建任务、查看运行历史、编辑 schedule 和 prompt、暂停或恢复任务,并删除任务。Dashboard 使用与 CLI 相同的 resident gateway RPC。

调度格式

调度器接受三类 schedule。

一次性

一次性任务接受正 duration 或 RFC3339 timestamp:

30m
2h
1d
2026-06-16T09:00:00Z

模型 automation tools 使用:

{"type": "once", "at": "30m"}

间隔

循环间隔在存储和 CLI 里使用 every <duration>

every 30m
every 2h
every 1d

模型 automation tools 使用:

{"type": "every", "mode": "interval", "interval": "30m"}

Advanced Cron

当前 parser 支持五字段表达式,其中 day、month、weekday 必须是 *,minute/hour 可以是 * 或数字:

0 9 * * *
30 * * * *
* 14 * * *

模型 automation tools 使用:

{"type": "every", "mode": "advanced_cron", "cron": "0 9 * * *"}

Calendar-style recurrence 还不支持。schedule.mode=calendar 会被 automation tool 拒绝。

Advanced cron schedules 要求可靠的 IANA timezone。如果 Anyy 无法解析可靠 timezone,会拒绝创建,而不是静默猜测。

投递

Cron jobs 可以投递到 gateway、原始 channel,或当前用户默认 channel binding。CLI 创建的任务也可以使用 none,用于不需要用户通知的任务。

模型创建 automation 时不接受 delivery target none;它保留给内部 scheduler jobs。

示例:

anyy cron create \
--name "Weixin digest" \
--schedule "0 9 * * *" \
--prompt "Send my morning digest" \
--delivery-target current_user_default \
--delivery-channel weixin

投递错误会通过 cron run status、job metadata 和 outbox records 暴露。如果 cron job 记录了新的 failure signature,heartbeat 可以发布失败通知。

Role 与 Workspace Scope

Cron jobs 按 role 和 workspace 归属。CLI 命令默认按 profile-wide 列出,除非传入 --role--workspace--all-scopes

CLI 创建的新任务在未指定 --role 时使用当前 selected default role。从 session 创建的任务继承该 session 的 runtime scope。

生命周期操作

使用:

anyy cron list --include-disabled
anyy cron update --id cron_123 --enable
anyy cron update --id cron_123 --schedule "every 1h"
anyy cron delete --id cron_123

模型工具里的 lifecycle 入口:

工具用途
automation_list列出可见的 scheduled automations 和 reminders。
automation_create创建定时 automation 或 reminder。
automation_update启用、禁用、重排时间或修改 prompt。
automation_delete删除定时 automation。
automation_run尽快把 job 排队给 scheduler claim。
automation_history列出近期运行历史和输出。

Automation tools 只展示模型可见 job kinds。Script jobs 不通过这些工具暴露。

历史记录

Cron run records 会记录状态:runningsucceededfailedcancelledskippedwaiting_approval。输出以 stdout、stderr 或 tool output records 存储。

对话中可用 automation_history;本地 runtime surface 可以通过 cron history RPC 查看。

Runtime Loop

常驻 gateway 会启动 scheduler loop。默认 tick interval 是一分钟。可通过配置覆盖:

cron:
tick_interval: 30s

兼容字段 tick_interval_seconds 也被接受。

Gateway 必须运行,scheduled work 才会执行。如果定时任务没有触发,检查 anyy statusanyy doctoranyy heartbeat status