In 2016 a Google data centre handed control of its cooling setpoints to a piece of software. That software reads thousands of sensor values every few seconds, decides how far to open each valve and chiller, then checks the result against actual power consumption. Cooling energy fell by around 40%. Nobody had written a rule for every scenario. The system learned the policy itself.
You are almost certainly not cooling a data centre. But the same loop, sense, decide, act, measure, runs behind a delivery route that reroutes itself mid-shift, a support queue that triages tickets before a human opens them, and an ad system that re-prices a placement fifty thousand times a minute.
Here is how to build one of those, step by step, with examples you can copy.
First, Check That You’re Actually Building an Agent
Plenty of so-called AI projects are classifiers wearing a costume. A model that labels an email as spam and stops there is not an agent. An agent closes the loop: it takes an action, watches what happens, and changes its behaviour next time.
The test takes thirty seconds. Ask three questions:
- Can it perceive something about its environment?
- Does it choose an action, rather than just emit a label?
- Does the outcome feed back and alter future decisions?
Three yeses and you have an intelligent agent. Fewer, and you have a component, which is fine, but name it honestly. If the vocabulary still feels slippery, what actually separates an agent from a plain automated script is worth ten minutes before you write any code.
Step 1: Pick a Job That Already Produces a Feedback Signal
Agents learn from consequences, so your first real design decision is finding a job where consequences show up quickly and cheaply.
Strong candidates look like this: restocking decisions at a retailer, where sell-through is visible within days. Bid adjustments on paid search, where cost per conversion moves within hours. HVAC scheduling, where the electricity bill lands monthly but sub-metered readings arrive every minute.
Weak candidates are anything where the ground truth takes six months to surface. Hiring quality, long-term brand health, strategic bets. If you cannot observe the result inside a few cycles, you are building a demo, not an agent. For a sense of how far this scales in production, there are real-world examples of agents already running in logistics, finance and energy.
Step 2: Define the Perception Layer Before You Touch a Model
Write down everything the agent can see and how often each thing refreshes. A delivery routing agent might read a traffic feed every 60 seconds, a weather API every 15 minutes, driver shift rules once a day, and confirmed orders in real time.
The temptation is to plug in every data source you own. Resist it. Each input adds latency, cost, and a new way to break. A useful rule: if a signal cannot plausibly change the next decision the agent makes, leave it out of the first version.
Also decide what the agent does when a feed goes dark. Silent nulls are how most first attempts fail in production. Treat missing data as a state, not an error.
Step 3: Match the Decision Policy to the Stakes
Three approaches cover most builds, and the right one depends on how expensive a mistake is and how reversible it is.
Rules where being wrong is expensive
Anything touching payments, safety or legal exposure should sit behind hard-coded limits. A rules layer that refuses to send a withdrawal to a newly added bank account is unexciting and correct. Keep it dumb and keep it fast.
Supervised models for judgement with history behind it
When you have thousands of labelled past decisions, a trained model generalises well. Netflix’s recommender influences roughly 80% of what subscribers watch, but it is ranking options, not signing contracts. That is the sweet spot: high volume, low individual cost, plenty of precedent.
Reinforcement learning for optimising a loop
RL earns its keep when you can simulate the environment or afford to explore: cooling systems, bidding strategies, robot fleets. This is the territory of autonomous software quietly managing infrastructure while everyone looks at the dashboard instead.
Step 4: Constrain the Action Layer in Code
Decide, before launch, exactly what the agent may do unsupervised. A support agent refunds up to $50 without asking; anything larger gets drafted and queued for a human. A trading agent caps position size and shuts itself off after three consecutive losses. A warehouse robot yields to any human presence in its zone, no exceptions.
Write these as executable guardrails, not a policy document nobody reads. If a limit only exists in a slide deck, it does not exist.
Step 5: Measure the Loop, Not the Model
Model accuracy is the least useful number in the room. What matters is the loop-level metric: average handling time, energy per rack, misroutes per thousand tickets, cost per acquisition.
A triage agent with 92% routing accuracy sounds respectable until you notice the 8% it misses are enterprise accounts, the ones worth more than everything else combined. Ship against the business metric and the accuracy conversation takes care of itself.
Four Examples You Can Copy This Quarter
- Cooling and energy optimisation. DeepMind’s data centre work reported roughly 40% lower cooling energy and about 15% lower overhead overall. The mechanism is unglamorous: predict, act, measure, correct every few minutes.
- Real-time bidding. Ad exchanges evaluate bids in under 100 milliseconds and reallocate budget across millions of impressions daily. The feedback signal, clicks and conversions, arrives within hours.
- Support triage. An agent reads an inbound ticket, sets priority, tags the product area, and routes it, then watches whether reopen rates spike.
- Warehouse fleets. Hundreds of robots replan routes continuously as they pass each other, with the feedback loop measured in seconds rather than days.
Where These Builds Usually Go Wrong
Reward hacking tops the list. Give an agent a proxy metric and it will optimise the proxy. One team rewarded ticket closure and got tickets closed without the underlying problem being fixed; reopen rates tripled inside a month.
Over-permissioning is the next culprit. An agent with write access to production and no spend cap is a single bad parse away from an expensive afternoon. Silent drift is the quiet one: input distributions shift, the model keeps answering confidently, and nobody notices until volume drops. Understanding why the distinction between AI and agents matters in practice helps here, because the failure modes are different in kind, not degree.
And every agent needs a kill switch a junior engineer can reach in under a minute without asking permission.
A 90-Minute Exercise to Get Your First Loop Running
Pick one task you do repeatedly that has a measurable outcome within a week. Log the inputs you use and the decisions you make for five working days. That log becomes your training data and your baseline.
Then write the simplest possible version: a rules-based decider with a manual override, wired to read real inputs and write one real action. Log every decision and its outcome. Run it in shadow mode for a week, where it recommends but you approve.
Only after the recommendations beat your baseline do you remove the human from the loop, one action type at a time. That is how the data centre software started too, with engineers watching closely, ready to take the dials back.

