Skip to content

Latest commit

 

History

History
126 lines (87 loc) · 2.61 KB

File metadata and controls

126 lines (87 loc) · 2.61 KB

s14: Cron Scheduler

Background tasks run now. Sometimes an agent needs to schedule work for later: reminders, periodic checks, delayed follow-ups, or recurring maintenance.

This chapter adds a simple cron scheduler.

Run

cargo run -p s14_cron_scheduler

New Capabilities

  • Add CronScheduler.
  • Add cron_create.
  • Add cron_list.
  • Add cron_delete.
  • Persist scheduled tasks.
  • Match schedules using cron expressions.
  • Re-inject due tasks into the agent loop.

Why Cron

An agent harness is not only a request-response loop. It can also react to time.

Cron scheduling lets the agent express:

Do this later

or:

Check this periodically

The scheduler turns time into another event source for the agent.

Code Layout

s14_cron_scheduler/
├── src/
│   ├── main.rs
│   ├── lib.rs
│   ├── cron.rs
│   └── tool/
│       ├── cron_create.rs
│       ├── cron_list.rs
│       ├── cron_delete.rs
│       ├── bash.rs
│       ├── read_file.rs
│       ├── write_file.rs
│       └── edit_file.rs
├── s14.md
└── cron_rs_explained.md

Scheduler logic is in src/cron.rs.

ScheduledTask

A scheduled task contains:

  • id
  • schedule expression
  • prompt or message to inject
  • enabled state
  • last run time
  • next run time

This gives the scheduler enough durable state to list, delete, and trigger tasks.

cron_create

Example:

{
  "schedule": "0/5 * * * * *",
  "prompt": "Check whether the background test job has finished."
}

The exact cron syntax depends on the cron parser used by the chapter.

cron_list

Lists known scheduled tasks and their next run times.

cron_delete

Removes a scheduled task by id.

Re-injecting Work

When a task becomes due, the scheduler injects a new user message into the agent context.

This keeps the core model loop unchanged:

time event -> user-like message -> model -> tool use -> result

The scheduler is an event source, not a second agent loop.

Rust Notes

  • Keep scheduled tasks durable.
  • Use a scheduler manager rather than direct file access from tools.
  • Convert due scheduled work into normal agent messages.
  • Keep cron operations as separate typed tools.

Limits

  • No distributed scheduler.
  • No time zone UI beyond the chosen implementation.
  • No missed-run recovery beyond the teaching version.
  • No complex recurrence management.
  • No calendar-style scheduling.

Next

s15 introduces agent teams. Instead of one agent doing everything, named teammates can communicate through inboxes.