AI engineering · field notes

Before you build an AI agent, learn how AI systems are actually built.

An agent is one layer of a production AI system. Most of the engineering that decides whether it works lives in the layers around it, and those layers are older than agents.

Field notes~16 min read 10 layers · 15 failure modesInteractive

Something in AI engineering has become increasingly interesting to me.

People are jumping directly into AI agents without first understanding the engineering foundations that made agents possible. The path usually looks like this. A framework is released. A model gets connected to a tool, a vector database is added, a few prompts are written, and an orchestration layer ties it together.

The system works, at least on the inputs it has seen so far, and the builder starts calling themselves an AI engineer.

Building an agent and understanding AI engineering are two different things, and the difference matters.

To be clear, I am in favor of agents. They are becoming an important abstraction for building software around increasingly capable models. An agent is still a system, though. It has inputs, outputs, dependencies, state, failure modes, latency constraints, security boundaries, evaluation requirements, infrastructure requirements, and operational costs.

Those concerns did not appear because agents became popular. They existed long before agents, and most of them are general engineering problems that AI systems inherit.

Section 01

AI engineering did not begin with agents

Before today's agent frameworks, there was machine learning. Before modern machine learning systems, there was statistical learning. Before that came decades of research in artificial intelligence, optimization, probability, search, computer science, distributed systems, databases, software engineering, and mathematics.

The modern AI stack is the result of all of those layers accumulating over time. That history matters because every abstraction hides complexity.

Figure 01

What one framework call hides

One call, fourteen concerns. A high-level agent framework puts them behind a single interface. Every one of them is still running underneath.

agent.run(task)STILL RUNNING UNDERNEATHONE CALLinvocationcontextretrievaltool routingstateretriesconcurrencycachingauthAPI failuresobservabilityevaluationdeploymentcost

A high-level agent framework can hide all of the following:

  • Model access. Model invocation, context construction, and retrieval.
  • Control flow. Tool routing, state management, retries, concurrency, and caching.
  • Integration. Authentication, API failures, and observability.
  • Lifecycle. Evaluation, deployment, and cost management.
The principle

Hiding complexity leaves it in place. The abstraction makes development faster, and the engineering underneath still has to be done.

That is the difference between using an AI system and engineering an AI system.
Section 02

The question production actually asks

Modern AI development is often presented as if the central problem were "How do I make the model more intelligent?" In production, that is only one part of the problem. A more important question is:

How do I build a system that remains useful when reality does not behave like my demo?

That question covers fifteen failure modes. I group them by where they originate, because the origin usually determines the fix. Open any row for the failures that start there.

The model produces an incorrect answer. It hallucinates an action, such as a tool call with fabricated arguments. Its behavior changes after the provider updates it. The agent enters an unnecessary loop.
Retrieval returns irrelevant context, or the context window becomes saturated.
A tool returns malformed data. An API becomes unavailable. Latency suddenly increases. Traffic grows by 10x. A downstream service fails halfway through execution and leaves state partially updated.
The evaluation dataset stops representing production, or user behavior changes.
An attack manipulates the context, for example a prompt injection planted in a retrieved document or a tool output.
The cost per task becomes economically unreasonable.
None of these is solved by simply adding another agent. They are solved through engineering discipline.
Section 03

Software engineering still runs through most of AI engineering

This is one of the most important things I have learned while working through the rapid evolution of AI systems: a surprisingly large portion of AI engineering is still conventional software engineering.

The AI component changes how one part of the system behaves. Everything around it still has to be engineered.

The probabilistic nature of modern AI often makes these disciplines more important. Traditional software generally tries to produce deterministic behavior from deterministic inputs. AI systems frequently operate under uncertainty, so the surrounding engineering has to compensate for it.

Compensating for uncertainty

Validate model outputs against a schema before anything downstream consumes them. Put timeouts and bounded retries around external calls. Define fallbacks for when a component degrades. Gate releases on evaluation results.

Section 04

Machine learning fundamentals still matter

There is another layer that is increasingly easy to skip. If you want to work seriously on AI systems, understanding how models learn is still valuable. You should be able to reason with concepts such as these:

The goal is enough understanding to reason about what the model is doing, which is well short of deriving every optimization algorithm from first principles.

Without it, you are operating the system from the outside. You can call the API, configure the framework, and connect the tools, but when the system behaves unexpectedly, you may not know why. That is where the difference between framework usage and engineering becomes obvious.

Figure 02

Distribution shift

A concrete case. An agent that scored well in offline evaluation starts choosing worse tools in production.

EVALUATION SETLIVE TRAFFICSHIFT

One of the first hypotheses to test is distribution shift between the evaluation set and live traffic. Testing it requires knowing what that shift looks like in your data, and that is an ML question.

What to check

Compare the inputs your agent sees in production with the evaluation set it was measured on. If they have drifted apart, the offline score no longer describes the system you are running.

Section 05

The agent is one layer of a larger stack

A production agent can be described as a stack. The exact architecture varies by system, but the principle holds.

Figure 03

The production AI stack

