ステップ 10 / 13 - 約 40 分
Lab 09 - Scheduler
Time: about 40 minutes. You will: let Steward start work on its own: a daily study plan before you wake up, and reminders it sets itself when you ask.
Why
Everything so far waits for you to type. A coach that only answers is a reference book. The useful version says "Good morning - your exam is in 54 days; today, context management, three questions" at 07:30, and remembers that you asked to be reminded about the mock exam on Friday.
Concepts
A timer is just another event source
The scheduler does not run turns itself. When a job is due, it hands the gateway (lab 08) a
message for the job's own session, steward:cron:<job>:
[scheduled job "daily-review"] Write a short study plan for today: ...So the queue still applies, scheduled work never clutters your main conversation, and the answer
reaches you through gateway.deliver(): printed in the terminal, pushed to the web page, and
kept in the outbox. The turn context says channel: scheduler, and config/rules.md tells the
model you are not watching: do the job, write a short message, ask no questions.
Jobs
<dataDir>/jobs.json holds every job: its schedule, prompt, next run, last run, and how that
went. Jobs come from two places:
| Source | createdBy |
Who can change it |
|---|---|---|
scheduler.jobs in your config |
owner |
You, by editing the config |
The schedule_task tool |
assistant |
The assistant (cancel_task) and you |
The example config ships one owner job, daily-review (30 7 * * 1-5), disabled. Turn it on with
"enabled": true.
Cron in your time zone
Five fields: minute, hour, day of month, month, day of week (src/scheduler/cron.ts). Fields take
*, numbers, ranges 1-5, lists 1,15, and steps */15. The schedule is evaluated in the
owner's time zone by walking real instants and reading their local time, which handles daylight
saving honestly: a local time that does not exist (02:30 on a spring-forward day) is skipped.
After downtime
Laptops sleep. On start, a job that came due while Steward was off runs once if it is less
than catchUpHours (12) late; older misses are skipped to the next run (a one-off job is turned
off) and marked skipped: missed by .... Nobody wants six "good morning" messages after a week
away.
Steward's scheduler is a timer in its own process, so it runs only while Steward runs. Claude Managed Agents offers the same idea as a hosted service: scheduled deployments that start a session on a cron schedule (lab 12 compares the two approaches).
Guards on the assistant's own schedule
schedule_task is the first tool that makes the assistant act later without you. Its guards are
ordinary code inside the tool: a refused call comes back to the model as a
tool result with is_error, and the model
explains it to you. So:
- the default policy asks before it runs (lab 05);
- at most 20 assistant jobs; a recurring job may run at most every 30 minutes;
- one-off times must be in the future, given as
YYYY-MM-DD HH:MMin your time zone; - the assistant can cancel only jobs it created.
Build
src/config/config.ts- theschedulersection andJobConfig.src/scheduler/cron.ts-parseCron(),localParts(),nextRun().src/scheduler/job-store.ts-JobStore(atomic writes) andsyncOwnerJobs().src/scheduler/scheduler.ts-start()(catch-up rule, then a timer that sleeps until the next job, at most 60 seconds),tick(), andrunJob()(run, deliver, reschedule).src/scheduler/schedule-tools.ts-schedule_task,list_tasks,cancel_task, andlocalToInstant().
Run
pnpm steward chatyou> Remind me on Friday at 9:00 to take a full mock exam.Approve the schedule_task request. Steward picks a job id such as mock-exam-friday. Quit the
chat (only one Steward process may use the data folder at a time, see lab 12), then:
pnpm steward jobs # find the id
pnpm steward jobs run mock-exam-friday # run it now instead of waitingThe job's answer appears as [job:mock-exam-friday] .... Running a one-off job by hand uses it
up: it will not fire again on Friday. Ask Steward to schedule it again if you still want the
reminder. jobs run runs only the job you name, even when others are due, and it does not
change whether the job is enabled. To try the owner job, run pnpm steward jobs run daily-review;
to have it fire on its own schedule, set "enabled": true on daily-review in your local config.
Break it
- Spam. Ask:
Check in on me every minute. Steward asks for approval first (the policy runs before the tool). Approve it:schedule_taskthen refuses with "recurring jobs may run at most every 30 minutes". The guard checks the shortest gap over the next eight days, so0,59 * * * *(59 and 00, one minute apart) is refused too. - Downtime. You need an enabled recurring job: set
"enabled": trueondaily-reviewin your local config. Stop Steward, edit<dataDir>/jobs.jsonso that job'snextRunis three days ago, and startpnpm steward serve. In another terminal,pnpm steward jobsshowslast skipped: missed by 72h while offline, and the job is rescheduled instead of firing. (Whileserveruns,steward jobsonly readsjobs.json; the running process owns it.) - Your jobs are yours. Ask Steward to cancel
daily-review. It cannot: the job belongs to your config.
Check
pnpm lab 09The checkpoint proves: cron parsing and errors; next runs in different time zones; the skipped
spring-forward time; classic day-of-month OR day-of-week; local-time conversion across DST and New
Year; scheduling guards; owner jobs protected and schedule_task asking first; a due job runs in
its own session, is delivered, and is rescheduled; one-off jobs run once; recent misses catch up
and old ones are skipped; assistant jobs survive config changes.
Exercises
- Add quiet hours (for example 22:00-07:00): jobs that come due then are delivered at 07:00.
- Let the daily review adapt: the job prompt asks Steward to read memory and the study log, so the plan changes as you progress. Try it for a week and read the outbox.
- Allow one-off reminders within the next 30 days without asking, and keep asking for recurring jobs. Which policy feature do you need?
Claude API docs
- Define tools - how
schedule_taskdescribes itscronandatinputs - Handle tool calls - returning a refused schedule as an error result
- Strict tool use - make the API guarantee that tool inputs match the schema
- Batch processing - half-price requests for scheduled work that nobody waits for and that needs no tool loop
- Building effective agents - when an agent should act on its own, and with which guardrails
Exam connection
CCA-F - Agentic Architecture & Orchestration: proactive agents, event sources beyond the user, and isolating background work from interactive sessions. Practice this domain on CertLabPro, or every morning in the CertLabPro app.
Previous: Lab 08 - Next: Lab 10 - Sub-agents