Schedule agent executions at specific times, intervals, and recurring patterns
Scheduling enables agents to run automatically on time-based schedules, from simple recurring tasks to complex time-orchestrated workflows, ensuring critical operations happen exactly when needed.
The Scheduling primitive allows you to execute agents at specified times using cron expressions, intervals, or custom schedules. Whether you need daily reports, hourly data syncs, or one-time future executions, scheduling makes it effortless to automate time-based operations.Scheduling is essential for:
Recurring Tasks: Run agents daily, weekly, monthly, or custom intervals
Batch Processing: Process data during off-peak hours
Regular Reports: Generate and distribute reports on schedule
Maintenance Operations: Perform cleanup and optimization tasks
Time-Based Triggers: Execute agents at specific times or dates
Multi-Region Coordination: Schedule across different time zones
Cron Expressions
Use familiar cron syntax for flexible scheduling
Time Zones
Schedule in any time zone with automatic DST handling
// Run every hourconst hourlySync = await agentbase.scheduleAgent({ name: "hourly_data_sync", interval: "1h", agent: { message: "Sync data from external API", system: "Fetch latest data and update database" }});// Run every 15 minutesconst frequentCheck = await agentbase.scheduleAgent({ name: "health_check", interval: "15m", agent: { message: "Check system health", system: "Monitor services and alert if issues detected" }});
// First day of every monthconst monthlyReport = await agentbase.scheduleAgent({ name: "monthly_financial_report", schedule: "0 0 1 * *", // Midnight on 1st of each month timezone: "America/New_York", agent: { message: "Generate monthly financial report", system: `Create comprehensive monthly report: - Revenue and expenses - Profit margins - Cash flow analysis - Budget variance - Key metrics and KPIs Distribute to finance team and executives.` }});// Last day of every monthconst monthEnd = await agentbase.scheduleAgent({ name: "month_end_close", schedule: "0 23 L * *", // 11 PM on last day of month timezone: "America/New_York", agent: { message: "Perform month-end closing procedures", system: "Run accounting close process" }});
// Only run if condition is metconst conditionalSchedule = await agentbase.scheduleAgent({ name: "conditional_cleanup", schedule: "0 3 * * *", // Daily at 3 AM preCheck: { condition: "SELECT COUNT(*) FROM temp_data WHERE created_at < NOW() - INTERVAL '7 days'", runIfGreaterThan: 0 }, agent: { message: "Clean up old temporary data", system: "Delete temp data older than 7 days" }});
// Every day at midnightschedule: "0 0 * * *"// Every weekday at 9 AMschedule: "0 9 * * 1-5"// Every hour on the hourschedule: "0 * * * *"// Every 30 minutesschedule: "*/30 * * * *"// First day of month at noonschedule: "0 12 1 * *"// Last day of month at 11 PMschedule: "0 23 L * *"// Weekends only at 8 AMschedule: "0 8 * * 6,0"
{ schedule: "*/5 * * * *", // Every 5 minutes concurrency: { policy: "skip", // Skip if previous still running // Other options: "queue", "cancel_previous" }, timeout: 300000 // 5 minute timeout}
Set Expiration
Copy
// Schedule expires after date{ schedule: "0 9 * * *", expiresAt: "2024-12-31T23:59:59Z", onExpiration: "archive" // or "delete"}// Or after number of executions{ schedule: "0 12 * * *", maxExecutions: 30, // Run 30 times then stop onComplete: "notify_owner"}
// Optimize costs for frequent schedules{ schedule: "*/1 * * * *", // Every minute optimization: { skipIfNoWork: true, // Skip execution if no pending work earlyExit: true, // Exit early if nothing to do cacheResults: 300 // Cache for 5 minutes }}
{ schedule: "0 9 * * *", catchUpMissed: true, // Run missed executions executionWindow: { start: "09:00", end: "11:00" // Can run anytime in this window }}
Time Zone Issues
Problem: Schedule running at wrong timeSolutions:
Verify time zone string is correct
Check for DST transitions
Use UTC for consistency
Test schedule with multiple dates
Copy
// Validate time zone and get next runsconst validation = await agentbase.validateSchedule({ schedule: "0 9 * * *", timezone: "America/New_York", showNext: 10 // Show next 10 runs});validation.nextRuns.forEach(run => { console.log('Will run at:', run.local, '(', run.utc, 'UTC)');});
Overlapping Executions
Problem: New execution starting while previous still runningSolutions:
Increase timeout
Set concurrency policy to skip
Optimize agent execution time
Reduce schedule frequency
Copy
{ schedule: "*/5 * * * *", timeout: 240000, // 4 minutes (less than 5 min interval) concurrency: { policy: "skip" // Don't start if already running }}