{"slug":"scheduled-task","category":"messages","job":"steer","added":"2026-11-15T00:03Z","title":"Scheduled Task","description":"When the user accepts an offer to do something later, the reply confirms it as a \"Scheduled task\" card with the time in plain words, a pencil to change it and a Run now button.","url":"https://ai-patterns.app/patterns/messages/scheduled-task","markdown":"https://ai-patterns.app/patterns/messages/scheduled-task.md","json":"https://ai-patterns.app/api/patterns/messages/scheduled-task","seenIn":[{"team":"chatgpt","source":"https://help.openai.com/en/articles/10291617-tasks-in-chatgpt"}],"spec":"# Scheduled Task\n\n## Summary\nWhen the assistant offers to do something later (\"Want me to run the research scout again on Monday?\") and the user accepts, the reply confirms it as a scheduled task right in the conversation: a \"Scheduled task\" tag, a card naming the task and when it will run, an edit control to change the time, and a \"Run now\" button. It turns a promise in prose into a visible, editable commitment.\n\n## When to use\n- When the AI can run work on its own at a later time (a follow-up draft, a recurring check, a next step of a longer project) and the user has just asked for or accepted that.\n- When the natural end of a turn is \"let's continue later\" — the card replaces a vague \"sure, tomorrow!\" with something the user can check, adjust or trigger.\n- In chat-first products where there is no separate automations screen the user would visit to set this up.\n\n## When not to use\n- When the product can't actually run anything unattended — a card that says \"Tomorrow\" but needs the user to come back and type is a broken promise; offer a reminder or a follow-up suggestion instead.\n- For recurring, event-driven or multi-condition automations — use **Agent Triggers** or **Trigger Condition**, which have room for the configuration.\n- For work that is running right now — use **Agent Run Card** or **Background Tasks Drawer** to show progress.\n\n## Anatomy\n- **Offer** (preceding turn): the assistant proposes the deferred work, ideally as a one-tap option the user can accept (\"Run the research scout on Monday\"); once accepted it stays visible, dimmed with a check.\n- **Tag**: a small \"Scheduled task\" pill heading the reply, so the turn reads as a system action, not just text.\n- **Task card**: a leading icon, the task's title as a short imperative, and the schedule in plain words beneath (\"Monday, 9:00\").\n- **Edit control**: a pencil at the card's trailing edge that opens the schedule choices inline.\n- **Run now**: a secondary pill under the card that runs the task immediately instead of waiting.\n- **Confirmation line**: one sentence restating what will happen and where the result will show up.\n\n## Behavior\n- The card appears only after the task is really saved; while it's being created show a short \"Scheduling…\" state, not an optimistic card.\n- The edit control expands the card in place with a few likely times (the current one selected); choosing one updates the card's schedule line and the confirmation line, and collapses the choices. Link out to a full scheduler for anything finer.\n- \"Run now\" swaps the schedule line for a running state, then \"Ran just now\" with a check; the edit control and Run now disappear once the task has run, since there is nothing left to schedule.\n- When the task runs on schedule, its result arrives in the same conversation (or a notification links back to it), so the card stays the anchor for \"what did I ask for, and when\".\n- The card stays in the transcript afterwards and reflects the task's latest state (scheduled, running, ran, cancelled), rather than freezing at the moment it was created.\n\n## Content guidelines\n- Title the task as what the AI will do, in the user's words where possible (\"Run the research scout\"), not the system's (\"Task #4821\").\n- Write the time relative and concrete: \"Tomorrow, 9:00\", \"In 1 hour\", \"Monday, 9:00\" — never a raw timestamp, and never just \"Later\".\n- Keep the confirmation line to one sentence and say where the result will appear (\"I'll link the report here when it's written\").\n- Keep \"Run now\" literal; don't rename it to \"Skip the wait\" or similar.\n\n## Accessibility\n- The edit control is a real button with an accessible name that includes the task (\"Change when “Run the research scout” runs\") and `aria-expanded` tied to the choices it reveals.\n- The time choices are a `radiogroup` of `radio` buttons so the current one is announced as checked.\n- The schedule line is a polite live region, so switching to \"Running now…\" and \"Ran just now\" is announced.\n- Status changes are conveyed in text, not only by the spinner or check icons, which are `aria-hidden`.\n\n## Related patterns\n- **Agent Triggers** — Use it when the task should fire on external events or a recurring schedule configured in a panel.\n- **Wait Time Handoff** — Use it when the deferral is a timeout that hands work to a person or workflow.\n- **Agent Run Card** — Use it to show the task once it's running or finished.\n- **Follow-Up List** — Use it when the next step is a question to ask now rather than work to do later.\n","code":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport { CalendarClock, Check, Loader2, Pencil } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport type ScheduledTaskStatus = \"scheduled\" | \"running\" | \"ran\";\n\nexport interface ScheduledTaskProps {\n  /** What the AI will do, as a short imperative (\"Run the research scout\"). */\n  title: string;\n  /** When it will run, in plain words (\"Tomorrow, 9:00\"). */\n  when: string;\n  /** Other times the user can pick from the edit menu. */\n  whenOptions?: string[];\n  status?: ScheduledTaskStatus;\n  /** Label of the tag above the card. */\n  label?: string;\n  onWhenChange?: (when: string) => void;\n  onRunNow?: () => void;\n  className?: string;\n}\n\nexport function ScheduledTask({\n  title,\n  when,\n  whenOptions = [],\n  status = \"scheduled\",\n  label = \"Scheduled task\",\n  onWhenChange,\n  onRunNow,\n  className,\n}: ScheduledTaskProps) {\n  const [editing, setEditing] = React.useState(false);\n  const menuId = React.useId();\n  const canEdit = status === \"scheduled\" && whenOptions.length > 0;\n\n  const open = editing && canEdit;\n\n  const subtitle = status === \"running\" ? \"Running now…\" : status === \"ran\" ? \"Ran just now\" : when;\n\n  return (\n    <motion.div\n      initial={{ opacity: 0, y: 6 }}\n      animate={{ opacity: 1, y: 0 }}\n      transition={{ duration: 0.25, ease: \"easeOut\" }}\n      className={cn(\"flex w-full max-w-sm flex-col items-start gap-2.5\", className)}\n    >\n      <span className=\"rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2.5 py-0.5 text-xs font-medium text-emerald-700 dark:text-emerald-400\">\n        {label}\n      </span>\n\n      <div className=\"w-full rounded-2xl border bg-card\">\n        <div className=\"flex items-center gap-3 px-4 py-3\">\n          <div className=\"flex size-9 shrink-0 items-center justify-center rounded-full border bg-muted text-muted-foreground\">\n            <CalendarClock className=\"size-4\" aria-hidden />\n          </div>\n          <div className=\"min-w-0 flex-1\">\n            <p className=\"truncate text-sm font-medium text-foreground\">{title}</p>\n            <AnimatePresence mode=\"wait\" initial={false}>\n              <motion.p\n                key={subtitle}\n                initial={{ opacity: 0, y: 3 }}\n                animate={{ opacity: 1, y: 0 }}\n                exit={{ opacity: 0, y: -3 }}\n                transition={{ duration: 0.15 }}\n                className=\"flex items-center gap-1 text-xs text-muted-foreground\"\n                aria-live=\"polite\"\n              >\n                {status === \"running\" && <Loader2 className=\"size-3 animate-spin\" aria-hidden />}\n                {status === \"ran\" && <Check className=\"size-3\" aria-hidden />}\n                {subtitle}\n              </motion.p>\n            </AnimatePresence>\n          </div>\n          {canEdit && (\n            <button\n              type=\"button\"\n              onClick={() => setEditing((v) => !v)}\n              aria-expanded={open}\n              aria-controls={menuId}\n              aria-label={`Change when “${title}” runs`}\n              className=\"flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent focus-visible:outline-none\"\n            >\n              <Pencil className=\"size-3.5\" aria-hidden />\n            </button>\n          )}\n        </div>\n\n        <AnimatePresence initial={false}>\n          {open && (\n            <motion.div\n              id={menuId}\n              initial={{ height: 0, opacity: 0 }}\n              animate={{ height: \"auto\", opacity: 1 }}\n              exit={{ height: 0, opacity: 0 }}\n              transition={{ duration: 0.2, ease: \"easeOut\" }}\n              className=\"overflow-hidden\"\n            >\n              <div role=\"radiogroup\" aria-label=\"Run at\" className=\"flex flex-wrap gap-1.5 border-t px-4 py-3\">\n                {[when, ...whenOptions.filter((o) => o !== when)].map((option) => {\n                  const selected = option === when;\n                  return (\n                    <button\n                      key={option}\n                      type=\"button\"\n                      role=\"radio\"\n                      aria-checked={selected}\n                      onClick={() => {\n                        onWhenChange?.(option);\n                        setEditing(false);\n                      }}\n                      className={cn(\n                        \"cursor-pointer rounded-full border px-2.5 py-1 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n                        selected\n                          ? \"border-foreground/30 bg-foreground text-background\"\n                          : \"bg-background text-muted-foreground hover:bg-accent hover:text-foreground\",\n                      )}\n                    >\n                      {option}\n                    </button>\n                  );\n                })}\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n\n      {status === \"scheduled\" && onRunNow && (\n        <button\n          type=\"button\"\n          onClick={onRunNow}\n          className=\"cursor-pointer rounded-full border bg-background px-4 py-1.5 text-sm text-foreground transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n        >\n          Run now\n        </button>\n      )}\n    </motion.div>\n  );\n}\n","dependencies":["lucide-react","motion"],"localImports":["@/lib/utils"]}