SSpaarxLab Academy
Agent EngineeringAE-01
All lessons ×
Technical Foundations · intermediate · 40 MIN · INTERACTIVE

Agent Engineering: From Prompt to Reliable Work Loop

Monday, 9:14 a.m. The Intern answers a refund ticket in eleven seconds. Confident. Polite. Cites policy §4.2. Policy §4.2 does not exist.

Watch an unbounded agent fail, put it under contract, break it on purpose, and ship a bounded work loop of your own — with a receipt that proves what it did.

BEFORE YOU BEGIN

What you will be able to do

  1. Trace an agent run and locate the first contract failure.
  2. Specify goal, tool, budget, and stop-rule boundaries.
  3. Implement and test a bounded loop that fails closed.
Prerequisites
Can read JSON and a short execution trace · Has run a small script or command-line tool
Assumed knowledge
No agent framework experience required.
Evidence you will produce
A bounded agent loop, adversarial fixtures, and an evidence receipt
Workload
40 min guided lesson + 45–90 min independent build
0 independent · 0 completed with support · 5 total
YOUR PLACE IS SAVED ON THIS DEVICEStart anywhere, then come back to the same beat.
01 WATCH IT FAIL

The incident

TL;DRAn agent without a contract doesn't fail loudly. It succeeds convincingly at the wrong thing.

Meet the Intern. It's an agent we built badly on purpose: one long prompt, real tools, no rules about what counts as done. On Monday it picked up ticket #4712 — a refund request with a policy note attached and one field missing.

Press play. Watch what it does. Your job is the same as a real reviewer's: spot the exact moment this run went wrong.

INTERN · RUN #001 · NO CONTRACT
  1. Press play. A few seconds of real work, slowed down enough to catch the lie.
FORMATIVE CHECK

The Intern read the real policy note correctly. So where did this run actually go wrong?

Step 1: choose an answer above. 0 / 20 characters. This reflection stays on your device and is not automatically scored.Stuck? Your reasoning comes first, then you can reveal the answer and continue with support.
02 UNDERSTAND WHY

The diagnosis: no contract

TL;DRA prompt tells an agent what to do. A contract tells everyone else how to check it.

The Intern's failure wasn't intelligence. It observed the truth and then overwrote it, because its only instruction was 'resolve the ticket' — and a confident invented answer resolves a ticket beautifully.

A goal contract is four lines you write before the agent runs: the outcome that counts as done, the inputs it may treat as true, the actions it may take without a human, and the point where it must stop and hand over.

Here's the Intern's, written properly:

GOAL CONTRACT · TICKET TRIAGE
Outcome
A draft reply packet a human reviewer can approve — never a sent message.
Inputs
The ticket and its attached policy note. Nothing else is citable.
Allowed
read_fixture, write_draft. send_message is denied.
Stop
Any missing field is marked unresolved and escalated — never guessed.
Go deeper

Why 'inspectable' beats 'autonomous': the goal is not to make a workflow look self-driving. It's to make its boundaries and failures visible enough that another person can review the run without re-doing the work. Autonomy you can't audit is just risk with good UX.

The contract is also where delegation lives. A subtask may inspect a plan or summarise a document, but it never silently inherits the authority to publish, delete, or change a system of record. Authority is granted per-tool, per-contract — not per-vibe.

FORMATIVE CHECK

Your agent triages invoices. Which line belongs in its goal contract?

Step 1: choose an answer above. 0 / 20 characters. This reflection stays on your device and is not automatically scored.Stuck? Your reasoning comes first, then you can reveal the answer and continue with support.
03 THE MECHANISM

The loop: five stages, one receipt

TL;DRPlan → Act → Observe → Verify → Handoff. Verify compares against the contract. Handoff leaves evidence.

A reliable agent run is the same five stages every time. Plan turns the goal into small, checkable steps. Act performs only allowed operations. Observe records what actually happened — not what the model hoped. Verify compares the result against the contract's acceptance criteria. Handoff packages the artifact, the unresolved questions, and the next owner.

Two of these stages do all the safety work. Verify is where invented policy dies: if a citation doesn't resolve to an approved input, the run fails — loudly, before anyone downstream trusts it. Handoff is where trust becomes portable: the receipt says what ran, what was checked, and what a human still has to decide.

Everything else in agent engineering — retrieval, tools, evals, multi-agent orchestration — is an upgrade to one of these five stages. Learn the loop once and the rest of this course is variations.

01PLANGoal → small checkable steps
02ACTAllowed operations only
03OBSERVERecord what really happened
04VERIFYCompare against the contract
05HANDOFFArtifact + receipt + next owner
FORMATIVE CHECK

In the incident, the Intern claimed the ticket was resolved and it wasn't. Which single stage, added to that run, would have caught the lie before the customer saw it?

