First, put the model back into the full system
In one lineData, memory, retrieved evidence and tools all change the result. Improve them together instead of only trying a larger model.
An AI system's result depends on more than its model. Data, retrieved memories, evidence, and tools all affect what it does. Improving the result means examining those parts together, rather than only trying a larger model.
Where to start
In one lineThe chapter follows a user getting a task done, not engine or training internals. Read this page, then pick a note by the problem you have.
This section follows a user trying to get something done. It does not repeat the implementation details of inference engines or distributed training. Read this overview for the request flow, then choose the problem you want to investigate.
| Your question | Start here | What you can check afterward |
|---|---|---|
| Where did this run go wrong? | Agent observability | Trace bad arguments, waits, and repeated actions without adding overlapping durations |
| What happens after a timeout, retry, or cancellation? | Failure and recovery | Distinguish not started, completed, and unknown before deciding whether to retry |
| When should a person step in, and can the team keep up? | Human-in-the-loop | Estimate review capacity and design approval, expiry, and handoff |
| Does human review actually improve the decision? | LLM decision support | Compare the person, model, and combined result, not just acceptance rates |
| Does a faster answer actually save the user work? | Model experience | Include waiting, correction, and time to finish, not only time to first token |
| What should carry across sessions? | Personal AGI | Select context by task, scope, and permission, then test corrections and withdrawal |
For prefill, decode, GPUs, and training frameworks, use the MLSys / LLMsys guide. For data, training, serving, and ownership across teams, see the end-to-end ML system walkthrough.
Which stages one request really passes through
In one lineA wrong date may come from stale state, old search results, a time-zone bug or a wrong field. Judging only the reply, you may fix the wrong part.
Suppose a travel agent books the user a flight on the wrong date.
“The model got it wrong” is only the most superficial description. The real cause may be that:
- the user changed the date in the previous turn, but the state was not updated;
- search found outdated flight information;
- the time-zone conversion in the tool arguments was wrong;
- the model picked the right date, but the execution layer passed the wrong field;
- the final evaluation only checked the reply text and never verified the real order.
If you look only at the final answer, you may fix the wrong part of the system.
Agree on what completion means
In one lineHTTP 200, “booked” and a correct order are three different things. In the example, 98% of responses are valid but the task metric is only 91%.
For a booking, HTTP 200, an assistant saying “booked,” and a correct confirmed order are different outcomes. Define a good event before measuring it: for example, a confirmed order returned within the allowed time, with the date, passenger, and amount matching the approved action. Record refusals, user cancellations, and pending approvals separately rather than folding them into one success rate.
A service-level indicator (SLI) measures delivery; a service-level objective (SLO) sets its target. Google's SRE chapter on SLOs starts with outcomes that matter to users and then specifies how to measure them. For an AI product, distinguish a successful response from a correct task result.
Here is a simpler order-status example with entirely assumed numbers. All 10,000 queries in the measurement window require an answer and remain in the denominator; none are user cancellations. A good event means showing a correct, sufficiently fresh order status within 6 seconds.
| Measurement | Count | Share of all queries |
|---|---|---|
| Valid response returned | 9,800 | 98% |
| Content verified as correct | 9,400 | 94% |
| Correct and completed within 6 seconds | 9,100 | 91% |
The response metric is 98%, but the agreed task metric is 91%. With an illustrative 95% target, the error budget is 10,000 × 5% = 500 missed targets. There were 900, consuming 1.8 times that budget. This is not a recommended booking target or permission for unauthorized actions or duplicate charges: check safety constraints separately, not as something a good average can offset.
Correctness may also be unknown when the request finishes. Report pending outcomes and measurement coverage; do not count them as successes or choose a flattering denominator from known results alone. Break results down by language, task, and latency to see whether particular users consistently fare worse.
Walk through it end to end
In one lineUpdate state, then search; confirm, then book; then check the real order. Each of eight layers, from goal to evaluation, can change the result.
- 1 · Update, then searchReplace the old travel date with Friday, then look up flights and prices. Otherwise the model may give a careful answer based on stale information.
- 2 · Confirm, then actShow the exact flight, date, and cost. Call the booking API only after confirmation and authorization checks; an “okay” from the assistant is not a completed order.
- 3 · Check the real orderRead back the order and verify its date. If it is wrong, trace the first failure in state updates, search, or execution rather than only revising the final answer.
1. User goal: what are we actually trying to solve
First state clearly the task, the target population, the cost of failure, and the conditions that must not be violated. Otherwise the system easily optimizes a metric that is convenient to measure but does not represent real value.
2. Data and feedback: the past the model sees
Data is produced jointly by previous models, the product interface, and user behavior. It is not a neutral fact. See Data and feedback.
3. Representation and memory: how the system keeps state
This layer decides what enters the current context, what persists across sessions, and how new evidence revises old understanding. See Representation and memory.
4. Search and tools: how the system connects to the outside world
Search is responsible for finding evidence and candidates; tools are responsible for reading or changing external state. Both can return successfully and still deliver wrong or outdated information.
5. Model and policy: how the system decides the next step
The model combines the goal, the state, and the evidence to decide whether to answer, ask a follow-up question, search, or act. Post-training shapes that behavioral tendency.
6. Runtime and execution: what decides whether it can really be done
Latency, caching, concurrency, retries, permissions, state synchronization, and cost are not necessarily research topics, yet they directly change the behavior the user sees.
7. User outcome: “generation finished” does not mean finished
What really has to be checked is whether the task was completed, whether the external state is correct, and whether the user got the result they wanted.
8. Evaluation and learning: how the next round gets better
Rules, executors, LLM judges, human review, and online metrics together form the evidence. Failure cases also have to flow back as new tests, data, or policy updates.
Example: a support agent that can look up orders and issue refunds
In one lineLook up orders and refund rules at run time; execution code, not the prompt, enforces permissions. After a timeout, check status before retrying.
This kind of system cannot stop at generating natural language. It reads constantly changing business facts and may execute actions with side effects:
User message
→ Language, intent, and risk detection
→ Structured conversation state
→ Retrieve order, logistics, policy, and seller evidence
→ Model decides to reply, ask a follow-up question, or call a tool
→ Execution-layer checks for authorization, schema, policy, and required confirmation
→ Execute the read / write tool
→ Generate the answer from the execution result
→ Confidence check, clarification, or human escalation
Order status, logistics tracking, refund eligibility, and current policy cannot rely on what the model's parameters remember; they must be obtained at run time through retrieval or tool calling. Post-training teaches the model how to use evidence and take action; it is not responsible for storing constantly changing business facts.
State should also be layered. The most recent raw turns preserve linguistic continuity; structured task state stores the order ID, the verified identity, tool results, and actions pending confirmation; a long-conversation summary keeps only evidence-backed facts and unresolved items. The enterprise database and versioned policy remain the source of truth and cannot be replaced by a summary.
A refund needs authorization, schema validation, any required user confirmation, and an audit log. If the API supports idempotency keys, retries of the same refund must reuse the original key and parameters within the API's documented scope and retention period. Generating a new key does not prevent a duplicate refund. A timeout does not tell us whether the action happened: check its status or rely on a verified idempotency guarantee before retrying. Never pretend it succeeded. When evidence is insufficient, policies conflict, or risk is too high, ask for clarification or hand off to a human. Semantics are API-specific; for example, see Stripe's idempotent-request documentation. Do not assume every tool offers the same guarantees.
Enforce these checks in trusted execution code, not just in a prompt. A seller note saying “ignore the refund limit” is still data to verify, not policy or authorization. Valid JSON does not establish that the current user may refund this order. Instructions inside retrieved content or tool results cannot grant permissions, and a model's score cannot replace access checks. See OWASP's agent-tool defenses.
Evaluation looks at task resolution, grounding, policy compliance, tool-call correctness, unsafe-action rate, multilingual consistency, escalation quality, latency, cost, CSAT, and repeat-contact rate all together. Fluent wording is only one part of the result.
A more reliable evaluation stack
In one lineIf a rule can check a condition exactly, use it. For model scoring, write the criterion first; in pairwise tests, swap the order and allow ties.
The evaluation stack compares deterministic rules, references or executors, LLM judges, human review, and online metrics in one table. It explains what each method can establish and where it falls short. If a rule can check a condition exactly, use it rather than asking a model to guess.
When model scoring is needed, define the criterion first, then choose between scoring one output and comparing two. For pairwise comparisons, swap the display order and allow a tie or “both bad”; see LLM judge output formats. For calibration against human labels and agreement checks by slice, see LLM-as-a-judge.
Why look at the full chain
In one lineErrors flow downstream: with wrong data or state, a model can decide reasonably from its inputs and the whole task still fails.
Errors in the system propagate downstream:
Wrong or missing data
→ wrong user state
→ wrong query
→ wrong retrieval results
→ the model makes a “reasonable” decision in the wrong context
→ the final experience fails
The model may be entirely reasonable given its own inputs, and the system as a whole is still wrong.
When analyzing a problem, I first write down these nine questions
In one lineBefore debugging, write down nine questions, from goal and hypothesis to evidence and tradeoffs, so you do not fix only the visible symptom.
Goal What are we really trying to improve?
User Improve it for whom? Is any group hidden by the average?
System How do the data, components, and control flow connect?
Invariant Which properties must never be broken?
Failure Where, specifically, does it fail, and how?
Hypothesis What do I think the cause is? What result would overturn it?
Constraint What are the latency, cost, hardware, privacy, and compatibility limits?
Evidence What evidence will tell us the fix works?
Tradeoff What improves, and what might it hurt?
These questions help avoid fixing only the most visible symptom; they need not complicate a simple problem. You do not have to master every layer, but keep the full system in view when working deeply on one part.
Two modules that help the system keep improving
In one lineTraces make a run inspectable and replayable; people step in for high risk or weak evidence. Models only propose actions; permission checks decide.
Agent Observability: first, see what happened
It connects model calls, retrieval, tools, memories, and state changes into a trace that can be inspected and used to construct controlled replay tests.
Human-in-the-Loop: when to ask someone to step in
People do not need to review every step. Ask for confirmation, correction, or a handoff when an action is risky, the evidence is weak, or the system faces a task it has not been tested on.
- 1 · Specify the actionRecord the target, arguments, evidence, and tool state. The model may propose an action, but a proposal does not grant permission to execute it.
- 2 · Check permissionThe execution layer checks authorization and business rules. If they do not allow the action, stop or request authorization; a model score cannot bypass this check.
- 3 · Decide whether to askRun deterministic checks and use calibrated evaluators where scoring is needed. Required confirmation, high risk, or insufficient evidence leads to step 4; otherwise continue to step 5.
- 4 · Follow the decisionApproval leads to step 5. Changed targets or arguments return to step 1 for fresh checks. Rejection or an expired confirmation stops execution; record the decision and reason.
- 5 · Recheck before writingThe exact action, authorization, required approval, and current state must still be valid. Use version conditions or atomic operations to guard against changes between check and write. Stop if validation fails.
- 6 · Verify and recordCheck the external outcome; a timeout proves neither success nor failure. Keep appropriate records of execution and stops, then use failures for regression tests and later policy updates.
High risk, insufficient evidence, or irreversible effects can require human review; actions requiring confirmation also need valid approval. If the target or arguments change after approval, validate the new action rather than reusing the old confirmation. This diagram shows control flow, not a deployable security implementation.
One layer further down: infra
In one lineThis chapter stops above infra. Training and inference engines have their own notes here; outside the site, start with Awesome-ML-SYS-Tutorial.
For a first explanation of how training spans devices, read distributed training. It compares DDP, FSDP, TP, and PP with small hand-checkable examples, checks the global loss denominator, and accounts for memory and communication. It is a mechanism guide, not a deployment manual. For one layer worked through, continue with tensor parallelism; for what DDP, FSDP2, and related tools each take over, read choosing a training stack; on the inference side, start with a request through the service and vLLM and SGLang.
This chapter is about the path a request takes. Below it — how an inference engine schedules, how memory is laid out, how RL training and rollout are stitched together — is not my strength, and not where my interest sits.
For that layer the best thing I know is Awesome-ML-SYS-Tutorial: zhaochenyang20 has been writing these ML SYS notes since August 2024 — RL infra, online and offline inference, SGLang including the SGLang Omni series on multi-stage generative models — in both Chinese and English. He works on RL infra inside the SGLang community, so he is writing about what he is changing. Start there.
This site also has notes on that layer: GPUs, CUDA, frameworks and performance analysis are in AI infrastructure; how sampling, numerics and context are aligned in RL training is in post-training infrastructure; how the training system for multi-step agent RL is put together is in Agent RL: credit assignment and the training system.