← Resources
guide·
Mar 15, 2026·12 min

The Complete Guide to Scheduling Tasks for AI Agents

By Govind Kavaturi

Constellation forming a clock face representing agent task scheduling

If you are building AI agents that need to do things on a schedule — poll an API every hour, send a follow-up email tomorrow, retry a failed task in five minutes — you need a scheduling layer. This guide covers everything: why agents need scheduling, what the options are, and how to implement reliable task scheduling with CueAPI.

Why Do AI Agents Need Scheduling?

AI agents are not just chatbots. Modern agents interact with external systems, manage long-running workflows, and coordinate with other agents. Many of these interactions are time-dependent:

  • Polling external APIs: Check for new data every 15 minutes
  • Sending follow-ups: Email a user 24 hours after signup
  • Retry logic: Retry a failed API call with exponential backoff
  • Batch processing: Run a data pipeline every night at midnight
  • Health checks: Verify upstream services every 5 minutes
  • Multi-agent coordination: Agent A triggers Agent B after completing a step

Without a scheduling layer, agents resort to setTimeout, sleep loops, or cron jobs bolted onto a server. These approaches break in production.

The Problem with DIY Scheduling

Cron Jobs

Cron is the most common scheduling tool. It works — until it does not.

  • Single point of failure: Cron runs on one server. If that server restarts, scheduled tasks disappear.
  • No retry logic: If a cron job fails, it does not retry. You find out when someone notices the data is stale.
  • No execution history: Cron does not track whether a job ran, succeeded, or failed.
  • No multi-tenancy: Every agent shares the same crontab. Isolation requires manual orchestration.
  • Deployment complexity: Adding or removing cron jobs requires SSH access and server restarts.

In-Process Timers

Using setTimeout, setInterval, or Python's asyncio.sleep inside your agent process:

  • Lost on restart: When the process restarts, all pending timers vanish.
  • Memory leaks: Long-running timers accumulate and consume memory.
  • No persistence: If the agent crashes, scheduled work is lost.
  • Scaling issues: Running multiple instances means duplicate firings or missed tasks.

Message Queues with Delayed Delivery

Some teams use RabbitMQ or SQS with delayed messages:

  • Maximum delay limits: SQS caps delay at 15 minutes. RabbitMQ's delay plugin has similar constraints.
  • No cron support: Recurring schedules require external scheduling to enqueue messages.
  • Operational overhead: Running and maintaining a message broker is a significant burden.

What Is a Scheduling API?

A scheduling API is a managed service that handles time-based task execution. You register tasks via API calls, and the service fires them at the right time. The key properties:

  1. Persistence: Tasks survive server restarts and deployments.
  2. Reliability: Built-in retries ensure tasks are delivered even if the first attempt fails.
  3. Observability: Every execution is logged with timestamps, status, and outcome.
  4. Multi-tenancy: Each user or agent gets isolated tasks and usage tracking.
  5. API-first: No SSH, no crontab files, no server configuration. Just HTTP calls.

How CueAPI Works

CueAPI is a scheduling API designed specifically for AI agents. Here is how the core flow works:

Step 1: Create a Cue

A cue is a scheduled task. You create one by calling the CueAPI endpoint with a schedule and a callback:

curl -X POST https://api.cueapi.ai/v1/cues \
  -H "Authorization: Bearer cue_sk_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "hourly-data-sync",
    "schedule": {
      "type": "recurring",
      "cron": "0 * * * *"
    },
    "callback": {
      "url": "https://your-agent.com/webhook"
    },
    "payload": {
      "action": "sync_data",
      "source": "salesforce"
    }
  }'

This creates a cue that fires every hour. When it fires, CueAPI POSTs the payload to your callback URL.

Step 2: Receive the Webhook

When a cue fires, CueAPI creates an execution and delivers it:

{
  "execution_id": "exec_abc123",
  "cue_id": "cue_xyz789",
  "cue_name": "hourly-data-sync",
  "payload": {
    "action": "sync_data",
    "source": "salesforce"
  },
  "scheduled_for": "2026-03-15T14:00:00Z",
  "attempt": 1
}

Your agent processes the payload and reports the outcome.

Step 3: Report the Outcome

After processing, report success or failure back to CueAPI:

curl -X POST https://api.cueapi.ai/v1/executions/exec_abc123/outcome \
  -H "Authorization: Bearer cue_sk_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "success",
    "output": {"records_synced": 142}
  }'

CueAPI logs the outcome. If the webhook delivery fails, CueAPI retries automatically.

Schedule Types

CueAPI supports two schedule types:

Recurring Schedules (Cron)

Standard 5-field cron expressions:

ExpressionMeaning
0 Every hour
/15 *Every 15 minutes
0 9 1-5Weekdays at 9 AM
0 0 1 First of every month
30 2 *Daily at 2:30 AM

One-Time Schedules

Fire once at a specific time:

