Build & Deploy AI Agents

Lesson 4

Module 4: Human-in-the-Loop & Scheduling

Ask before posting, and re-review on a timer.

Module 4 turns REVIEWBOT from reactive to deliberate: it asks before doing anything visible, and it can act on its own clock.

Approve before it posts

A tool can require human approval before it runs. REVIEWBOT’s postReview is marked with needsApproval, so before it comments on a real pull request it pauses and the chat shows an Approve / Reject prompt. Only an approval lets execute run and flip the review to posted. This is the gate you put in front of any action with side effects.

Schedule a recheck

Agents are proactive. this.schedule(delaySeconds, "recheckReview", reviewId) registers a callback to fire later, so REVIEWBOT can re-review a PR after a delay. Try “check this PR again in 30 seconds” and watch it re-run.

Why it is durable

Scheduling is backed by a Durable Object alarm and a SQL table. It survives hibernation and deploys, and burns no compute while waiting. getSchedules() and cancelSchedule() let you manage pending tasks. When the alarm fires, recheckReview re-runs the workflow and broadcasts status to the UI.

When you are ready, open the HITL & Scheduling exercise to build it.