Loop Engineering: Build Scheduled AI Agent Loops
Loop engineering is the shift from one-shot prompting to small scheduled programs that run an AI agent for you: schedule, pull context, decide, act, verify. Covers prompt vs loop, the 5-step anatomy, three ways to build one (Claude Code scheduled tasks, n8n, cron + agent), best practices, and a worked morning-sales example.
Loop engineering is the shift from asking AI one question at a time to building small, scheduled programs that run an AI agent for you on repeat. Instead of typing a prompt, getting an answer, and doing it all again tomorrow, you hand the agent an outcome once and let it pull context, decide what matters, and act, with guardrails. You still write prompts, they just live inside the loop now.
Prompt vs loop
- A prompt is one shot. You ask, it answers, you move on.
- A loop is a tiny scheduled program with agent intelligence inside. It wakes up on its own, gathers fresh data, reasons, takes actions through tools, checks itself, and records what it did so the next run has memory.
Anatomy of a loop (5 steps)
- Schedule the trigger. A timer wakes the loop on an interval (every morning, every hour). Use cron, an n8n schedule trigger, or a scheduled task runner.
- Load the outcome. Give it a specific goal, not 'be helpful'. For example: 'find my 10 highest-priority follow-ups and draft a next step for each.'
- Pull context. Fetch only the relevant data: CRM records, email threads, meeting transcripts, recent docs. Enough signal, not noise.
- Decide and act. The agent reasons, calls tools, gets results back, and iterates until it produces the output or hits a stop condition.
- Verify and record. Gates check the output for policy or hallucinated fields, risky actions route to you for approval, and the result is logged so the next run has state.
Three ways to build one
1. Claude Code scheduled tasks
Set up a scheduled task that runs a repeatable workflow, reads the relevant project or work context, and produces a structured plan or action list before it touches anything. Start with simple, transparent patterns and add complexity only once it is reliable.
2. n8n schedule trigger + AI agent node
Use an n8n schedule trigger to start the flow, chain nodes that fetch your CRM, email and transcript data, pass it into an AI agent node, then route the output through condition checks or a human-approval step before anything is sent or written back. This is the easiest no-code path.
3. Cron + an agent service
A cron job calls your agent endpoint on a schedule. Your service loads context, sends it to the model, executes only approved tools, and loops (prepare context, call model, run tool calls, feed results back) until the model returns a final answer. Most control, most setup.
Best practices that actually matter
- Define 'done' first. Tell the agent exactly what success looks like (draft 5 follow-ups, flag at-risk accounts, summarise action items).
- Feed it the right context, not all of it. Pull the most relevant fields so it has signal without drowning.
- Add guardrails. Validate inputs, restrict which tools it can use, and cap iterations so a loop can't run away.
- Keep a human in the loop for risky steps. Require approval before any external send, record change, or anything money or compliance related.
- Start small. One narrow workflow, one tool set, one success metric. Expand only after you can measure that it is reliable.
Worked example: a morning sales loop
- 7am: the scheduler fires.
- It fetches yesterday's CRM changes, email replies, and recent call transcripts.
- The agent is told: 'find the 10 highest-priority follow-ups and draft a concise next step for each.'
- It looks up account history and message templates, then returns the drafts.
- A rules check flags anything risky or invented.
- You approve, the approved emails send, everything is logged, and the next run picks up from there.
Why it matters
Prompting still works, but prompting alone is no longer the whole job. The leverage now is in wrapping good prompts inside loops that run on a schedule, gather their own context, and act. Learn to build one small loop and you stop babysitting a chat window and start handing over whole outcomes.
New guides land in your inbox first
One short email a week with the tools and prompts worth your time. Free, and you can leave any time.