Pocketbook No. 3 — AI Agents in Practice

From Demo to Production: Agent Reliability & Evaluation

How to Close the Production Gap and Ship AI Agents You Can Trust

By Leandro Calado Ferreira · Free reading · English · December 2026

Introduction: Everyone Has a Demo

In 2026, everyone has a demo.

You have seen it a hundred times: an agent that writes a report, answers a question, calls a tool, and impresses a room. The demo takes ten minutes. The applause takes thirty seconds. The production system takes months — and most teams never get there.

That is the production gap. It is not a model problem. The models are good enough. It is a reliability problem: a demo has to work once, for one person, on clean data, while you are watching. A production agent has to work a thousand times, for people you do not know, on data you did not clean, at 3 a.m., without you watching.

Industry reports in 2026 tell the same story from different angles: most enterprises can build an agentic demo, fewer than one in five have one running reliably in production, and analysts warn that a large share of agentic projects will be cancelled — not because the models are weak, but because the cost is unclear, the business value is unclear, or the risk controls are weak.

This pocketbook is about closing that gap. It is short on purpose. You will not learn a new framework here. You will learn the four things that separate a demo from a production agent — a harness, evals, observability, and rollback — and how to put them together in thirty days.

By the end, you will have an evaluation set you can run every day, a harness that catches failures before your users do, logs you can actually read, and a rollback that takes minutes, not a weekend.

Want the full version of this story?

The harness in depth, the evaluation patterns, and the production controls are in the author’s full books on Amazon. This pocketbook is the taste. The books are the meal.

Browse Leandro Calado Ferreira’s books on Amazon →

Chapter 1. The Production Gap: Why Demos Die

A demo hides seven problems. Production exposes all seven, usually in the same week.

You already met them in the first pocketbook in this series, but they are worth naming again here, because this book is about fixing them, not just listing them:

  1. Nondeterminism. The same prompt, the same data, a different answer.
  2. Tool failures. An API returns a 500, a Databricks job times out, an MCP server goes down — and the agent invents an answer instead of saying it failed.
  3. Data drift. A column is renamed, a source stops updating, and the agent keeps answering as if nothing changed.
  4. Cost and latency. Ten calls in a demo become ten thousand in production, with no cache and no short-circuit.
  5. Security and permissions. A demo runs with your credentials. Production runs with someone else’s data.
  6. No observability. When a prototype fails, you are sitting next to it. When a production agent fails, you get a screenshot and a vague “it was wrong yesterday.”
  7. No rollback. A bad prompt goes live to everyone at once, and there is no way back.

None of these is a model problem. All seven are systems problems. That is good news: systems problems have systems answers, and they are boring, repeatable, and cheap compared with a cancelled project.

The test for this chapter: take one agent you already built and run it ten times on the same input. If you get ten different answers, you do not have a reliability problem to fix later. You have a demo. Write down what changed between runs. That list is your production backlog.

Chapter 2. Reliability Is a System, Not a Model

The most common mistake in agent work is trying to fix reliability by changing the model.

A bigger model will not fix a missing timeout. A newer model will not fix a tool that fails silently. A better prompt will not fix data that changed yesterday and nobody noticed.

Reliability is a system, and a system has four parts. This book gives one chapter to each of the last three, and this chapter to the first — because the first is the one teams skip.

1. A harness. The small, boring machine that runs the agent the same way every time: plan, act, observe, correct, stop. No harness, no production. You met the shape in Pocketbook #1:

# run_agent.py — the shape, not the whole system
def run_agent(request, run_id):
    log_input(run_id, request)
    plan = plan_with_model(request)          # small model, cheap, fast
    result = execute_tools(plan, timeout=30) # retries, backoff, clear failures
    score = evaluate(result, request)        # did it answer, cite, and stay in scope?
    log_output(run_id, result, score)
    if score < 0.8:
        return escalate_to_human(run_id, result)
    return result

2. Evals. A repeatable test that answers: “Is the agent still good at this?” — Chapter 4.

3. Observability. Logs, traces, and cost you can read — Chapter 5.

4. Rollback and guardrails. A way to fail safely and undo a bad change — Chapter 6.

If you have all four, you can change one thing — a prompt, a model, a tool — without breaking everything else, and you can prove the change helped. If you are missing even one, every change is a gamble.

A practical rule: do not add a second agent until the first one is boring. Boring means reliable. Boring means you know when it fails, you can reproduce the failure, and you can roll it back. Excitement is for demos. Boring is for production.

Chapter 3. The Harness: The Boring Machine That Keeps Agents Alive

A harness is not a framework. It is a contract: every run goes through the same steps, in the same order, with the same limits, and the same log at the end.

Here is a minimal harness in Python, expanded from the shape in Chapter 2. It is not a production system. It is the shape of one — and the shape is the point.

# harness.py — a minimal production harness
import time

