Skip to content

Schedules

A schedule triggers agent runs on a cron expression. Each trigger creates a task you can inspect. Set it and forget it — your agent runs automatically, creates a fresh session each time, and you can check results whenever.

Use cases: daily code reviews, weekly dependency audits, nightly test suite runs, periodic report generation.

Create a Schedule

typescript
const agent = client.agent({
    name: "build",
    config: { permission: "allow" },
});

const schedule = await agent.schedule({
    cron: "0 9 * * 1-5", // weekdays at 9am
    prompt: "Check /workspace for TODO comments. Write a summary to /workspace/todo-report.md.",
});
console.log(`Schedule created: ${schedule.id}`);

Cron Syntax

Standard five-field cron:

┌───────── minute (0-59)
│ ┌─────── hour (0-23)
│ │ ┌───── day of month (1-31)
│ │ │ ┌─── month (1-12)
│ │ │ │ ┌─ day of week (0-6, Sun=0)
│ │ │ │ │
* * * * *
ExpressionMeaning
0 9 * * 1-5Weekdays at 9:00 AM
0 */6 * * *Every 6 hours
30 2 * * 0Sundays at 2:30 AM
0 0 1 * *First day of each month at midnight

Trigger Manually

Don't wait for the cron — trigger a run right now and get a task handle:

typescript
const task = await schedule.trigger();
const result = await task.result({ timeoutMs: 120_000 });
console.log(`Status: ${result.status}`);
console.log(result.text);

Manage Schedules

typescript
// Pause (skip future triggers)
await schedule.pause();

// Resume
await schedule.resume();

// Update the cron or prompt
await schedule.update({
    cron: "0 9 * * *", // change to daily
    prompt: "Updated prompt here",
});

// Delete
await schedule.delete();

List All Schedules

typescript
const schedules = await client.listSchedules();
for (const s of schedules) {
    console.log(`${s.id} — cron: ${s.cron}, enabled: ${!!s.enabled}`);
}

Full Example

typescript
import { createClient } from "swarmlord";

const client = createClient({
    apiKey: process.env.SWARMLORD_API_KEY!,
});

const agent = client.agent({
    name: "build",
    config: { permission: "allow" },
});

// Create a weekday schedule
const schedule = await agent.schedule({
    cron: "0 9 * * 1-5",
    prompt:
        "Check /workspace for any TODO comments in source files. " +
        "Write a summary of findings to /workspace/todo-report.md.",
});
console.log(`Schedule created: ${schedule.id}`);

// Trigger it now
const task = await schedule.trigger();
const result = await task.result({ timeoutMs: 120_000 });
console.log(`Result: ${result.status}`);
console.log(result.text.slice(0, 300));

// Pause and resume
await schedule.pause();
console.log("Paused.");
await schedule.resume();
console.log("Resumed.");

// List all
const all = await client.listSchedules();
console.log(`Total schedules: ${all.length}`);

// Cleanup
await schedule.delete();
await client.session(task.id).end();

SDK released under the MIT License.