Skip to content
The AI Agent Factory

Chapter 30. Shipping Claude Applications: Files, Surfaces and Resilience

Approved by
Panaversity ·
27 min read

Start here if you skipped Chapter 29

If you read Chapter 29, skip this. These are the words from it, and from the chapters before it, that this chapter builds on.

WordWhat it meansWhere this chapter uses it
WorkspaceA separate space on the platform for keys, resources and spending. Brightline has one for staging and one for production (23.4)Everywhere
Staging keyThe key your laptop uses. It reaches only the staging workspace, and it sits in .secrets/anthropic.env, a file git ignores (Lab 23, Task 0)The point, 30.1, 30.3
Lock fileThe record of which hosted resources, at which versions, belong to one workspace: claude-lock.staging.json for staging (23.4)30.1, 30.6
The hosted worker, its agent fileThe AP worker that runs inside Brightline's portal on a hosted runtime. Its instructions are in agents/ap-worker.md (23.4)30.1, 30.5
The portalBrightline's own product, one portal for every customer company. Its scheduled session runs at 7:10 each weekday (23.16)Everywhere
The extraction stepOne Messages API call for each new invoice, outside the hosted session. The portal's morning job makes it before 7:10, and gets the invoice's fields back as JSON (Lab 24, Chapter 25)Everywhere
The suite, a required checkChapter 24's cases, each with the answer Ana Morales expects. On every pull request, CI runs them on recorded answers, with no key. A required check must pass before a pull request can merge (24.3, 15.7)Everywhere
The suite's reportThe file each run of the suite writes. It names the model each case ran on (25.10), and, from Lab 30's kit on, the prompt version too30.4, 30.6
A named prompt version25.1's rule: "a prompt reaches production only as a named version that the suite has read" (25.1)The point, 30.5, 30.6
PinThe exact model id, written in one place, so the model changes only when you choose (21.13)30.4, 30.6
The SDK's retriesBoth SDKs retry some failed requests twice by default: connection errors, and statuses 408, 409, 429 and 500 and above. So the loop itself does not retry (21.9)30.4
Workload identityThe way CI proves who it is with no stored key (23.13)30.6
settingSourcesThe Agent SDK option that names which settings files a run loads. Lab 22's worker sets it to an empty list, so it reads no settings files (22.9)30.1, 30.5
Release planChapter 29's written decision about when a change, such as a newer model, goes out (29.5)30.6

The point

Monday, May 17, 2027. You are the builder. Today's change is one change, with two parts. Brightline's small vendors still send some invoices on paper, and Ana Morales, Brightline's AP analyst, photographs them. So the worker must now read scanned and photographed invoices. With them comes the extraction prompt's next version. Ana tried that version first in her own Claude project this morning, and she liked its answers.

On your laptop, everything works. [A photo] and [a PDF scan] each go up once. They go up through the Files API, Anthropic's store for files you upload once and then name by an id (30.3). The worker answers three questions about each. [INV-9103] is a photo in HEIC, a format the API does not take. It accepts JPEG, PNG, GIF and WebP.1 The worker's own check of the file's type refuses it before any request is sent, and a test proves that it does. The suite passes, [n of N].

This morning, before the change, you wrote docs/environments.md from what the repository already holds. It is one table. Each row is one thing that is set separately for each place the worker runs, in a file and not in the loop's code. Each column is one environment: a place where the same code runs, with its own keys, files and settings. Brightline has three. Development is your laptop. Staging is CI and the staging workspace, where the hosted agent's staging version runs (23.4) and the portal's staging copy calls it (Lab 23). Production is the portal every customer uses.

Each cell holds a value and its proof, which says how the value can be checked. A proof is one of three kinds. It can be a file and a key in it: the check, npm run check:environments, reads that key and compares it with the cell. It can be "by a person", and the check only lists the cell. Or it can be waiting: a file that a named later step makes. The check lists it, like a cell proved by a person, until the file exists, and then compares it. This chapter writes a file and a key in it as file#key, and [*] means every entry in a list.

When a pull request changes a file that a row's proofs name, the check fails on any empty cell in that row. This morning config/prompts.yaml named only a prompt version for staging and for production, and no file held rows 3 and 4 for them. So those four cells are empty. Row 3 says which workspace the file ids belong to. Row 4 says which models may answer.

Tuesday, May 18, 10:00 a.m. You open the pull request. The change touched data/file-ids.json and config/prompts.yaml, where it added each entry's model and fallbacks. Rows 3 and 4 name those files in their proofs. So the check fails on four empty cells.

