Part I / The Two Loops
Two loops, one machine
Before algorithms and GPUs, draw the system boundary correctly. One loop changes the policy. The other executes it. In modern agent systems, inference sits inside both.
Where does learning stop and serving begin?
A reasoning engine handles an incident, then learns from replay.
A system map that prevents team-boundary confusion.
Start with two factories
Imagine a restaurant with a test kitchen and a dinner service. The test kitchen tries recipes, measures outcomes, and changes the cookbook. Dinner service follows a particular cookbook under real constraints: guests are waiting, ovens are finite, and the dining room cannot pause because a new sauce looks promising. Reinforcement learning is part of the test kitchen. Inference engineering is the discipline of making dinner service fast, predictable, economical, and faithful to the chosen cookbook.
The metaphor breaks in one useful place. The test kitchen also needs dinner service. To evaluate a recipe, somebody must cook it. To generate an RL trajectory, a policy must run inference, select tokens, call tools, receive observations, and continue. If we sample eight answers for every prompt, run a judge model, and repeat across thousands of prompts, the learning loop can execute far more inference than production traffic.
Training changes parameters. Inference holds parameters fixed while using them. An RL run alternates between those modes: long bursts of fixed-policy inference create experience, then an optimizer changes the policy.
Follow one incident through both loops
A user asks: "Why did the western site lose connectivity at 14:03?" The serving system tokenizes the request, schedules a prefill, streams model output, executes topology and telemetry tools, appends their results to the context, and performs more decode steps. The answer arrives in 18 seconds and costs six tool calls.
That investigation is useful now, but it may also become experience. A privacy and provenance filter decides whether the trace is eligible. An evaluator checks the final cause, whether evidence supports it, whether the engine invented facts, and whether it ignored an alternate gateway. The trace joins other attempts generated in replayable seeded environments. Some are correct and efficient; others are persuasive failures.
The learning system can use that corpus in several ways. It can select strong traces for supervised fine-tuning. It can turn strong and weak pairs into preference data. It can use deterministic incident outcomes and structured rubrics as rewards for online rollouts. Each choice creates different data requirements, optimization behavior, and failure modes. None eliminates inference: every new attempt, reward-model judgment, or candidate evaluation runs one or more models.
The two loops optimize different contracts
The learning loop improves a policy to maximize expected return over the tasks and trajectories it trains on. It cares about sample efficiency, exploration, data quality, reward validity, and policy stability. Held-out evaluation asks whether those improvements transfer beyond the training distribution. The serving loop maximizes useful work under operational constraints. It cares about time to first token, inter-token latency, requests or tokens completed within an SLO, accelerator utilization, memory, availability, and cost.
These objectives interact but are not interchangeable. A faster rollout engine can buy more samples per research day, which may improve the policy sooner. A policy update can change response length, tool-call frequency, KV-cache pressure, or speculative-decoding acceptance. A serving optimization can alter numerical behavior or scheduling enough to change rollouts. A rollout system optimized only for raw tokens per second can produce stale trajectories from old policies. A useful interface exposes versions, workload shape, provenance, and quality alongside the model endpoint.
| Loop | Primary object | Typical constraint | Failure that looks like success |
|---|---|---|---|
| Learning | Policy update | Valid experience and stable optimization | Reward rises while real task quality falls |
| Serving | Completed useful request | Latency, capacity, memory, reliability | Tokens per second rises while SLO goodput falls |
| Shared inference | Forward passes | Workload-dependent cost and scheduling | Benchmark wins on a shape the application never sends |
The optimizer is only one component. An applied RL system also needs task sampling, environments, policy inference, tool execution, trajectory storage, rewards or preferences, evaluation, version transfer, and release control. In agent RL, rollout execution is often the operational center of gravity.
Three boundaries to keep crisp
Training inference versus production inference
Both execute a fixed model forward pass, but the workloads differ. Training rollouts may want many diverse samples, controlled temperatures, long tool traces, and asynchronous throughput. Production may want predictable tail latency, strict isolation, streaming, quotas, and rollback. Reusing a runtime does not mean reusing every serving policy.
Model quality versus system quality
A model can be excellent in isolation and poor inside an agent if tools are unreliable, observations are malformed, context assembly loses evidence, or timeouts reward premature answers. Conversely, good orchestration can mask a weak policy on easy tasks. Evaluate the full trajectory and its environment.
Raw throughput versus useful throughput
More tokens are not automatically more value. A late answer, an invalid trajectory, or a reward-hacking rollout consumes capacity without satisfying the contract. Later chapters use goodput for work that is correct enough and timely enough to count.
References
- Sutton and Barto establishes the agent-environment loop and policy/value vocabulary used throughout.
- Modal's applied RL infrastructure essay is a first-party account of elastic sandbox, rollout, evaluation, and inference workloads.
- Gong and Alberti, 1:04 and 14:20, discuss rollouts as inference and the convergence of RL and inference optimization.
- Kiely's book informs the workload-to-production scope of inference engineering.