Overview
Agents provide built-in task scheduling with support for one-time tasks, delayed execution, cron-based schedules, and fixed intervals. Schedules persist across hibernation and support automatic retry on failure.schedule()
Schedule a callback to run at a future time or on a recurring interval.keyof this
required
Name of the method to call
ScheduleOptions
required
Schedule configuration (see variants below)
Promise<string> - Schedule ID
Schedule Types
One-Time (Specific Time)
Execute a callback at a specific date/time.Date
required
Date/time to execute
T
Data to pass to the callback
RetryOptions
Retry options for this schedule
Delayed Execution
Execute a callback after a delay (in seconds).number
required
Number of seconds to delay
T
Data to pass to the callback
RetryOptions
Retry options for this schedule
Cron Schedule
Execute a callback on a recurring schedule using cron syntax.string
required
Cron expression (e.g., “0 0 * * *”)
T
Data to pass to the callback
RetryOptions
Retry options for this schedule
minute hour day month weekday
*= any value*/n= every n units0-6= Sunday through Saturday (for weekday)
Interval
Execute a callback at fixed intervals (in seconds).number
required
Number of seconds between executions
T
Data to pass to the callback
RetryOptions
Retry options for this schedule
Interval schedules are resilient to hung executions. If a callback takes longer than
hungScheduleTimeoutSeconds (default: 30s), the interval is reset.Callback Implementation
Scheduled callbacks receive the payload (if provided):Retry Options
Schedules support automatic retry on failure:RetryOptions
Retry options can also be configured globally via static
options.retry on the Agent class.Managing Schedules
getSchedules()
Query existing schedules.cancelSchedule()
Cancel a scheduled task.updateSchedule()
Update a schedule’s payload or timing:Queue vs Schedule
queue()
For immediate asynchronous execution:- Immediate background tasks
- Fire-and-forget operations
- No specific timing requirements
schedule()
For time-based or recurring execution:- Time-based tasks
- Recurring operations
- Delayed execution
Natural Language Scheduling
Use AI to parse natural language schedule requests:- “Backup database every day at midnight”
- “Send report tomorrow at 2 PM”
- “Run health check every 15 minutes”
Persistence
Schedules are stored in SQLite:Best Practices
Keep Callbacks Small
Use Payloads for Context
Handle Failures
Use Cron for Recurring Tasks
Related
- Agent Class - Agent base class
- Natural Language Scheduling - Example