Scheduled TaskNew
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.
Scheduled Task is merged and in the catalogue. Want me to run the research scout again on Monday, to code the week’s new changelogs against the registry?
"use client";
import * as React from "react";
import { AnimatePresence, motion } from "motion/react";
import { CalendarClock, Check, Loader2, Pencil } from "lucide-react";
import { cn } from "@/lib/utils";
export type ScheduledTaskStatus = "scheduled" | "running" | "ran";
export interface ScheduledTaskProps {
/** What the AI will do, as a short imperative ("Run the research scout"). */
title: string;
/** When it will run, in plain words ("Tomorrow, 9:00"). */
when: string;
/** Other times the user can pick from the edit menu. */
whenOptions?: string[];
status?: ScheduledTaskStatus;
/** Label of the tag above the card. */
label?: string;
onWhenChange?: (when: string) => void;
onRunNow?: () => void;
className?: string;
}
export function ScheduledTask({
title,
when,
whenOptions = [],
status = "scheduled",
label = "Scheduled task",
onWhenChange,
onRunNow,
className,
}: ScheduledTaskProps) {
const [editing, setEditing] = React.useState(false);
const menuId = React.useId();
const canEdit = status === "scheduled" && whenOptions.length > 0;
const open = editing && canEdit;
const subtitle = status === "running" ? "Running now…" : status === "ran" ? "Ran just now" : when;
return (
<motion.div
initial={{ opacity: 0, y: 6 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.25, ease: "easeOut" }}
className={cn("flex w-full max-w-sm flex-col items-start gap-2.5", className)}
>
<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">
{label}
</span>
<div className="w-full rounded-2xl border bg-card">
<div className="flex items-center gap-3 px-4 py-3">
<div className="flex size-9 shrink-0 items-center justify-center rounded-full border bg-muted text-muted-foreground">
<CalendarClock className="size-4" aria-hidden />
</div>
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium text-foreground">{title}</p>
<AnimatePresence mode="wait" initial={false}>
<motion.p
key={subtitle}
initial={{ opacity: 0, y: 3 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -3 }}
transition={{ duration: 0.15 }}
className="flex items-center gap-1 text-xs text-muted-foreground"
aria-live="polite"
>
{status === "running" && <Loader2 className="size-3 animate-spin" aria-hidden />}
{status === "ran" && <Check className="size-3" aria-hidden />}
{subtitle}
</motion.p>
</AnimatePresence>
</div>
{canEdit && (
<button
type="button"
onClick={() => setEditing((v) => !v)}
aria-expanded={open}
aria-controls={menuId}
aria-label={`Change when “${title}” runs`}
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"
>
<Pencil className="size-3.5" aria-hidden />
</button>
)}
</div>
<AnimatePresence initial={false}>
{open && (
<motion.div
id={menuId}
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.2, ease: "easeOut" }}
className="overflow-hidden"
>
<div role="radiogroup" aria-label="Run at" className="flex flex-wrap gap-1.5 border-t px-4 py-3">
{[when, ...whenOptions.filter((o) => o !== when)].map((option) => {
const selected = option === when;
return (
<button
key={option}
type="button"
role="radio"
aria-checked={selected}
onClick={() => {
onWhenChange?.(option);
setEditing(false);
}}
className={cn(
"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",
selected
? "border-foreground/30 bg-foreground text-background"
: "bg-background text-muted-foreground hover:bg-accent hover:text-foreground",
)}
>
{option}
</button>
);
})}
</div>
</motion.div>
)}
</AnimatePresence>
</div>
{status === "scheduled" && onRunNow && (
<button
type="button"
onClick={onRunNow}
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"
>
Run now
</button>
)}
</motion.div>
);
}
A UX spec for this pattern — written for agents implementing or reusing it, not the code.
# Scheduled Task
## Summary
When 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.
## When to use
- 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.
- 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.
- In chat-first products where there is no separate automations screen the user would visit to set this up.
## When not to use
- 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.
- For recurring, event-driven or multi-condition automations — use **Agent Triggers** or **Trigger Condition**, which have room for the configuration.
- For work that is running right now — use **Agent Run Card** or **Background Tasks Drawer** to show progress.
## Anatomy
- **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.
- **Tag**: a small "Scheduled task" pill heading the reply, so the turn reads as a system action, not just text.
- **Task card**: a leading icon, the task's title as a short imperative, and the schedule in plain words beneath ("Monday, 9:00").
- **Edit control**: a pencil at the card's trailing edge that opens the schedule choices inline.
- **Run now**: a secondary pill under the card that runs the task immediately instead of waiting.
- **Confirmation line**: one sentence restating what will happen and where the result will show up.
## Behavior
- The card appears only after the task is really saved; while it's being created show a short "Scheduling…" state, not an optimistic card.
- 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.
- "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.
- 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".
- 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.
## Content guidelines
- 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").
- Write the time relative and concrete: "Tomorrow, 9:00", "In 1 hour", "Monday, 9:00" — never a raw timestamp, and never just "Later".
- Keep the confirmation line to one sentence and say where the result will appear ("I'll link the report here when it's written").
- Keep "Run now" literal; don't rename it to "Skip the wait" or similar.
## Accessibility
- 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.
- The time choices are a `radiogroup` of `radio` buttons so the current one is announced as checked.
- The schedule line is a polite live region, so switching to "Running now…" and "Ran just now" is announced.
- Status changes are conveyed in text, not only by the spinner or check icons, which are `aria-hidden`.
## Related patterns
- **Agent Triggers** — Use it when the task should fire on external events or a recurring schedule configured in a panel.
- **Wait Time Handoff** — Use it when the deferral is a timeout that hands work to a person or workflow.
- **Agent Run Card** — Use it to show the task once it's running or finished.
- **Follow-Up List** — Use it when the next step is a question to ask now rather than work to do later.
Do’s and don’ts
Do use it for
- 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.
- 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.
- In chat-first products where there is no separate automations screen the user would visit to set this up.
Don’t use it for
- 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.
- For recurring, event-driven or multi-condition automations — use Agent Triggers or Trigger Condition, which have room for the configuration.
- For work that is running right now — use Agent Run Card or Background Tasks Drawer to show progress.
Related patterns
Agent Triggers
Use it when the task should fire on external events or a recurring schedule configured in a panel.
Wait Time Handoff
Use it when the deferral is a timeout that hands work to a person or workflow.
Agent Run Card
Use it to show the task once it's running or finished.
Follow-Up List
Use it when the next step is a question to ask now rather than work to do later.