Skip to content
Esc
↑↓navigate↵open⌘Jpreview
Start
On this page

Scheduled Tasks

Scheduled tasks let agents run recurring work such as dependency updates, report generation, and health checks without a human prompt.

Scheduling options

  • Cloudflare Workers cron triggers - run a lightweight scheduler that starts an agent session.
  • Durable Object alarms - persist the next run time and resume reliably after restarts.
  • System cron - run a local script with cron on a server or container.
  • Workflow schedulers - use Kubernetes CronJobs, AWS EventBridge, or GitHub Actions scheduled workflows.

Cron trigger example

Run recurring checks from the scheduler your stack already uses, then keep the prompt narrow enough for predictable output.

export default {
  async scheduled(controller, env, ctx) {
    ctx.waitUntil(env.AUTOHAND.run({
      cwd: '/app',
      prompt: 'Find stale issues and draft follow-up comments.'
    }));
  }
};
import { AutohandSDK } from '@autohandai/agent-sdk';

export default {
  async scheduled(controller: ScheduledController, env: Env, ctx: ExecutionContext) {
    const sdk = new AutohandSDK({ cwd: '/app', apiKey: env.AUTOHAND_KEY });
    ctx.waitUntil(sdk.run('Find stale issues and draft follow-up comments.'));
  }
};
import asyncio
from autohand_sdk import AutohandSDK

async def hourly():
    async with AutohandSDK(cwd="/app") as sdk:
        await sdk.run("Find stale issues and draft follow-up comments.")

if __name__ == "__main__":
    asyncio.run(hourly())
func runHourly(ctx context.Context) error {
  sdk := autohand.NewClient(autohand.Config{Cwd: "/app"})
  _, err := sdk.Run(ctx, "Find stale issues and draft follow-up comments.")
  return err
}
@Scheduled(cron = "0 0 * * * *")
void runHourlyReview() {
  var sdk = AutohandClient.builder().cwd("/app").build();
  sdk.run("Find stale issues and draft follow-up comments.");
}
let timer = AsyncTimerSequence(interval: .seconds(3600))

for await _ in timer {
    let sdk = AutohandClient(cwd: "/app")
    _ = try await sdk.run("Find stale issues and draft follow-up comments.")
}

Durable scheduling

For tasks that must not run twice or must resume after a crash, store state in a Durable Object. Set an alarm for the next execution time and confirm completion before scheduling the next run.

Best practices

  • Use short timeouts for scheduled agents to avoid runaway costs.
  • Write output to durable storage, not stdout, so you can inspect results later.
  • Track the last run timestamp and avoid overlapping executions.
  • Alert on repeated failures with a separate hook.

Last updated on

Was this helpful?

Send Feedback

Help us improve this documentation page. Your feedback is valuable.

We'll only contact you if we need clarification