Cron-based AI scheduling without loading a full app on every tick
Running an agent on a schedule should not mean cold-starting your entire stack every minute. A lightweight pattern for efficient, reliable agent cron.
Running an AI agent on a schedule sounds trivial until you watch the infrastructure bill. The naive approach — boot your full application, load every dependency, initialize the model client, run one tick, and shut down — means you pay a cold start and a full app load for what is often a thirty-second task. Multiply that by a per-minute schedule and the cost and latency dwarf the actual work.
We needed agents that wake on a schedule, do a small focused job, and go back to sleep, without dragging the entire product stack into memory on every tick.
The lightweight pattern
The core idea is to separate the scheduler from the application. The cron entry point does not import the app; it imports a single, narrow job module with the smallest possible dependency graph. That module receives a pre-built, least-privilege context — only the tools, credentials, and data access that one job needs — rather than the whole application container.
We keep the job modules deliberately thin. Each one is a pure function from a typed input to a typed result, with the model client created lazily and only if the job actually needs a model call. Many scheduled jobs turn out to need no model at all on most ticks — they check a condition and exit, which means they should cost almost nothing.
What this buys you
Cold-start time drops because you are no longer initializing the full framework, ORM, and middleware stack for a background tick. Cost drops in proportion. And reliability improves, because a narrow job module has far fewer ways to fail than a full application boot — and when it does fail, it fails in isolation instead of taking your web process down with it.
The broader lesson generalizes: an agent on a schedule is a batch job, not a web request. Treat it like one — minimal dependencies, least privilege, lazy initialization — and scheduling stops being something you pay for on every tick.