Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
What fundamentally distinguishes an "agent" from a single LLM call in a backend system?
💻 Code Challenge | +75 XP
Design an agent loop (as pseudocode) with a maximum iteration count, a restricted set of read-only allowed tools, and a requirement that any consequential action (like issuing a refund) triggers an explicit human approval step before executing.
A backend AI agent got stuck in a loop repeatedly retrying the same failed action, and because it wasn't idempotent, ended up issuing a customer refund three times. Reorder the steps to fix this properly.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Giving a backend AI agent unrestricted ability to take actions with no bound on iteration count or allowed tools
// Risky: no bounds at all
while (!taskComplete) { /* runs indefinitely, any tool, any action */ }
// Correct: explicit, essential bounds
const MAX_ITERATIONS = 10;
const ALLOWED_TOOLS = ["searchOrders"]; // read-only
// Consequential actions require explicit human approvalThe Solution //
An unbounded agent is a genuine operational risk — it could loop indefinitely, consuming unbounded cost and time, or take a consequential action (like a financial transaction) without appropriate human oversight. Explicit bounds — a maximum iteration count, a restricted tool set, required approval for consequential actions — are essential engineering controls.
The Error //
Implementing an agent-triggered action (like issuing a refund) without making it idempotent
// Wrong: an agent retry could issue this multiple times
async function processRefund(orderId) { await issueRefund(orderId); }
// Correct: safe even if the agent decides to retry
async function processRefund(orderId) {
if (await alreadyProcessed(orderId)) return;
await issueRefund(orderId);
}The Solution //
An agent's own reasoning process can independently decide to retry a step it believes failed, even outside any infrastructure-level retry logic — if the underlying action isn't idempotent, this can cause it to be executed multiple times, with real consequences for something like a financial transaction.