Reading an AI application from the inside
A diagram of a working assistant can contain ten product names. You can understand it by identifying four jobs: computing a response, finding evidence, carrying out actions and keeping track of the request.
Open this chapter with experiments and audio
Trace the components behind one answer
Consider an assistant that answers questions about a studio handbook. A web interface accepts the question. An application server authenticates the user and chooses a collection of documents. A retrieval component returns passages, and a model endpoint generates text using those passages. The server delivers the answer with source IDs.
One Python program can perform several jobs. A large service might run each component independently. Keeping their inputs and outputs clear makes the design easier to change. A retrieval component needs a query, an allowed collection and a requested number of results. Its output can be an ordinary list of passages with identifiers and scores.
Give each name a place in the system
Start with the interface a component exposes. A model runtime accepts token sequences or messages and returns generated tokens. A vector index accepts a query vector and returns nearby entries. A workflow library directs control between steps and remembers intermediate state. An integration protocol describes how separate programs discover and call one another’s capabilities.
| Job | Examples | Inspect |
|---|---|---|
| Model execution | Ollama, vLLM | Model tag, output tokens |
| Document retrieval | LlamaIndex integrations, pgvector, Qdrant | Passage IDs and scores |
| Application workflow | Python, LangGraph | State and next action |
| Tools and resources | MCP client and server | Declared inputs and returned results |
| HTTP interface | FastAPI | Request and response schema |
Keep a trace of one request
A trace records the order and timing of operations. The synthetic trace below takes 440 ms. The largest stage is generation at 380 ms. Improving retrieval by 50% saves 20 ms in this example. Reducing generation time by the same percentage saves 190 ms. These numbers help locate a bottleneck before selecting a new framework.
spans = [("permissions", 12), ("retrieve", 40),
("generate", 380), ("format", 8)]
total = sum(ms for _, ms in spans)
for name, ms in spans:
print(f"{name:12} {ms:3} ms {ms / total:5.1%}")
print("Total:", total, "ms")Find the smallest responsible component
If the answer cites an unrelated passage, inspect the retrieved IDs before changing the prompt. If the IDs are right and the model misquotes the passage, inspect its formatted input and output. If a retired document remains visible, check the indexing and permissions code. The size of the model tells you little about any of these application failures.
To compare two systems, replay the same saved questions with identical document versions and record more than final answers. Include whether the right passage was retrieved, whether its claims made it into the response, and the elapsed time. This separates the cost and quality of each stage and gives the next experiment a specific target.
Which component would store the active tool result between steps?
The application or workflow state. A model can see that result if the application includes it in a later request.
Which decisions belong to the model and which belong to its harness?
An assistant must compare two versions of a contract. In a fixed workflow the program fetches both versions, computes a text diff, asks a model to explain it and checks the quoted lines. In an agent loop the model can propose another search, select a section to inspect or finish. The harness is the program that supplies tools, stores results, checks permissions, enforces a step or cost limit and decides whether a proposed action will run.
Trace one failure. A later step quotes the wrong revision. Examine the tool arguments, the returned revision, the excerpt inserted into context and the quoted span in the answer, in that order. The first point where the expected ID changes identifies a different repair. A larger model cannot recover a document that the harness never delivered unless it can request that document and the request is permitted.
Trace where a request spends its time →
Sources · Anthropic, 2024