def run_agent(request, run_id, max_attempts=3, timeout=30):
    log_input(run_id, request)
    start = time.time()
    for attempt in range(max_attempts):
        try:
            plan = plan_with_model(request)
            result = execute_tools(plan, timeout=timeout)
            score = evaluate(result, request)
            log_output(run_id, result, score, elapsed=time.time() - start)
            if score >= 0.8:
                return result
            # Low score is not a failure to hide — it is a signal to escalate.
            return escalate_to_human(run_id, result, score)
        except ToolError as e:
            log_error(run_id, e, attempt=attempt)
            if attempt == max_attempts - 1:
                return escalate_to_human(run_id, None, error=e)
            continue  # retry with backoff, not with a guess
    return escalate_to_human(run_id, None, error="max attempts reached")

Three details make this harness safe, and all three are easy to skip when you are excited:

A budget. Maximum attempts, maximum tool calls, maximum cost per run. Set it in code, not in a prompt. An agent without a budget is a loop that can run until your cloud bill notices.

A timeout and a retry policy. Every tool call gets a timeout, a retry with backoff, and a clear failure mode. A tool that fails should return “I could not do this, here is why” — never a confident guess.

An escalation rule. Decide in advance what “I don’t know” looks like. A missing table, a schema change, a permission error — these are things to stop on, and hand to a human with the evidence attached.

In practice, the harness lives where the work lives. On Databricks, it is a notebook or a job, with Unity Catalog as the governance layer. In n8n, it is a workflow you can see: trigger, agent node, Databricks job, checks, then promote or escalate. Through MCP, it is the server that owns the tools, the credentials, and the permissions — the agent only sees the tool, never the secret.

Try it: take the agent from Chapter 1 and wrap it in this harness. Run it ten times. Count how many runs escalated, and why. That count — not the demo — is your reliability score.

Chapter 4. Evals: How to Know If Your Agent Is Still Good

An eval is a small, repeatable test that answers one question: “Is the agent still good at this?”

Keep a small evaluation set — ten to twenty real examples, with the right answer attached. Run it every day, or every time you change a prompt, a model, or a tool. If the score drops, stop and look. Do not ship a prompt change because it “felt better in the demo.”

A useful eval for an agent is not “did it sound smart?” It is three concrete checks:

  1. Did it answer? Not a refusal, not a hallucinated guess, not an empty result.
  2. Did it cite its source? Which table, which document, which tool call produced this answer? If it cannot cite its source, it is guessing.
  3. Did it stay in scope? Did it do what was asked, and nothing it was not asked to do?

Here is the shape of an eval, in Python. It is deliberately small — small is what makes it run every day.

# evals.py — a small, daily eval set
EVALS = [
    {"input": "Summarize last week's sales from sales_curated.",
     "expected_table": "sales_curated",
     "must_cite": True},
    {"input": "List customers with no orders in 30 days.",
     "expected_table": "customers",
     "must_cite": True},
    # Add 8 to 18 more real examples, with the right answer attached.
]

def run_evals(agent):
    passed = 0
    for case in EVALS:
        result = agent.run(case["input"])
        ok = (
            result.answered
            and result.cited_table == case["expected_table"]
            and result.in_scope
        )
        log_eval(case["input"], result, ok)
        passed += ok
    return passed / len(EVALS)

Run this set on a schedule — every morning, or on every pull request that touches a prompt. Keep the history. A score that drifts down slowly is more dangerous than a score that crashes, because nobody notices a slow drift until a user does.

Three eval habits that actually work:

If you cannot tick the eval box, you do not have a production agent. You have a very good demo. That is fine — as long as you know which one it is.

Chapter 5. Observability: Logs, Traces, and Cost You Can Actually Read

When a prototype fails, you are sitting next to it. When a production agent fails, you get a screenshot from a user and a vague “it was wrong yesterday.”

Observability is the difference. It is not a dashboard. It is three logs for every run, and the discipline to read them.

1. The inputs. What was asked, by whom, and when? Log the request, the user, and the context the agent was given. Without the input, you cannot reproduce the failure.

2. The tool calls and their results. Which tools ran, in which order, what they returned, and how long they took? If you cannot trace a bad answer back to a bad tool call or a bad retrieval, you will fix the wrong thing.

3. The final answer, with its evaluation score. What did the agent say, what did it cite, and how did it score on your eval? Log the score, not just the text. A text log tells you what happened. A scored log tells you whether it is getting worse.

# observability.py — three logs, every run
def log_run(run_id, request, tool_calls, result, score, cost_usd, elapsed_s):
    record = {
        "run_id": run_id,
        "input": request,
        "tool_calls": [{"tool": t.name, "ok": t.ok, "ms": t.ms} for t in tool_calls],
        "answer": result.text,
        "cited": result.cited_table,
        "score": score,
        "cost_usd": cost_usd,
        "elapsed_s": elapsed_s,
    }
    write_log(record)  # Databricks table, file, or your logging system — pick one and keep it

