# Build a pipeline you can afford

Lesson 12 · Ship

Put budgets, retries, caching, and offline boundaries around the production pipeline.

## Outcomes

- Estimate cost and latency per pipeline stage before running it at scale.
- Add cache keys, retry ceilings, and deterministic fallbacks.
- Distinguish development-time generation from optional runtime calls.

Prerequisites: Lesson 11 and a layered evaluation suite.

Deliverable: A costed pipeline manifest and one full Signal Garden production run.


## Cost is a design constraint

An AI-assisted pipeline spends more than money. It spends developer attention, wall-clock time, context, review effort, and failure tolerance. Estimate those before multiplying a prototype across hundreds of assets.

For each stage, record unit count, calls per unit, input size, expected output size, model or local tool, retry ceiling, and human review minutes. Use current prices from your chosen provider at planning time; do not bake a course example into production assumptions.

Track actuals beside estimates. The gap reveals hidden retries, oversized context, and review work that a token-only budget misses.

## Map the Signal Garden pipeline

| Stage | Runs when | AI required? | Failure behavior |
| --- | --- | --- | --- |
| relay data validation | every data change | no | reject file |
| map generation/checks | development or build | no | reject seed |
| field-note drafts | development | optional | keep authored draft |
| tone review | development | optional | queue human review |
| repair reaction | runtime extension only | optional | show local fallback |

The base game ships with validated data and authored reactions. Development-time generation can be rerun deliberately. Runtime calls have tighter latency, privacy, moderation, and availability requirements, so use them only where variation visibly improves the experience.

## Bound every variable loop

Retries need a ceiling and a reason. Retry transient transport failure once or twice with backoff. Do not retry a semantic violation unchanged. A refiner may receive the exact error, but it still stops after the contract limit.

Cache immutable results using a key derived from input hash, contract version, model/version, and relevant settings. A cache without versioning can return output made under old rules. Never cache private player input without a retention policy.

Set a wall-clock timeout as well as an attempt limit. Three stalled calls are not meaningfully bounded if each can wait forever.

## Keep context and output small

Send the relay state and tone excerpt needed for one reaction, not the whole project. [Context engineering guidance](https://www.anthropic.com/research/effective-context-engineering-for-ai-agents) treats context as something to select deliberately. Require structured output where integration needs it, while retaining semantic validation as described in the [Structured Outputs guide](https://developers.openai.com/api/docs/guides/structured-outputs).

Smaller or local models may suit narrow development tasks, but benchmark them on your fixtures rather than assuming “small” means adequate. A deterministic script is cheaper and more reliable when rules are already expressible in code.

## Failure modes and tradeoffs

**Prototype multiplication** prices one successful call and ignores volume, retries, and review. **Infinite repair** spends more trying to rescue weak output than rewriting it. **Cache confusion** serves stale results after a style or schema update. **Runtime dependency creep** moves essential instructions into generated dialogue.

Budgets reduce exploration, but unlimited exploration rarely creates proportionate value. Reserve a small experiment budget and a separate production ceiling. When the ceiling is reached, stop, inspect, and choose whether the task deserves more investment.

## Build task: run the manifest

Create a manifest for one complete production pass: three relay records, three field-note drafts, one map batch, and all validators. Estimate best case, expected case, and ceiling. Run it once, record actuals, then update the estimate. Force one failure to prove the retry and fallback paths.

```text
Audit this Signal Garden pipeline plan for cost and failure risk.
For each stage, identify unit volume, variable-cost action, retry ceiling,
cache key, validator, and fallback. Flag any essential gameplay step that
depends on a network or model call. Do not estimate vendor prices without
provided current rates. Recommend one simplification, not a new service.
```

## Completion evidence

The manifest is complete when every variable-cost stage has a ceiling, every retry has a classified reason, and the offline game remains complete at zero runtime calls. Compare estimated and actual counts, time, and review effort. The run log and checkpoint should make the pass resumable, following the durable-artifact principles in [long-running harness research](https://www.anthropic.com/research/effective-harnesses-for-long-running-agents).



## Knowledge check

What is the safest response after a runtime dialogue call exhausts its retry ceiling?

1. Keep retrying until it succeeds.
2. Block the repair interaction.
3. Show the validated authored fallback and log the failure.

Answer: 3. Optional runtime generation must not block core gameplay; a known fallback preserves the offline contract.

## Further reading

- [Effective context engineering for AI agents](https://www.anthropic.com/research/effective-context-engineering-for-ai-agents) — Anthropic
- [Structured model outputs](https://developers.openai.com/api/docs/guides/structured-outputs) — OpenAI
- [Effective harnesses for long-running agents](https://www.anthropic.com/research/effective-harnesses-for-long-running-agents) — Anthropic

Sources checked 1 December 2026. Signal Garden is an original teaching scenario.
