Section650

Writing

TopicAI
Reading8 min

What It Takes to Make an AI System Reliable

Where prompts, context, tools, harnesses, loops, graphs, evaluation and memory fit, using an illustrative coding agent and a sorting bug.

By Ka Lun Chan · Cloud & AI · AI / Architecture / Engineering judgment

What makes an AI system reliable?

An AI system is reliable when it does the intended job repeatedly, inside limits you set, and you can show that it did. The model is one part of that. The rest is engineering around it: a clear task, the right information, well-designed actions, a runtime that enforces limits, a rule for when to stop, an explicit path through the work, a way to measure the result, and a decision about what to remember.

Production readiness for AI agents covers retries, idempotency, evaluation, cost and approvals. This series uses an illustrative sorting bug to explain which design decision addresses each type of failure.

These terms overlap. They are useful as names for different failure modes, and the series uses them as a diagnostic vocabulary.

One agent, one sorting bug

Every article in the series follows the same illustrative scenario, so the boundaries between the parts are easier to see. A ticket says that clicking the Quantity column on an Orders page sorts the values as 1, 10, 2. A coding agent can read the repository, edit files, run the tests and open a pull request. It is asked to fix the bug.

The bug is ordinary, which is the point. Text sorts character by character, so “10” comes before “2”. JavaScript’s default Array.prototype.sort() does exactly that: MDN documents that it converts elements to strings and compares UTF-16 code units unless you pass a compare function. In this scenario the table sorts the formatted text it displays, so a quantity shown as “1,200” is also text.

A single model call could suggest a plausible fix. Making an agent fix it reliably, every time a ticket like this arrives, involves the whole list of decisions below.

What each discipline decides

A tool defines an operation. The harness governs its execution. A loop decides whether to try again. A graph decides which step runs next. Evaluation measures the result. Memory carries selected information into future runs. Prompts and context determine what the model is asked and what it sees.

Fig. 736-1 Eight names for parts of the work, and the decision each one makes on the same bug
PartThe question it answersIn the sorting bug
Prompt engineeringWhat is the task, and what does a good answer look like?The ticket becomes a task with constraints, expected orderings and a report format.
Context engineeringWhat does the model see for this task?The sort helper, the table, the formatter, the failing case and the test file. Not the whole repository.
Tool engineeringWhat actions can it take, and what comes back?Search, read, edit and run tests, each with a narrow schema and errors the agent can act on.
Harness engineeringWhat does the runtime allow and record?A sandboxed worktree, no push to main, a time limit, approval before a pull request, a log of every call.
Loop engineeringIs it done, should it try again, or should a person take over?The first fix passes a unit test and fails in the table. One more attempt, then a handoff.
Graph engineeringWhich step runs next?Reproduce first; if it won’t reproduce, ask. After the fix, run checks in parallel and wait for approval.
Evaluation engineeringDid the system achieve the result?Sort through the real table, including 1,200 and blanks, and keep those cases as regression tests.
Memory engineeringWhat carries into the next run?“Sort on raw values, not formatted text” is kept. “The API sends strings” was a guess and expires.
The boundaries overlap. A retry limit could live in the loop or the harness, and a permission could live in a tool or the runtime. The names matter less than knowing which decision you are making.

Read down the right-hand column and you get the whole workflow for one bug. Most of it has nothing to do with how clever the model is. The model writes the fix. Everything else decides whether the fix is the right one, whether the agent was allowed to make it, and whether anyone can trust the result.

Where RAG, guardrails and human review fit

Many familiar terms map onto more than one of these parts, which is part of why AI conversations get muddled.

  • Retrieval and RAG are context engineering. They decide which documents, code or records reach the model. Retrieval quality, stale sources and irrelevant results are context problems, whatever the retrieval technology.
  • Guardrails are spread across tools, the harness and evaluation. A tool that can only edit files inside the repository is a guardrail. So is a runtime that blocks pushes to main, and so is a check that rejects output before it ships. OWASP’s guidance on excessive agency makes the same split: limit what extensions can do, require approval for high-impact actions, and enforce authorization in downstream systems rather than trusting the model.
  • Workflows and orchestration are loops and graphs. A loop repeats a step until it passes or gives up. A graph decides the order of steps, the branches and what runs in parallel.
  • Human review shows up three times: as an approval the harness enforces before a risky action, as the handoff a loop makes when it runs out of attempts, and as a grader in evaluation when automated checks can’t judge the result.
  • Observability belongs to the harness, which records what happened during a run, and to evaluation, which turns those records into a judgment about quality.
  • Safety runs through tools and the harness. A prompt can ask a model to be careful. Only the runtime can make a destructive action impossible.