Cost is observability too. Log tokens, time, and cost per run. An agent that makes five large-model calls per request, with no cache and no short-circuit, becomes a bill before it becomes a product. Use a smaller model for classification and routing. Cache repeated lookups. Only call the large model when the decision actually needs it.

A practical routine: every morning, read three things — the overnight eval score, the five most expensive runs, and the five lowest-scored runs. That is ten minutes. It will tell you more about your agent than any dashboard, because it tells you what is getting worse, what is getting expensive, and what your users are already noticing.

In Databricks, Unity Catalog gives you lineage for free, if you use it: which table, which run, which prompt version produced this answer. Use it. When a user asks “why did the agent say that yesterday?”, lineage is the only honest answer.

Chapter 6. Rollback and Guardrails: Failing Safely

A prototype can be restarted. A production agent cannot be un-shipped. A bad prompt, a bad model version, or a bad tool change goes live to everyone at once — unless you built a way back.

Rollback is not a feature you add at the end. It is a design decision you make at the start, and it has three parts.

1. Version everything. Prompts in GitHub, models pinned, tools versioned, deployments through your normal CI. If you cannot name the exact prompt version that produced yesterday’s answer, you cannot roll it back. Put the prompt in a file, give it a version, and deploy it like code — because it is code.

2. Guardrails around writes. An agent may propose anything. It may apply only what is reversible, tested, and logged. Start with read-only tools. Add a write tool only when you can name the exact check that runs before the write, and the exact rollback if it goes wrong. Least privilege, one identity per agent, and guardrails around tools that write, send, or delete. Log who asked for what, and what the agent actually did.

3. A rollback that takes minutes. A deployment through AWS Lambda or your normal CI, with the previous version one click away. A prompt change that can be reverted in minutes is an experiment. A prompt change that takes a weekend to revert is a risk.

# rollback.py — the shape of a safe deploy
# Deploy v12 of the prompt. Keep v11 live as the fallback.
# If the eval score drops below 0.8 after deploy, revert to v11 automatically.

def deploy(prompt_version):
    run_evals(prompt_version)          # gate: no deploy without a passing eval
    set_live(prompt_version)           # one change, one version, one log line
    monitor(score_threshold=0.8)       # watch the first 100 runs
    # If score < 0.8: set_live(previous_version) — minutes, not a weekend

The checklist before any agent touches production:

If you cannot tick all six, you do not have a production agent. You have a very good demo. That is fine — as long as you know which one it is, and as long as you do not ship it as if it were production.

Chapter 7. The 30-Day Playbook: From Demo to a Boring, Reliable Agent

You do not need a platform team to close the production gap. You need thirty days, one agent, and the discipline to stop at each gate.

Days 1–7: Measure the gap. Pick the agent that matters most — the one a human babysits, or the one users already complain about. Do not change anything yet. Just measure it: run your eval set, log the score, count the escalations, and write down the cost per run. That baseline is your business case. Without it, every later change is a guess.

Days 8–14: Build the harness, read-only. Wrap the agent in the harness from Chapter 3, with read-only MCP tools. Let it triage failures and propose fixes. Let it write tests and documentation. Do not let it write to production. Measure again: how many triages were right? How much time did they save? If the eval score holds, keep going. If it drops, you just learned something cheap.

Days 15–21: Add evals and observability. Add the eval set from Chapter 4 and the three logs from Chapter 5. Run the evals every morning. Read the five most expensive and five lowest-scored runs. Fix the one thing that keeps breaking — the contract, the eval, the cost — before you add anything new.

Days 22–30: Add one safe write, and a rollback. Pick one reversible, tested write — a staging table, a sandbox run, a draft report. Add the checks from Chapter 6. Deploy it with a versioned prompt and a tested rollback. Run it for a week. If the eval score holds and the cost is sane, keep it. If not, roll it back and write down why.

At the end of thirty days you will have one of two honest outcomes, and both are wins: a small agent that works, with the evidence to prove it — or a clear, written reason why this particular agent is not ready yet, and what would make it ready. Both beat a demo that impressed a room and died the following Monday.

Boring is the goal. Boring means reliable. Boring means you know when it fails, you can reproduce the failure, and you can roll it back. Build that, and then build the next one.

This pocketbook was the taste. The full books go deeper, with the harness, the evaluation, and the production controls in full.

Start here, in the author’s catalogue on Amazon:

If you ran the eval in Chapter 4, read the logs in Chapter 5, or tested the rollback in Chapter 6, you already did the hard part. The next step is not a bigger model. It is a smaller, better-guarded loop — run every day, logged, evaluated, and boring enough to trust.

Build that. Then build the next one.

More free pocketbooks in this series:

Keep reading — the full books are on Amazon.

Browse all books by Leandro Calado Ferreira on Amazon →

Also free on this site: Harness Engineering for AI Coding Agents