自动化命令 (/automation)

本页目录

通过在对话中向 Agent 描述需求来设置定时后台自动化任务,无需手动编写 sidecar.json。

概览

后台自动化任务(原名“定时任务”)会按周期性计划运行 Agent 提示词,例如每日摘要、每周拉取请求检查或夜间测试报告。每次运行都会启动一个全新的 Agent 对话,不保留之前运行的记忆。

/automation 命令会让 Agent 引导你完成创建流程。你也可以在 Automations 标签页中选择 Create with Prompt 来启动相同的流程,这会打开一个新对话并预先填入 /automation 命令供你发送。Agent 会执行以下操作:

  • 询问执行计划:由你选择执行频率、日期和时间。Agent 始终使用你提到的时区或城市(或你计算机所在的时区),通过 CRON_TZ=<zone> 将计划固定到对应的 IANA 时区。
  • 编写独立完整的提示词:将你希望任务执行的操作提炼为无需依赖早期对话即可独立运行的指令。
  • 创建自动化任务:将自动化任务保存到 ~/.gemini/config/sidecars/<automation-id>/sidecar.json。新建的自动化任务最初会显示在 Automations 标签页的 Paused 下,直到你手动将其开启。
  • 立即或稍后设置权限:如果选择立即设置,它会在当前对话中运行一次该任务,并记录此次运行所需的确切权限。
  • 汇总自动化任务信息:列出执行计划、任务内容和权限,并提供一个 Open Automations Dashboard 按钮,方便你前往开启该自动化任务。

自动化任务默认使用 Flash 模型运行。在 Automations 标签页中创建或编辑自动化任务时,你可以选择 Flash Lite、Flash 或 Pro。

Launch /automation

可通过以下任意一种方式在对话输入框中启动 /automation:

  • 附带行内提示词:输入 /automation,并在后面紧跟自动化任务应执行的操作及运行时间:

    /automation every Monday at 9am Pacific time, check my open pull requests and list any with failing checks
  • 引导式设置:单独运行 /automation,或在 Automations 标签页中选择 Create with Prompt 并发送预填的命令。随后 Agent 会逐一询问各项细节:

    /automation

/automation 的工作原理

Agent 会在对话中通过简短的问答流程来创建自动化任务:

  1. 选择执行频率

    Agent 会询问自动化任务的运行频率:Hourly(每小时)、Daily(每天)、Weekly(每周)或 Custom cron schedule(自定义 cron 计划)。

    automation
    Explored file
    Asking 1 question
    Waiting for user input.
    What should be the cadence of the automation?
    • Hourly
    • Daily
    • Weekly (selected)
    • Custom cron schedule
    • Other (write your answer)
  2. 选择日期和时间

    Agent 会询问具体的日期和时间,然后连同时区一起确认执行计划。它会将你的回答转换为带有 CRON_TZ=<IANA zone> 前缀的五字段 cron 表达式,例如 CRON_TZ=America/Los_Angeles 0 9 * * 1。

  3. 描述任务内容

    Agent 会询问自动化任务应执行的操作,并将你的回答提炼为一段独立完整的提示词,明确说明任务目标、查找位置以及报告内容:

    automation
    Worked for 1m
    1 question
    What should be the cadence of the automation?
    Weekly
    2 questions
    Which day(s) of the week should it run?
    Monday
    At what time of day?
    9:00 AM

    Got it, every Monday at 9:00 AM America/Los_Angeles time.

    What would you like the task to do? (For example: "Check my open pull requests and list any with failing checks.")

  4. 立即或稍后设置权限

    Agent 会创建该自动化任务,随后询问是否立即运行一次测试以配置自动化任务的权限。如果选择测试运行,Agent 会在当前对话中运行一次该任务,并将此次运行所需的确切权限记录到自动化任务的 agent_permissions 中。如果选择跳过,你可以在 Automations 标签页中审阅权限并开启该自动化任务。

    Created automation
    Asking 1 question
    Waiting for user input.
    Once enabled, 'Weekly PR Check' will run in a project that inherits global permissions and presets, and all other non-approved commands will be auto-denied. Would you like me to execute a test run now to configure its permissions properly so it can proceed successfully?
    • (Recommended) Yes, execute a test run now to configure permissions (selected)
    • No, I'll review permissions and enable 'Weekly PR Check' in the Automations dashboard
    • Other (write your answer)
  5. 审阅摘要并打开 Automations 标签页

    Agent 会汇总自动化任务的信息:名称和 ID、执行计划、任务内容以及已授予的所有权限,同时显示 Open Automations Dashboard 按钮,方便你开启该自动化任务:

    Sounds good. Summary of what's set up:

    • Automation: Weekly PR Check (weekly-pr-check)
    • Schedule: every Monday at 9:00 AM America/Los_Angeles
    • Task: lists your open pull requests and reports any with failing checks, with links and the failing check names (read-only; no changes to pull requests).
    • Permissions granted: gh pr list,gh pr checks

    Enable it when you're ready: Open Automations Dashboard. If the first run gets blocked on a permission, let me know and I can run a test pass to tighten the grants.

如需开始使用该自动化任务,请打开 Automations 标签页(该任务列在 Paused 下),检查其权限并将其开启。开启后,你还可以通过 Run Now 立即运行一次。

有关自动化任务使用的 sidecar.json 字段(包括 arguments 和 agent_permissions),请参阅自动化任务。

示例提示词

以下提示词展示了 /automation 的常见用法:

  • 每周拉取请求检查:

    /automation every Monday at 9am Pacific time, check my open pull requests and list any with failing checks
  • 工作日问题分类处理:

    /automation every weekday at 9am in New York, triage new GitHub issues and label them by severity
  • 夜间测试报告:

    /automation every night at midnight UTC, run the integration test suite and summarize any failures

/automation 与 /schedule 的对比

/automation 和 /schedule 都能按计划运行 Agent 任务,但适用范围不同:

/automation/schedule
最适合周期性任务,例如每日报告、夜间维护和问题分类处理任务执行期间的计时器、CI 轮询和状态检查
SurfacesAntigravity AppAntigravity App、Antigravity CLI 和 Antigravity IDE
Schedule通过 CRON_TZ=<IANA zone> 固定时区的 cron 表达式一次性计时器或 cron 循环
Lifetime跨会话和重启持续有效,直到你将其关闭Current conversation
上下文每次运行时启动全新的 Agent 对话唤醒现有的 Agent 并保留完整的对话历史记录
存储位置~/.gemini/config/sidecars/<automation-id>/sidecar.json,在 Automations 标签页中管理由 Agent 代你发起的工具调用
权限测试运行后记录的限定范围的 agent_permissions当前对话的权限

对于未打开对话时仍需持续运行的无人值守任务,请使用 /automation。如果你希望当前对话中的 Agent 在计时器到期后唤醒,或在你继续工作时轮询某项操作,请使用 /schedule。

下一步

Explore related documentation:

  • Sidecar:了解如何配置自动化任务及其他 Sidecar,包括 arguments 和 agent_permissions。
  • 定时命令 (/schedule):在对话中设置一次性计时器和周期性计划任务。
  • 权限:了解访问授权的工作原理。
  • 斜杠命令概览:浏览所有可用的斜杠命令。