Agent orchestration is the eighth of ten layers. Most of what determines whether it works sits below it, and most of what determines whether it keeps working sits above it.

10Production operations09Evaluation and observability08Agent orchestrationTHE AGENT07Tool integration06Retrieval and knowledge systems05Inference infrastructure04Deep learning and foundation models03Machine learning02Software engineering01Computer science and mathematicsWHETHER ITKEEPS WORKINGWHETHER ITWORKS

Read it from the bottom up. Computer science and mathematics sit at the base, followed by software engineering, machine learning, deep learning and foundation models, inference infrastructure, retrieval and knowledge systems, and tool integration. Agent orchestration comes eighth. Evaluation and observability, then production operations, sit above it.

The principle

The agent is one abstraction sitting on top of many others.

This is why learning only an agent framework can create a dangerous illusion of competence.

You may know how to construct the graph without yet knowing how to engineer the system.
Section 06

Vibe coding an agent has a ceiling

I have nothing against AI-assisted coding. It is one of the most powerful productivity shifts software engineering has seen. The problem begins when generated code becomes a substitute for understanding. Compare two statements:

"The AI generated an agent and it works."
"I understand the architecture, constraints, failure modes, evaluation methodology, operational requirements, and trade-offs of this agent."

The first shows that you can produce software. The second shows that you can engineer a system. AI coding tools can dramatically reduce the cost of implementation, but they do not automatically transfer architectural judgment to the developer. That gap matters more as systems become more autonomous.

A practical test for any agent you have shipped is whether you can answer these nine questions.

Question 1

Why did it select that tool?

Tool routing is one of the concerns a framework hides. The decision still has to be explainable after the fact.
Question 2

Why did retrieval produce that context?

Irrelevant retrieved context is one of the fifteen failure modes, and it shapes every answer downstream.
Question 3

Why did that request fail?

Model, context, infrastructure, data distribution, security, or cost. The origin usually determines the fix.
Question 4

Where is state stored?

Two tool calls can modify the same state at once, and a service can fail halfway through a write.
Question 5

How do retries behave?

If a retried operation has side effects and is not idempotent, it runs again. Retries need a budget.
Question 6

How are failures recovered?

A downstream service can fail halfway through execution and leave state partially updated.
Question 7

How is the system evaluated?

Offline scores describe production only while the evaluation set still represents it.
Question 8

How are costs controlled?

Cost per task can become economically unreasonable long before anything visibly breaks.
Question 9

How is the system secured?

Prompt injection can arrive inside a retrieved document or a tool output as well as in the user's message.

If you cannot, the generated code may be running, but you are not necessarily in control of the system.

Section 07

The lifecycle is much larger than the demo

One idea I particularly appreciate in Thomas R. Caldwell's The AI Engineering Bible is its framing of AI development as a complete engineering lifecycle, in which building the model is one part of one stage.

The ordering matters, because the work does not end when the model responds correctly. Step through it.

Stage 1 · the problem

Design

What are we actually trying to solve? What data do we need, what constraints exist, what architecture makes sense, and how will success be measured?

Covers

Data, constraints, architecture, and success metrics.

Stage 2 · the working system

Build

How do we turn that design into a working system?

Covers

Data pipelines, training, prompting, orchestration, integration, and testing.

Stage 3 · the production service

Deploy

How does this become a production service?

Covers

Infrastructure, containers, APIs, CI/CD, and a deployment strategy.

Stage 4 · growth

Scale

What happens when usage increases?

Covers

More users, more requests, more data, more throughput.

Stage 5 · efficiency

Optimize

How do we make the system economically and technically efficient?

Covers

Latency, cost, model compression, quantization, and resource utilization.

Stage 6 · the long run

Maintain

How does this system remain reliable six months or two years from now? Many prototypes never reach this question.

Covers

Monitoring, drift detection, retraining, security, governance, versioning, and continuous improvement.

That lifecycle is a much better mental model for AI engineering than Prompt → Agent → Ship. The book's running Customer Support AI example makes this concrete by carrying one production system through the entire lifecycle, showing how decisions made early in the architecture affect deployment, scaling, and maintenance later.

Section 08

The real complexity lives between the components

Individual components are often not the hardest part. You can learn an embedding model, RAG, tool calling, an agent framework, a vector database, and an LLM API one at a time. Production complexity emerges from the interactions between them.

Take a simple workflow: user, agent, retrieval, LLM, tool, database, response. Every arrow is an interface, and each one raises its own engineering questions. Switch between them below. The nodes stay the same, only the failing interface changes.

useragentretrievalllmtooldatabaseresponse

User → Agent: the request changes midway

The agent has already started work when the user edits, extends, or replaces the request. The system is now executing against an intent that no longer exists.

What breaks

Work continues on the old request. Partial results from both versions mix in state and in the final response.

What it takes

An explicit task state that a new request can supersede, and traces that show which version of the request each step served.

The engineering question

What happens when the user's request changes midway through execution?

The engineering behind each arrow is where the work is. That is why production AI requires systems thinking.
Section 09

Autonomy makes fundamentals more important

There is an interesting paradox here: the more autonomous AI systems become, the more traditional engineering matters.

