Discuss your project

Article

How to build an AI agent that survives production

How to build an AI agent that works in a business: pick one job, define the check, set permissions, and test failures. The model is not the difference.

By · Published · 6 min read

A demo agent is quick to build. Making it work in a business takes far longer. The difference is not the model. It is the operating system around the model.

This is the process I use, in the order that avoids the most common failures.

Discuss your project

From job to handoff
  1. Pick one job
  2. Define the check
  3. Give it context
  4. Constrain permissions
  5. Test the failure
  6. Hand it over

The demo trap

A demo shows an agent answering a question with a tool. It looks finished.

The demo skips the parts that decide whether the agent survives.

  • Where does the knowledge come from
  • What happens when the tool fails
  • Who approves an action
  • How do you know the output is correct
  • What stops the agent from doing something else

Those questions are not in the demo because the demo has no consequences.

Step 1: pick one job

One agent, one job, one output.

Not "AI for operations". One task: review a contract, qualify a lead, assemble a report, check a website.

The job should have a clear input, a clear output, and a person who can review the result.

If the job needs two outputs, it is two agents. If the job needs a judgment on every case, it is not an agent job yet.

Step 2: define the output and the check

Write the definition of done before you write the prompt.

What does a good output contain. What fields are required. What is the format. What is the acceptable error rate.

Then write the check. The check is deterministic. It compares the output to a source, a schema, or a rule. It does not ask the model whether the model did a good job.

Examples of checks:

  • Does the file exist in the right directory
  • Does the total match the source system
  • Does the contract flag every clause on the checklist
  • Does the page return a 200
  • Does the email have a named recipient and an approved template

The check is the product. The prompt is the interface.

Step 3: give it the context

An agent cannot use knowledge it does not have.

The context is not a folder of PDFs. It is the set of facts the agent is allowed to use, with an owner and a date.

For a contract agent, the context is the checklist, the clause library, the approved exceptions, and the client's rules.

For a coding agent, the context is the repository, the instructions, the test suite, and the conventions.

For a content agent, the context is the voice guide, the facts file, the approved examples, and the topics that are off limits.

If the context is wrong, the agent is confidently wrong. If the context is stale, the agent is confidently out of date.

Step 4: constrain the permissions

Give the agent the tools it needs, and no more.

A read tool cannot write. A write tool has a boundary. A send tool has an approval rule. A payment tool has a limit.

The permissions are not a technical detail. They are the risk model.

The most useful pattern is read-only by default, with named exceptions for the actions that need a write. The exception is reviewed and logged.

Step 5: add memory

Memory is what the agent knows across steps.

There are three kinds.

  1. Task memory. What happened in this run.
  2. Project memory. What the agent has learned about this client or process.
  3. System memory. The rules and corrections that apply to every run.

Task memory is temporary. Project memory is scoped. System memory is the one that improves the agent over time.

The system memory is where a correction becomes a rule. Without it, the agent makes the same mistake next week.

Step 6: test the failure

Test the normal case. Then test the failures.

  • A missing document.
  • A malformed input.
  • A system that is unavailable.
  • A permission that is denied.
  • A conflicting instruction.
  • A result that is wrong but plausible.

The agent should fail loudly, not silently. A silent failure produces work that looks finished and is in the wrong place.

The test should run again when the model, the data, or the rules change.

Step 7: hand it over

An agent without an owner is an orphan.

The handoff includes the documentation, the account ownership, the operating procedure, the failure path, and the name of the person who owns it.

The owner maintains the knowledge, reviews the failures, and decides what the agent may do next.

If nobody owns it, the agent will drift. The drift is slow, and it is invisible until something breaks.

The 5 of 20 story

I connected an open-source coding agent to a local model. The first test passed 5 of 20 repository tasks.

The easy answer was to blame the model. Instead, I checked the environment.

The agent was working in the wrong directory.

I fixed the directory, pinned it, added repository instructions, added deterministic validation checks, and forced the agent to keep working until every test passed.

The same model passed 20 of 20.

That is the lesson. The model was not the problem. The operating system was.

What it costs

The build cost is the time to define the job, connect the tools, write the rules, and test the failures.

The run cost is the model usage. A routed system can be surprisingly cheap. One measured 30-day window of my system, from June 9 to July 8, 2026, processed 9.69 billion tokens for $210 in total.

The number that matters is the cost per accepted task. A cheap agent that needs rework is expensive.

What goes in the repository instructions

A coding agent is only as good as the instructions it receives. The same is true for any agent that works inside a system.

The instructions should cover six things.

  1. Where the work lives. The directory, the repository, the folder, the database.
  2. What the files are. The structure and the naming.
  3. How to run the tests. The command, the environment, the expected output.
  4. What not to touch. The files, the systems, the data that are off limits.
  5. How to report a failure. The format, the owner, the escalation.
  6. What done means. The test that has to pass.

The instructions are not a README for a person. They are the operating context for the agent. Short, explicit, and testable.

Without them, the agent guesses. Guessing is where most silent failures start.

The test set

Before the build, collect 20 real cases.

Not the clean examples. The messy ones. The missing document, the ambiguous clause, the customer with two IDs.

Run the check by hand on the 20 cases. Write down the answer for each one.

That set becomes the baseline. The agent is measured against it. If the agent cannot beat the hand-checked result, it is not ready.

If you want help with the build, see AI agent development or AI readiness assessment.

FAQ

Not to define the job, the output, or the check. You do need someone who can build and maintain the integration.

The one that passes the check at the lowest cost. Route the routine work to a smaller model and the hard judgments to a larger one.

It depends on the scope and on how many systems the job crosses. The check, the permissions, and the owner take longer to settle than the code.

Yes, for simple jobs. The limit is the check and the permissions. If the tool cannot enforce them, it is a demo.

The check. If you cannot define how to tell whether the output is correct, you are not ready to build the agent.

Start with the process that costs you the most time

Tell me which process you want to improve. A name, an email, and a short description of the process are enough to start a useful conversation.

Discuss your project