At 10:40 you fill them, and the check fails twice more.

  • Row 3. Production's cell says "workspace: production", with its proof config/prompts.yaml#production.workspace. That key does not exist, so the check fails. Without it, the ingestion would read every id in data/file-ids.json, and every one says "staging". A file belongs to the workspace it was uploaded to, so in production those ids would answer 404, not found. The kit's recording in tests/fixtures/errors/ shows that answer.
  • Row 4. Staging's list of fallback models, the models to try when the pinned one is overloaded, names [a model] that you copied from an example. The suite's report has never named it. No case has ever run on it.

You set production.workspace to production. You make the ingestion read only ids whose workspace matches it, so production uploads its own files. And you drop the fallback until the suite has run on it. The check passes. The merge at [11:15] applies the change to staging. After a week of right answers to real questions in staging, a person applies it to production.

No test on your laptop could have seen either value. Your laptop uses the staging key, so every file id it made belongs to staging, and every id worked. The suite ran on the pinned model, so it never sent a request to the fallback. The loop's code was the same in all three places. What surrounded it was not.

You have met every piece of this before.

  • 12.7 asked it of the coding agent: "So check that each seat loads the rules and settings you intend."
  • 23.4 gave staging and production a workspace and a lock file each.
  • 25.10 said: "An answer from a model the suite never ran has passed no test."

The one new thing is the table and its check. This chapter asks 12.7's question of the worker.

So before you change anything else, answer one question. The extraction worked in Ana's Claude project and on my laptop. What is different about the same request in CI, staging and production, and how do I find out before Ana does?

Why it matters

Tests catch faults in the code. The table and its check catch values that differ by place. A value that nobody wrote down is not empty. A default fills it, and that is where the request breaks.

The rule is the same for every row. A value that differs between columns differs on purpose, in a file, with a proof. A cell equal to the one on its left says "same".

There is a price. A cell proved "by a person" is not checked. The check lists it, and someone must read it.

Figure 30.1. The table's heads. Each row is one thing set per place, in files. Each column is one environment. The chapter fills one row at a time.

How this chapter works

Read the eight concepts in order. Sections 30.1 to 30.5 each fill one row of the table. Section 30.6 fills row 6 and shows the whole table once. Section 30.7 shows row 6's gates on the pull request. Section 30.8 shows the products, Claude first, then OpenAI, then open source. Sections 30.3 and 30.4 each have two halves. The first half is what is the same in every environment. The second half is the row, what differs by place.

Some subjects belong to other chapters. Guardrails and prompt injection are Chapter 28's. The decision to move to a newer model is 29.5's, and cache breakpoints and batches are 29.7's and 29.8's. The settings order is 12.8's, and AI review of a pull request is 15.6's. This chapter points to each and does not teach it again. Running a worker reliably at scale goes further in Chapter 42.

What you will build

Who's who. You are the builder. Ana Morales is Brightline's AP analyst, who reads each morning's report. Dave Kowalski is Brightline's controller. Brightline Wholesale Supply is the invented wholesale distributor whose AP worker you have built since Chapter 16. Cedar Ridge Supply is Brightline's second customer in the portal.

Where you are. At the end of Lab 29 the worker runs in the portal. Its extraction step reads invoices that arrive as text, and the suite runs on every pull request. No file says which values differ between your laptop, staging and production.

What you build in Lab 30 takes three sittings, from tag ch29 to tag ch30. First come the table and its check. Then come files in, faults on purpose, one move for each class of error, a promotion to production, and a port to OpenAI.

As in Chapters 17 to 29, coding agents write every file and run every command. You specify, check and approve.

In this chapter

SectionThe question it answers
30.1 One model, many surfacesWho sends the request, and what does each surface add to it?
30.2 What crosses the application boundaryWhat leaves, what comes back, and what is kept, in each environment?
30.3 Images, documents and the Files APIHow do files go in, what goes wrong, and which workspace owns each id?
30.4 Errors by class: retry, fall back or fixWhich move fits each error, and which models may each environment end on?
30.5 Configuration that travelsWhich configuration does each run read, and what does a default load?
30.6 One change, three environmentsHow does one change cross the table, column by column?
30.7 Claude in CI and the release pipelineWhich checks hold a change on the pull request?
30.8 How today's tools realize itOn each product, what are the six rows?
Lab 30The table and its check, then files, faults, a move for each class, a promotion and a port, from tag ch29 to tag ch30
Check yourselfOne open question for each concept, with an outline of its answer
  1. Vision, Claude API docs, Anthropic.↑
Owner
Panaversity