How do you decide which problem to solve first?

Start with evaluation, even a rough version: write down what a correct result looks like and check a few real runs against it. Then read the transcripts of the runs that failed, find where they went wrong, and fix the cheapest part that explains the failure. Add loops, graphs and memory only when a specific failure calls for them.

Without a definition of success, fixing one sort case can break another. Anthropic’s evaluation guide recommends starting with a small set of tasks drawn from real failures.

Read the transcript after a failure. A green process status establishes that the process exited. Inspect what the agent saw, what it called and what the checks measured.

Fig. 736-2 Where to look first when a run goes wrong
What you see in the transcriptLook atUsual cause
The agent solved a different problem than the one you meantPromptThe task, constraints or definition of done are unclear
It reasoned well about the wrong code, or quoted an outdated docContextIt saw too little, too much or the wrong version
It called the right tool with bad arguments, or misread the resultToolsThe schema invites mistakes or the response hides the cause
It did something it should never have been able to doHarnessThe runtime trusted the model with a decision it should enforce itself
It declared success early, or kept retrying the same ideaLoopCompletion criteria, attempt limits or the handoff are missing
It ran steps in the wrong order or skipped an approvalGraphThe path is implicit, so the model chooses it
Nobody can say whether it got better or worse after a changeEvaluationThere are no expected outcomes or regression cases
It repeats a mistake you corrected, or trusts last week’s guessMemoryNothing persists, or the wrong thing persists

Start with a clearer task or better inputs before adding workflow branches or shared state. Anthropic’s guidance on building agents recommends starting with the simplest solution. FedPath is an example of using transparent rules when the user needs to understand a score.

Two exceptions to “cheapest first”. Anything that can cause irreversible damage gets a harness boundary before it runs unattended, whatever else is wrong. And anything you plan to change repeatedly needs evaluation before the second change, or you are tuning by feel.

The series

Each article stands on its own and takes one decision in the sorting-bug workflow.

  1. Prompt Engineering: Make the Task Clear. Turning the ticket into a task with constraints, examples and an expected report, and telling a prompt problem from an input problem.
  2. Context Engineering: Give the Model What It Needs. Which code, ticket details and test results the agent sees, and what to leave out.
  3. Tool Engineering: Design the Actions an Agent Can Take. Schemas, errors, permissions and retry-safe operations, and how a test result shapes the next move.
  4. Harness Engineering: Control What Happens During a Run. What the runtime enforces even when the model makes a bad decision.
  5. Loop Engineering: Decide How an Agent Knows It’s Done. What happens when the first fix fails verification.
  6. Graph Engineering: When an AI Workflow Needs Branches. When a straight line is enough and what a graph costs.
  7. Evaluation Engineering: Prove the System Did the Job. Verifying numeric ordering through the real entry point and catching the regression later.
  8. Memory Engineering: Decide What an Agent Should Remember. Durable project facts, temporary hypotheses, and when memory should expire.

Sources

Checked in November against the primary documentation and engineering writeups below. The sorting-bug scenario is illustrative, and the opinions and the decision order are mine.

Short answers

Are prompt, context, tool, harness, loop, graph, evaluation and memory engineering a standard stack?

No. They are overlapping names for parts of the work, and only some of them are widely used. They are useful because each one points at a different kind of failure. You don’t need all of them, and there is no required order.

Where do RAG and guardrails fit?

Retrieval-augmented generation is one way to do context engineering: it decides what information the model sees. Guardrails are spread across several places: tool design limits what an action can do, the harness enforces permissions and approvals during a run, and evaluation checks the output before anyone relies on it.

Where to start

Pick five real tasks your agent got wrong, write down what the right result would have been, and read each transcript until you can name the part that failed.

That list will tell you more about which article to read next than any framework will. If the problem is that you can’t tell whether the agent is right, start with evaluation engineering.

Start with part one Discuss what you’re building