{
  "schedule": {
    "type": "once",
    "run_at": "2026-03-20T15:00:00Z"
  }
}

Perfect for delayed tasks: "send a reminder in 24 hours" or "retry this in 5 minutes."

Delivery Methods

CueAPI offers two ways to deliver executions:

Webhook Transport

CueAPI POSTs to your callback URL. Best for:

  • Agents with a public HTTP endpoint
  • Serverless functions (AWS Lambda, Cloudflare Workers)
  • Microservices behind a load balancer

Worker Transport

Your agent polls CueAPI for available work. Best for:

  • Agents behind firewalls without public endpoints
  • Long-running processes that pull tasks from a queue
  • Environments where inbound webhooks are not possible
from cueapi_worker import CueWorker

worker = CueWorker(api_key="cue_sk_your_key")

@worker.handler
def handle_task(execution):
    # Process the execution payload
    result = sync_data(execution.payload)
    return {"status": "success", "output": result}

worker.start()

Retry and Failure Handling

CueAPI retries failed webhook deliveries automatically:

  1. First retry: 1 minute after failure
  2. Second retry: 5 minutes after first retry
  3. Third retry: 15 minutes after second retry

If all retries fail, the execution is marked as failed and a failure notification email is sent to the account owner.

You can customize retry behavior per cue:

{
  "retry": {
    "max_attempts": 5,
    "backoff_minutes": [1, 5, 15, 60, 360]
  }
}

Security

CueAPI provides multiple security layers:

  • API key authentication: Every request requires a valid Authorization: Bearer header.
  • Webhook secrets: CueAPI signs webhook payloads with HMAC-SHA256. Your agent verifies the signature to ensure the webhook came from CueAPI.
  • Key rotation alerts: When an API key is regenerated, CueAPI sends an email notification and returns a key_rotated error code for 24 hours on the old key.
  • Rate limiting: Per-user rate limits prevent abuse. Headers include X-RateLimit-Remaining and X-RateLimit-Reset.

Monitoring and Observability

Every execution is tracked with:

  • Status: pendingdeliveringdelivered or failed
  • Timestamps: scheduled_for, started_at, completed_at
  • Attempt count: How many delivery attempts were made
  • Outcome: The result reported by your agent (success, failure, error)
  • Output data: Any JSON output your agent returns

Query execution history via the API:

curl https://api.cueapi.ai/v1/cues/cue_xyz789 \
  -H "Authorization: Bearer cue_sk_your_key"

Common Patterns

Pattern 1: Delayed Follow-Up

Schedule a one-time cue to fire 24 hours from now:

curl -X POST https://api.cueapi.ai/v1/cues \
  -H "Authorization: Bearer cue_sk_your_key" \
  -d '{
    "name": "follow-up-user-123",
    "schedule": {"type": "once", "run_at": "2026-03-16T14:00:00Z"},
    "callback": {"url": "https://agent.example.com/follow-up"},
    "payload": {"user_id": "123", "action": "send_follow_up"}
  }'

Pattern 2: Health Check Monitor

Ping an endpoint every 5 minutes and alert on failure:

curl -X POST https://api.cueapi.ai/v1/cues \
  -H "Authorization: Bearer cue_sk_your_key" \
  -d '{
    "name": "health-check-prod",
    "schedule": {"type": "recurring", "cron": "*/5 * * * *"},
    "callback": {"url": "https://agent.example.com/health-check"},
    "payload": {"target": "https://api.example.com/health"}
  }'

Pattern 3: Multi-Agent Pipeline

Agent A schedules Agent B to run after processing:

import httpx
from datetime import datetime, timedelta, timezone

# After Agent A finishes processing
next_run = datetime.now(timezone.utc) + timedelta(minutes=5)

httpx.post("https://api.cueapi.ai/v1/cues", headers={
    "Authorization": "Bearer cue_sk_your_key"
}, json={
    "name": f"agent-b-run-{next_run.isoformat()}",
    "schedule": {"type": "once", "run_at": next_run.isoformat()},
    "callback": {"url": "https://agent-b.example.com/process"},
    "payload": {"source": "agent-a", "batch_id": "batch_456"}
})

Getting Started

  1. Sign up at cueapi.ai and get your API key
  2. Install the CLI: pip install cueapi
  3. Create your first cue: Use the API or CLI to register a scheduled task
  4. Set up your webhook endpoint or install the worker package: pip install cueapi-worker
  5. Monitor executions via the dashboard or API

Full API documentation is available at docs.cueapi.ai.

Summary

Scheduling is infrastructure that AI agents should not have to build themselves. CueAPI provides a managed, reliable, API-first scheduling layer that handles cron schedules, one-time tasks, retries, webhook delivery, worker transport, and execution tracking. Replace your cron jobs, remove your timer hacks, and let your agents focus on what they do best.

Get started

pip install cueapi
Get API Key →

Related Articles