Skip to main content

What are Jobs?

Jobs are scheduled tasks that run automatically at specified times or intervals, without requiring user interaction. They enable your agent to perform automated operations like sending reports, cleaning up data, or monitoring systems.

Think of it as:

A scheduled assistant - tasks that run on their own schedule, like daily reports or weekly cleanup
New in v3.0.0: Two ways to create jobs - pre-defined with LuaJob or dynamically with Jobs API.

Why Jobs?

Automation

Run tasks automatically without user requests

Proactive Engagement

Send reminders, reports, and updates at the right time

Maintenance

Clean up old data, monitor health, maintain systems

Scheduled Communication

Send daily summaries, weekly reports, monthly newsletters

Two Types of Jobs

Static jobs defined at agent setup
import { LuaJob, User } from 'lua-cli';

const dailyReport = new LuaJob({
  name: 'daily-sales-report',
  schedule: {
    type: 'cron',
    expression: '0 9 * * *'  // Every day at 9 AM
  },
  metadata: {
    userId: 'user_abc123'  // Store user ID in metadata
  },
  execute: async (job) => {
    // ⚠️ Pre-defined jobs have NO conversational context
    // Get user by ID from metadata
    const user = await User.get(job.metadata.userId);
    await user.send([{
      type: 'text',
      text: 'Your daily report is ready!'
    }]);
  }
});
Best for:
  • Daily/weekly reports
  • Cleanup tasks
  • System monitoring
  • Recurring notifications
No Context: LuaJob executes outside conversations. Use User.get(userId) with ID from metadata.

Schedule Types

Cron (Specific Times)

schedule: {
  type: 'cron',
  expression: '0 9 * * *'  // Every day at 9 AM
  timezone?: 'America/New_York'  // Optional timezone
}
Common patterns:
  • '0 9 * * *' - Every day at 9 AM
  • '0 9 * * 1' - Every Monday at 9 AM
  • '0 0 1 * *' - First of every month at midnight
  • '*/15 * * * *' - Every 15 minutes

Interval (Regular Periods)

schedule: {
  type: 'interval',
  seconds: 3600  // Every hour
}
Common intervals:
  • 300 - Every 5 minutes
  • 3600 - Every hour
  • 86400 - Every day

Once (One-time)

schedule: {
  type: 'once',
  executeAt: new Date('2025-12-25T09:00:00Z')
}
Use for:
  • Specific future date/time
  • User-requested reminders
  • Follow-up messages

Example Use Cases

Daily Reports

Send sales summaries, analytics, or metrics every day

Cleanup Tasks

Delete old data, archive records, maintain database

User Reminders

Remind users about appointments, tasks, or deadlines

Monitoring

Check system health, API status, or thresholds

Follow-ups

Send follow-up messages after support tickets

Notifications

Proactive updates about orders, shipments, or events

Adding Jobs to Your Agent

Pre-defined jobs are added to your LuaAgent:
import { LuaAgent } from 'lua-cli';
import dailyReport from './jobs/daily-report';
import weeklyCleanup from './jobs/weekly-cleanup';

export const agent = new LuaAgent({
  name: "my-agent",
  persona: "...",
  skills: [...],
  
  // Add scheduled jobs
  jobs: [
    dailyReport,
    weeklyCleanup
  ]
});
Dynamic jobs are created from within tools using the Jobs API.

Testing Jobs

lua test
# Select: Job → daily-report
# Job executes immediately for testing

Next Steps