A field guide for AI engineers

Two Loops,
One Machine

Reinforcement learning asks how a policy improves through experience. Inference engineering asks how that policy produces useful tokens reliably, quickly, and economically. Agent systems make the two loops inseparable, especially when a policy must reason, call tools, learn from trajectories, and serve users under real latency and cost constraints.

This guide was compiled and put together to serve as a roadmap to help me better understand RL and inference. Hope you find it instructive. This conversation was the genesis for looking at RL and inference as tightly related loops.

22 chapters 4 curriculum parts 29 visual learning objects 1 recurring reasoning system

The entire argument in one picture

A deployed policy serves tasks. Some trajectories become governed experience. A training system turns selected experience into a candidate policy. The candidate returns to serving only after it passes evaluation. Inference generates production answers, rollout data, evaluator judgments, and sometimes draft tokens. That shared machinery is why RL and inference teams increasingly care about the same queues, runtimes, sandboxes, model versions, and cost curves.

The terrain

RL includes bandits, value learning, policy gradients, actor-critic, on-policy and off-policy learning, online and offline data, model-based planning, multi-agent learning, self-play, hierarchical control, preference learning, and verifiable rewards. Inference engineering begins with one forward pass and reaches continuous batching, KV memory, quantization, parallelism, speculative decoding, disaggregation, autoscaling, SLOs, and fleet economics.

The recurring case: an incident-reasoning engine

The incident-reasoning engine is a tool-using AI assistant for network operations teams. It receives an incident question and alert context, then works with a governed catalog of read-only tools that expose topology and inventory, telemetry, logs, and recent configuration changes.

Its job is to gather discriminating evidence, keep competing hypotheses alive, and decide when the evidence is sufficient. Its output is an evidence-backed likely cause, cited observations, explicit uncertainty, and a recommended next action for the operator. Throughout the series, this same product turns abstract vocabulary into concrete engineering choices: investigation traces become trajectories, tool calls become actions, replayable incidents become environments, rubrics become rewards, and serving constraints become inference-system requirements.

An alert says a western site is dropping packets. Two gateways serve the site, several telemetry streams disagree, and a recently changed interface is an attractive but misleading clue. The engine can inspect topology, query time-series data, search logs, test hypotheses, or answer. This investigation exposes the decision problem that RL must improve and the inference workload that production systems must execute.

RL sees
A partially observable environment, a tool-using policy, a trajectory of actions, delayed feedback, and a difficult credit-assignment problem.
Inference sees
Long prompts, growing tool transcripts, bursty parallel rollouts, latency-sensitive user turns, heavy KV memory, and an evaluation workload.
Engineering sees
Versioned evidence, reproducible scenarios, explicit contracts, observability, release gates, and a budget that spans quality, time, and cost.
Part IThe Two Loops
Chapter 01Two loops, one machineBuild the learning loop and serving loop separately, then find their shared inference core.01 / 22 Chapter 02The investigation as an episodeFollow one concrete tool-using investigation before introducing formal RL vocabulary.02 / 22
Part IIReinforcement Learning From the Ground Up
Chapter 03From rules to rewardsLearn what rewards express, what they omit, and how proxies get gamed.03 / 22 Chapter 04The world as an MDPSeparate hidden state, observation, action, transition, and reward.04 / 22 Chapter 05Time, return, and creditConnect delayed consequences to trajectories, discounting, and credit assignment.05 / 22 Chapter 06Value and advantageEstimate the future and judge actions relative to a baseline.06 / 22 Chapter 07Improving a policyBuild exploration, policy gradients, and actor-critic from a small example.07 / 22 Chapter 08PPO and GRPOSee why practical policy updates use guardrails and relative comparisons.08 / 22 Chapter 09The reinforcement-learning atlasOrganize the field by design axes instead of memorizing algorithm names.09 / 22 Chapter 10LLM post-trainingDistinguish SFT, preference learning, RLHF, DPO, RLAIF, and RLVR.10 / 22 Chapter 11Agent RL is a distributed systemConnect sandboxes, rollouts, graders, trainers, and release gates.11 / 22
Part IIIInference Engineering From One Token to a Fleet
Chapter 12One request, two phasesFollow a request through prefill, decode, sampling, and streaming.12 / 22 Chapter 13The GPU as a factoryReason about compute, bytes, arithmetic intensity, and hardware roofs.13 / 22 Chapter 14Keep the factory fullUnderstand continuous batching, scheduling, queues, and useful throughput.14 / 22 Chapter 15Remembering the promptPrice the KV cache and manage it with paging, reuse, and eviction.15 / 22 Chapter 16Make every pass cheaperPlace kernels, compilation, quantization, and parallelism on one map.16 / 22 Chapter 17Predict, then verifyBuild lossless speculative decoding from draft cost and acceptance length.17 / 22 Chapter 18From one GPU to a fleetOperate disaggregated, autoscaled, observable, and reliable serving systems.18 / 22
Part IVOne Machine
Chapter 19RL is an inference workloadSee why rollout economics make learning and serving share machinery.19 / 22 Chapter 20Build the learning loopEvolve a reasoning engine through data curation, preference learning, RLVR, and process feedback.20 / 22 Chapter 21What changes across agentsCompare reasoning, coding, conversational operations, and inference optimization.21 / 22 Chapter 22The field guideReview architectures, diagnose failure modes, and speak precisely.22 / 22 Interactive labBuild the intuition yourselfWork through the calculators and a complete reasoning-system capstone.Lab ReferenceGlossaryPlain-language definitions, connected back to their teaching chapters.A-Z ReferenceSources and further readingFoundational texts, primary papers, official documentation, and engineering reports.50 sources

Three reading paths

You needRouteDo not skip
A complete mental modelRead chapters 1 through 22 in order.The concrete reasoning episode and the field guide.
RL for agent workRead 1-11, then 19-22.Value and advantage before PPO/GRPO; systems before the applied pipeline.
Inference depthRead 1-2, 12-19, then 22.Prefill/decode before optimization; goodput before benchmark interpretation.