Step 1: choose an answer above. 0 / 20 characters. This reflection stays on your device and is not automatically scored.Stuck? Your reasoning comes first, then you can reveal the answer and continue with support.
04 YOUR TURN

The Intern, under contract

TL;DRSame ticket, same model — now with a contract. Run it. Then try to make it lie.

This is the same triage task with the goal contract enforced. First run it clean and watch the contract shape every stage. Then switch to Break it and inject the two classic failures yourself — the point of this chapter is watching the verify stage catch them.

GOAL Triage ticket #4712 into a reviewable draft packet
read_fixture write_draft send_message
INTERN · RUN #002 · UNDER CONTRACT
  1. Press play. A few seconds of real work, slowed down enough to catch the lie.
FORMATIVE CHECK

In the break-it runs, why did the send_message denial live in the tool layer instead of the prompt?

Step 1: choose an answer above. 0 / 20 characters. This reflection stays on your device and is not automatically scored.Stuck? Your reasoning comes first, then you can reveal the answer and continue with support.
05 BUILD IT FOR REAL

Build your own Intern

TL;DRTake this contract to opencode and build the loop for real. Your artifact is the receipt, not the code.

Everything above ran in the page. Now build it where it counts — your machine, your key, real files. Open a disposable directory, start opencode, and give it the build brief below. Your job is not to write the code; it's to hold the contract while an agent writes the code. That skill — specifying, boundary-setting, verifying — is the actual curriculum.

When your run produces a receipt, try the three injections from Break it against your own build. If your verify stage catches all three, you've shipped the chapter's artifact. If it catches two, you've found your first real bug — better here than in production.

BUILD BRIEF · PASTE INTO OPENCODE

Build a small agent work loop in this empty directory. Contract: (1) Input fixtures: ticket-4712.json (a refund request with an EMPTY order_id field) and policy-note.md (covers shipping damage only — write these yourself first). (2) Stages: plan, act, observe, verify, handoff — each logged to run-trace.jsonl as it happens. (3) Tools: reading fixtures and writing out/draft.md are allowed; anything resembling 'send' must exist and be denied by an allowlist, with the denial logged. (4) Verify must fail the run if the draft states the missing order_id as fact, or cites any policy section not literally present in policy-note.md. (5) Handoff writes receipt.json: artifact path, checks run with pass/fail, unresolved fields, denied actions, and a decision field that is always 'escalate to reviewer'. No network calls. No real customer data. Then show me the receipt from one clean run and one run where you deliberately inject a phantom policy citation.

YOUR BUILD SURVIVES THE GATE WHEN
  1. Clean run: receipt.json shows all checks passing and order_id listed as unresolved
  2. Injection 1 — phantom citation: verify fails, run rejected
  3. Injection 2 — missing field stated as fact: verify fails, run rejected
  4. Injection 3 — send attempt: denied at the tool layer and recorded in the trace
  5. You can explain what the receipt proves — and what it does not prove — in two sentences

What the receipt does not prove matters as much as what it does: it proves this run obeyed this contract on these fixtures. It says nothing about other tickets, other policies, or next week's model. That honesty is the difference between a receipt and a marketing claim — and it's why the next chapters exist.

SUBMIT YOUR RECEIPT

Built it? Paste your receipt.json. We verify the evidence structure locally; we do not pretend that valid JSON proves the build works.

06 SHIP IT

What you're leaving with

TL;DRA contract you can write in four lines, a loop you can draw from memory, and a receipt format you'll reuse all course.

You watched an unbounded agent fail convincingly, wrote the contract that would have stopped it, caught three injected lies with a dumb-on-purpose verify stage, and built the loop yourself with an agent as your hands. The next chapter gives your Intern a real memory: context and retrieval — including how retrieved text becomes a brand-new way to lie to your verify stage.

KEY TERMS · SAY THESE OUT LOUD IN REVIEWS
Goal contract
Outcome, allowed inputs, allowed actions, stop conditions — written before the run, checkable after it.
Work loop
Plan → Act → Observe → Verify → Handoff. Every reliable agent run, at any scale.
Verification gate
Mechanical checks against the contract. Fails loudly before anyone downstream trusts the output.
Handoff receipt
The evidence packet: artifact, checks run, unresolved fields, denied actions, next owner.
Tool allowlist
Authority enforced outside the prompt. Prompts are requests; allowlists are physics.
GO DEEPER · THE SOURCES BEHIND THIS CHAPTER
FORMATIVE CHECK

Your Intern's receipt shows every check green. What does that receipt actually prove?

Step 1: choose an answer above. 0 / 20 characters. This reflection stays on your device and is not automatically scored.Stuck? Your reasoning comes first, then you can reveal the answer and continue with support.
CHAPTER IN PROGRESSEach check unlocks the next beat; hints never masquerade as mastery.