scheduler

The scheduler extension provides pull-style scheduling for hiring agents and invoking them on a schedule.

Installation

bun add @regent/scheduler

Basic Usage

import { createAgent } from '@regent/core';
import { a2a } from '@regent/a2a';
import { createSchedulerRuntime, createSchedulerWorker, createMemoryStore } from '@regent/scheduler';

const agent = await createAgent({
  name: 'my-agent',
  version: '1.0.0',
})
  .use(a2a())
  .build();

const scheduler = createSchedulerRuntime({
  runtime: agent,
  store: createMemoryStore(),
});

// Create a hire
const { hire, job } = await scheduler.createHire({
  agentCardUrl: 'https://example.com/agent',
  entrypointKey: 'process',
  schedule: { kind: 'interval', everyMs: 60000 },
  jobInput: { task: 'ping' },
});

// Start worker
const worker = createSchedulerWorker(scheduler, 5000);
worker.start();

API Reference

createSchedulerRuntime()

Creates a scheduler runtime for managing hires and jobs.

Requirements: Runtime must have A2A extension enabled via .use(a2a())

Options

SchedulerRuntime

Hires

A Hire represents an agreement to invoke an agent's entrypoint on a schedule.

Hire Type

Creating a Hire

Managing Hires

Jobs

A Job represents a single scheduled execution.

Job Type

Adding Jobs

Managing Jobs

Schedules

One-Time Schedule

Recurring Schedule

Worker

The worker polls for and executes due jobs.

createSchedulerWorker()

SchedulerWorker

Usage

Storage

Memory Store (Built-in)

Custom Store

Implement SchedulerStore for persistent storage:

Retry Logic

Failed jobs use exponential backoff:

Includes ±20% jitter to prevent thundering herd.

Lease Recovery

Recover stuck jobs after worker crashes:

Exports

Last updated