Figure 04

What one wrong step can reach

A chatbot has one major output. An agent can call APIs, access databases, execute code, modify files, interact with external systems, trigger workflows, make decisions, delegate tasks, and maintain state.

LLMtextchatbotONE OUTPUTcall APIsaccess databasesexecute codemodify filesexternal systemstrigger workflowsmake decisionsdelegate tasksmaintain stateAGENTBLASTRADIUS

Each of those capabilities is another path by which a single wrong step reaches a real system, and together they increase the blast radius of failure. That calls for stronger guardrails, permissions, observability, validation, sandboxing, error recovery, human-in-the-loop mechanisms, evaluation, and auditability.

The mapping from capability to control is fairly direct.

CapabilityControl it needs
Code executionA sandbox
Writes to files and databasesScoped permissions and an audit trail
API callsValidated arguments and a recovery path
Irreversible actionsA human in the loop
All of the aboveGuardrails, observability, and evaluation
Autonomy without engineering discipline can look sophisticated. In practice it is a larger failure surface.
Section 10

Research literacy keeps your knowledge current

The pace of research is another reason fundamentals matter. The field is moving too quickly to treat today's frameworks as permanent knowledge.

Changes quickly

Framework APIs. Models. Inference methods. Context architectures. Evaluation methodologies. New research that changes what is possible.

Changes slowly

ML fundamentals. Systems engineering. Research literacy. Software engineering.

If your understanding is tied exclusively to one framework, it becomes obsolete when that framework changes. If it is grounded in ML fundamentals, systems engineering, research literacy, and software engineering, you can adapt.

The takeaway

At that point the framework is a tool you use, and your foundation does not depend on it.

Section 11

My own path through this shift

A quick note on where I am coming from: I'm Haroon, and I entered the AI field at the end of 2023, during the GPT era. I started from the fundamentals of machine learning and its core principles rather than from today's agent abstractions.

Since then, I have watched the industry move through a fast sequence of changes:

  1. LLMs became mainstream.
  2. RAG became mainstream.
  3. AI coding accelerated.
  4. Tool use became practical.
  5. Agentic workflows emerged.
  6. Multi-agent systems became a major research and engineering direction.
  7. Inference infrastructure matured.
  8. We are now moving toward increasingly autonomous AI systems.
The tools change incredibly quickly. The fundamentals change much more slowly.

The deeper I go into AI engineering and research, the more convinced I am that there is no point at which you finish the fundamentals and move on to being an AI engineer. They are the foundation you keep working from for your entire career.

Section 12

You do not need to know everything

None of this means every AI engineer needs to be a mathematician, a distributed-systems researcher, a deep-learning scientist, a compiler engineer, a security researcher, and an infrastructure expert at the same time. That is unrealistic, and specialization is necessary.

Specialization and foundational ignorance are different things, though. A strong AI engineer can move across layers when necessary, which takes:

Section 13

The future of AI engineering will reward systems thinkers

Knowing how to call the newest model will be a common skill. The next generation of AI engineers will be the people who can answer questions like these.

AreaThe questions
Problem framingWhat should we build? Why should we build it this way? What assumptions are we making?
EvaluationHow do we evaluate it? How do we know it is improving?
ReliabilityHow does it fail? How do we recover from those failures?
OperationsWhat happens at 10x traffic? What happens when the model changes? What does each request cost? How do we secure the system? How do we maintain it for years?
That is AI engineering, and agents are one part of it.
Section 14

Build agents, but understand what you are building

I love the current agent ecosystem. I experiment and build with these systems, and I study new architectures as they appear. I believe agents will become an important interface for software.

I would still encourage anyone entering AI today to resist one temptation.

Do not let the newest abstraction become the limit of your understanding.

Learn the foundations. Understand ML, and learn software engineering deeply. Study systems, including distributed systems. Understand data and inference, and learn how models are evaluated and deployed. Learn security. Read research. Build things, then break them, measure them, debug them, deploy them, and operate them.

Then build agents.

Once you understand the layers underneath the abstraction, an agent framework stops looking like magic. It becomes what it actually is: another engineering tool for building intelligent systems. That shift in perspective is, in my opinion, one of the most important transitions an aspiring AI engineer can make.

The bar worth aiming for

Impressive AI demos are cheap to build now. The goal is to become someone who can build an AI system that survives reality.

The takeaway

That is a much higher bar, and it is the one worth aiming for.

Contents

  1. AI engineering did not begin with agents1 min
  2. The question production actually asks1 min
  3. Software engineering is still most of the work1 min
  4. Machine learning fundamentals still matter1 min
  5. The agent is one layer of a larger stack1 min
  6. Vibe coding an agent has a ceiling2 min
  7. The lifecycle is larger than the demo1 min
  8. The complexity lives between the components3 min
  9. Autonomy makes fundamentals more important1 min
  10. Research literacy keeps your knowledge current1 min
  11. My own path through this shift1 min
  12. You do not need to know everything1 min
  13. The future rewards systems thinkers1 min
  14. Build agents, understand what you build1 min