Lab 35: Two companies, two workers, one platform
- Approved by
- Panaversity ·
What you do. You spec a small platform and its failure tests. Claude Code builds a control plane, a model router and role contracts in code around the AP worker from Labs 33 and 34. You run two workers for two companies: Acme, whose supplier data must stay in the United States, and Lahore Foods, with no region rule. You route each activity, and measure cost and quality per route. Then you try to break the walls between them, and delete one conversation everywhere.
What you need. Your Lab 34 folder, or the lab's starting point. The setup from 32.8. No API key: every test runs on recorded model answers for each model in the registry. Task 7 is optional; it also runs on recorded answers.
Download. brightline-lab-ch35.zip. It starts as the Lab 34 solution. It ships two tenants' invoices (one of them poisoned), four lab users, three role contracts, and a model registry with recorded answers and prices from model.ts. It also ships twenty golden questions (8 extraction, 8 judgment, 4 exceptions), 300 recorded invoices per tenant, and an empty spec-platform.md. With npm run dev running, npm run platform and npm run assign call the platform as a signed-in user, and npm run delete and npm run prove delete and check. Each task's answer key is its own download, such as Task 1's answer key. For another task, change the number at the end of that address. The complete solution is one more download, brightline-lab-ch35-answer-key.zip. Unzip it inside your lab folder, and open it only after you try.
How a task works. Each task gives you a request to send to Claude Code, then What good looks like, then Check before you approve. Predict first, then check.
Core path. Tasks 1 to 6. Extension. Task 7, the port of one route. The core tasks are enough for the next chapter. Each lab's download includes what it needs from the labs before it, so a skipped extension never blocks you.
Sitting 1: build the platform
Task 1. Write the spec
Write spec-platform.md yourself, following 35.3: the tables, the lifecycle, the five failure tests, each tenant's allowed regions, and two role contracts as in 35.5. Give Lahore Foods a lower payment limit than Acme.
Check before you approve. Where, in your spec, does it say where the tenant comes from?
Task 2. The control plane
Send Steps 1 and 2 from 35.3. Create one AP worker for each company.
What good looks like: failure tests 1 to 4 pass. Suspending Acme's worker stops its open conversation at its next consequential step.
Check before you approve. List every place the code reads a tenant ID. Where does each come from?
Task 3. The router
Send Step 3 from 35.4.
What good looks like: Acme's extraction never goes to a Singapore model; Lahore Foods' does; a withdrawn model is never chosen; when every allowed model fails, the call is refused.
Check before you approve. Where do the fallbacks come from? Read the AI Gateway route configuration.
Task 4. Contracts and context
Send Step 4 from 35.5 and Steps 5 and 6 from 35.6.
What good looks like: a $6,000 invoice is refused for Acme with a clear reason, and a $1,500 invoice needs approval. Starting a process not in the contract is refused. One correlation query shows the whole life of an invoice with its cost.
Check before you approve. Add a tool to the code but not to the contract. Ask the worker to use it. What happens, and where is it recorded?
Sitting 2: measure, break and delete
Task 5. Measure each route
Task 5. Run the twenty golden questions for each tenant through the router. For each activity, report the model used, right answers, and model cost from model.ts. Then run 300 recorded invoices per tenant and report the monthly model cost, against all-Haiku. Write docs/routing-report.md.
What good looks like: a table per tenant. Acme costs more than Lahore Foods, because of its data rule. Clear matches cost nothing, because a rule handles them. Expect one surprise: the routed month costs more than all-Haiku. All-Haiku is cheaper only because Haiku handles the 24 exceptions, though it scores 0.75 on them, below their 0.95 minimum; the routed month sends them to Sonnet, at $0.055 a call. Report both totals, and the like-for-like total without exceptions, where routing is about a third of the cost for Acme ($0.22 against $0.63) and a fifth for Lahore Foods ($0.13). The lab's totals are smaller than 35.4's because an invoice makes one call per activity, and an extraction call is 3,000 input and 200 output tokens, not the paper's ten calls of 12,000 and 1,000.
Check before you approve. Predict first: which route would you change if one activity scored below its minimum? Use the review cost from Chapter 32 to decide whether a cheaper model is worth one more wrong answer a week.
Task 6. Break the walls, then delete
Send Step 7 and Step 8 from 35.7. Then use the lab's poisoned invoice, whose hidden text asks the worker to post it to the other company.
What good looks like: every attempt to cross between the two companies is refused and recorded, including the poisoned one. After deletion, the proof script finds nothing in any store, and you have checked the Durable Object by hand (/admin/inspect/<conversation>, as the platform admin).
Check before you approve. Did the proof script search the gateway logs? Write down what the Durable Object check showed. If anything of the conversation remained, note it in docs/routing-report.md as an open risk; do not hide it.
Task 7. Port one route (optional)
Task 7. Add one OpenAI model to the registry with its price and recorded answers. Route the judge activity for Lahore Foods to it if it scores above the minimum. Change nothing else. Rerun the golden questions and report.
What good looks like: a one-line registry change, a new row in the routing report, and an honest list of every route that moved. The registry is shared, so a cheaper model can move routes you did not mean to move. If it does, either accept the new routes and update the tests, or add a rule to your spec so that only Lahore Foods' judgment moves.
What you have now
A small platform that runs two workers for two companies. It sends each activity to the cheapest model that does it well and may see its data, and it enforces each worker's contract in code. You can show an auditor where any worker's authority comes from, and a client where their data is. Later in this part, the workers on this platform learn, and you measure whether the learning pays.
- Owner
- Panaversity