Scheduling & Automation.

Agents can run autonomously on a schedule or in response to events — no human trigger required.

Scheduled tasks

Create tasks in the scheduled_tasks table with a scheduledFor timestamp and payload. The Cloudflare Queue consumer (processTaskBatch) picks them up and executes them. Tasks support retry logic with retryCount and lastError fields.

Queue architecture

The backend uses Cloudflare Queues (TASK_QUEUE binding) for async job processing. The queue consumer is exported as the queue handler in the Worker. Jobs are also tracked in the jobs table with status (queued/running/completed/failed), result, and error fields.

Durable Objects for sessions

Real-time agent sessions use the AgentSession Durable Object (AGENT_SESSION binding). This maintains stateful conversation context across streaming requests, enabling long-running agent tasks that survive network interruptions.

Common automation patterns

Daily briefings: agent wakes at 8am, reads NOW.md and RECENT.md, pulls calendar and news, sends a summary. Lead follow-up: agent checks agent_contacts for leads with lastContactedAt > 3 days, drafts and sends follow-up emails. Weekly reports: agent queries dashboard metrics, generates a business summary, emails it to the team.