Documentation menu
Documentation

Scheduling

Run one-time, delayed, recurring, and cron work inside the agent that owns it.

Start from a fresh project

This guide is self-contained. Create an empty Ayjnt project, then replace the starter agent with the files shown below. Run commands from the new project directory unless a step says otherwise.

terminal
bunx ayjnt new try-scheduling --empty
cd try-scheduling
bun install

# remove agents/alive once you are ready to add the guide's files

Schedule methods by name

A scheduled callback is a method on the agent. Use a number for seconds from now, a Date for a specific time, a cron expression for calendar schedules, or scheduleEvery() for fixed intervals.

example
async onStart() {
  await this.scheduleEvery(60, "checkInbox");
  await this.schedule("0 9 * * 1-5", "dailyBrief");
}

async remind(taskId: string) {
  const schedule = await this.schedule(15 * 60, "sendReminder", { taskId });
  return schedule.id;
}

async sendReminder(payload: { taskId: string }) {
  // durable callback
}

Inspect and cancel

Use getScheduleById(), listSchedules(), and cancelSchedule(). Recurring and cron calls are idempotent where documented, which makes onStart() a safe place to ensure a recurring schedule exists.

Run it and verify the result

Create a one-minute schedule, keep the dev server running, and watch the run appear in state after the agent wakes.

terminal
bun run build
bun run dev

# the local app is now available at http://localhost:8787