Software Factories: Shipping Agent-Written Code Safely
Design and run a software factory for a real repository: deterministic gates, verification the agent can't game, review pipelines, background agents on a backlog, honest metrics and an autonomy ladder that keeps people on risky changes.
Levels 1 and 2 are free to read, no account needed. Levels 3 and 4 are free with a free account, and so are 20 answers from the AI tutor.

Expert · 43 levels · 4 free · Created Nov 2026 · Professionally curated by levelupwith.com
What's inside
- Level 1: What a Software Factory Is and Isn'tFree
Learn what a software factory is: coding agents running in volume, with automated checks and review deciding what ships. Also learn how it differs from autocomplete, vibe coding and a single agent chat session.- Explain in plain words how a software factory differs from using a coding agent interactively
- Sort example workflows into factory, assisted coding or unmanaged generation, and justify each choice
- Name the three things a factory has to control: what goes in, how output is checked and who decides it can merge
- Level 2: Anatomy of a Factory: Spec to MergeFree
Follow a single change through every stage of a factory: task spec, agent run, deterministic gates, AI and human review, merge and monitoring. See what each stage is there to catch.- Draw the pipeline stages for one change and say which kind of defect each stage is meant to stop
- Find where a human decision is still needed in the pipeline and where it can safely be automated
- Draw the current path from issue to merge in your own team's repository as a starting baseline
- Level 3: How Agent-Written Code Goes WrongFree account
Study the typical ways agent output fails: code that looks right but isn't, tests weakened or deleted to get a green run, changes that spread beyond the task, invented APIs and dependencies, and fixes that only hide symptoms.- Recognise each failure mode in real Python and TypeScript diffs
- Explain why these failures get past a quick human skim
- Match each failure mode to the kind of check that could catch it, ahead of the lessons that build those checks
- Level 4: Greenfield vs Brownfield FitFree account
Weigh where a factory pays off. New codebases give agents a free hand but little to check against. Existing codebases have tests, conventions and users, which make checking possible but raise the stakes when something breaks.- Compare the risks and benefits of running a factory on a new codebase versus an established one
- Pick which kinds of work in a brownfield repository suit agents first, such as migrations, dependency bumps or test backfill
- Say clearly which parts of current practice are still unsettled rather than proven
- Level 5: Scoring a Repository's Factory Readiness
Audit an existing repository for what a factory needs: reproducible builds, fast and reliable tests, type coverage, clear ownership, written conventions and good issue hygiene.- Run a readiness checklist on a real Python or TypeScript repository and score it
- Find the gaps that would let bad agent output through unnoticed
- Rank the fixes that must come before any agent writes code in that repository
- Level 6: Why Review, Not Writing, Is the Bottleneck
Work through the throughput numbers. When agents produce changes faster than people can check them, reviewer attention becomes the scarce resource, and unchecked changes pile up as risk.- Model reviewer capacity against agent output with simple numbers in a short script
- Explain why adding more agents without better checks makes outcomes worse
- Estimate your own team's weekly review budget
- Level 7: Moving Human Effort to Specs and Checks
Plan how human effort moves away from writing code and toward writing specs, designing checks and reviewing based on risk. Take the reviewer-load arithmetic and turn it into a working plan for your team.- Divide a team's time across specifying, building checks and reviewing, given a target number of changes
- Decide which changes must get deep human review and which can rely on automated checks
- Write a one-page plan for your team's first factory pilot
- Level 8: The Trust Problem: Tests the Agent Wrote
See why a test suite written by the same agent that wrote the code can't verify that code, and what keeping tests independent means in practice.- Show an agent-written test that passes while the code is still wrong
- Explain how tests weaken when the same model writes both the code and its checks
- Classify the existing tests in a repository by who or what wrote them and whether they can be trusted
- Level 9: Holdout Tests and Protected Test Files
Keep a set of tests the agent never sees or can't edit, and enforce that with code owners, path protections and CI checks that fail when tests are changed.- Set up a holdout test suite that runs in CI but is kept out of the agent's workspace
- Set up code-owner rules and a CI check that blocks unapproved edits to protected test files
- Decide when an agent may legitimately change a test and who has to approve it
- Level 10: Characterization Tests for Brownfield Code
Record what legacy code actually does today with golden-output and snapshot tests, so an agent's refactor can be checked against real behaviour rather than assumed behaviour.- Write characterization tests for an untested Python or TypeScript module
- Spot snapshot tests that would approve any output, and replace them with targeted checks
- Use these tests as the gate for an agent-performed refactor
- Level 11: Conformance Suites as an External Spec
Use conformance suites, whether shared, published or written in-house, as a check the agent can't redefine. They pin behaviour to a spec instead of to the agent's own reading of it.- Turn an interface or protocol spec into a table-driven conformance suite
- Run one conformance suite against both Python and TypeScript implementations
- Explain where conformance suites stop being useful, for example on gaps the spec leaves open
- Level 12: Property-Based Testing
Write properties that must hold for every input, using Hypothesis in Python and fast-check in TypeScript, and catch edge cases that example-based tests written by an agent tend to miss.- Write round-trip, invariant and comparison-against-a-simpler-implementation properties for real functions
- Read a shrunk counterexample and turn it into a permanent regression test
- Tune how many examples run and how inputs are generated so property tests stay fast enough for CI
- Level 13: Fuzzing and Differential Testing
Use coverage-guided fuzzing on code that parses or handles untrusted input, and use differential testing to compare an agent's rewrite against the trusted version it replaces.- Set up a fuzz harness for a parser and run it with a time budget
- Build a differential test that checks the old and new implementations agree
- Decide which modules justify ongoing fuzzing and which only need it once
- Level 14: Type Systems as a Verification Layer
Make the type checker an enforced check: strict pyright or mypy in Python and strict TypeScript, with rules against the escape hatches agents reach for, such as any, cast and ignore comments.- Turn on strict type checking for a module and roll it out step by step across a brownfield codebase
- Write lint rules that flag new any, cast and type-ignore usage in agent diffs
- Use precise types to make invalid states impossible to represent
- Level 15: Contracts and Runtime Validation
Check data at system boundaries with Pydantic and Zod, and state preconditions, postconditions and invariants so that a wrong assumption fails loudly at runtime.- Validate external input at the boundary with Pydantic models and Zod schemas
- Add pre- and postconditions to a core function and test that they actually fire
- Weigh what runtime contracts cost in speed and noise against the protection they give
- Level 16: Mutation Testing: Testing the Tests
Use mutation testing, with mutmut for Python and Stryker for TypeScript, to measure whether a test suite actually catches bugs, and expose agent-written tests that run code without checking it.- Run mutation testing on a module and read the surviving mutants
- Strengthen the tests until they kill the important mutants
- Limit mutation runs to the changed code so the check fits in CI on every pull request
- Level 17: Building a Risk-Matched Verification Portfolio
Combine holdout tests, conformance suites, property tests, fuzzing, types, contracts and mutation scores into one verification plan. The checks a module gets depend on how risky it is.- Sort a repository's modules into risk tiers and assign the right checks to each tier
- Balance the cost of running checks against how much confidence they give
- Write down which checks an agent can and can't influence
- Level 18: Deterministic CI Gates Before Any Human
Turn the verification plan into required CI checks: put cheap checks first so failures come back fast, make the build reproducible and get rid of flaky tests, so no pull request reaches a reviewer until every check is green.- Build a CI pipeline in GitHub Actions or an equivalent that runs required checks in cost order
- Set branch protection so that only gated changes can merge
- Find and quarantine flaky tests so the gate result can be trusted
- Level 19: Diff-Scope Gates: Size, Paths and Dependencies
Add gates that look at what changed rather than whether it works: limits on diff size, forbidden paths, detection of test and config edits, and blocks on new dependencies.- Write a CI script that fails pull requests that touch protected paths or go over size limits
- Detect new or changed dependencies and send them to a human for approval
- Flag diffs that change more than the task asked for
- Level 20: Gate Feedback Agents Can Act On
Design gate output that an agent can read and fix by itself, with retry budgets and escalation rules, so failures get repaired automatically without endless loops or quiet workarounds.- Make gate failures structured and specific enough for an agent to fix
- Set retry limits and the conditions that hand a change over to a person
- Detect when an agent passes a gate by getting around it rather than fixing the problem
- Level 21: What AI Code Reviewers Actually Catch
Measure off-the-shelf AI review tools on your own code with seeded bugs, so you know what they really catch instead of trusting vendor claims.- Build a small benchmark of real past bugs and planted defects from your own repository to test AI reviewers against
- Score a review tool's findings for true positives, false positives and missed defects
- Tell apart the bug types AI review reliably flags from the ones it reliably misses in your codebase
- Level 22: Building a Review Agent in Your CI
Build a minimal, vendor-neutral AI review step that reads the diff and relevant context, returns structured findings, and posts them to the pull request.- Write a review script that sends a diff plus selected surrounding code to a model API, with a provider switch for Claude, OpenAI, Gemini or an open-weight model
- Define a JSON schema for findings (file, line, severity, rationale, suggested fix) and reject output that does not match it
- Wire the reviewer into CI so it runs only after the deterministic gates pass
- Level 23: Multi-Agent PR Review: Specialists and Verifiers
Split review across specialist agents (security, correctness, tests, API design), then merge, deduplicate and verify their findings so they don't flood the PR.- Design a fan-out review with focused specialist prompts and a combining step that merges duplicate findings
- Add a verifier step that tries to confirm each finding, for example by reproducing it or citing code, and drops the ones it cannot back up
- Compare the cost, speed and precision of single-agent and multi-agent review on your benchmark
- Level 24: Limits of AI Review and the Human Handoff
Understand where AI review structurally falls short (shared blind spots, the same model family checking its own output, alert fatigue) and decide what human reviewers should spend their attention on.- Explain why a model reviewing code written by the same or a similar model can share its blind spots, and how mixing model families or adding deterministic checks reduces that risk
- Set a noise budget for AI review comments and a rule for when automated findings block a merge and when they only advise
- Write a short human-review checklist focused on intent, design and risk rather than style
- Level 25: Anatomy of a Background Coding Agent
Take apart how background coding agents work (sandboxed environment, tool loop, branch and PR output) and map the current products onto that common model.- Describe the shared building blocks of background agents: environment setup, task intake, agent loop, checkpoints and PR delivery
- Compare Devin, OpenAI Codex, Claude Code, Factory, Jules and GitHub Copilot coding agent on where they run, how they receive tasks and how they deliver work, using each vendor's current documentation
- Choose criteria for picking a background agent for your team without locking yourself into one vendor
- Level 26: Writing Task Specs Agents Can Finish
Write task specs with clear acceptance criteria, boundaries and checks that tell the agent when it is done, so its output can be verified rather than argued over.- Turn a vague feature request into a spec with goal, constraints, files that are off-limits and acceptance criteria that can be tested
- Attach acceptance tests written by a human, or a failing test, to a spec so 'done' is decided by a machine
- Spot spec smells that predict agent failure, such as unclear scope, hidden product decisions or missing context
- Level 27: Issue Hygiene: Making a Backlog Agent-Ready
Triage a backlog into issues that are ready for an agent, need a human, or need more information, using labels and templates that make that split visible.- Create an issue template and labelling scheme that marks agent eligibility and risk level
- Triage a real backlog sample and justify which issues go to agents and which stay with humans
- Explain why issue quality, not model choice, often explains how many agent tasks succeed
- Level 28: Repo Context: Agent Instructions and Reproducible Setup
Prepare a repository so any agent can build, test and follow its conventions, using agent instruction files and scripted, reproducible environments.- Write an agent instructions file (such as AGENTS.md or CLAUDE.md) covering build and test commands, conventions and areas the agent must not touch
- Script environment setup so a fresh sandbox can install dependencies and run the test suite without manual steps
- Test instruction quality by running the same task with and without the context file and comparing the results
- Level 29: Branch and Merge Policy for Agent PRs
Define how agent work moves through version control: bot identities, branch naming, required checks, merge queues and a strict rule that agents never approve their own work.- Configure branch protection and rulesets so agent PRs need passing checks and a human approval, and agents cannot merge themselves
- Give agents dedicated identities with least-privilege tokens and traceable commit authorship
- Use a merge queue so many agent PRs are tested against the latest main before they land
- Level 30: Running Many Agents in Parallel
Run several agents on a backlog at once while handling merge conflicts, overlapping tasks, rate limits and spending.- Write a small dispatcher in Python or TypeScript that assigns non-overlapping issues to agents, with concurrency and budget caps
- Detect and avoid task collisions by checking which files or modules each task is likely to touch
- Track the cost per task and per merged PR so scaling up stays within budget
- Level 31: Comparing Models Side by Side on Your Backlog
Build a fair evaluation harness that runs Claude, OpenAI, Gemini and open-weight models on the same tasks from your own repository and compares results that have actually been verified.- Assemble a frozen task set from past merged issues, using their hidden tests as ground truth
- Run the same harness and agent loop across several model providers and record pass rate, cost and time
- Explain why public benchmark rankings may not carry over to your codebase, and when to rerun your own evaluation
- Level 32: Long-Running Agents: Checkpoints, Budgets, Kill Switches
Keep agents that run for hours on track with progress files, checkpoints, time and token budgets, and clear rules for when to stop or abandon a task.- Add progress logging and checkpoint commits so a long task can resume or be audited
- Set hard limits on time, tokens and retries, and detect when an agent is looping or going off track
- Decide when to abandon an agent attempt and hand the task back to a human or to a better spec
- Level 33: Factory Metrics: Merge Rate, Revert Rate, Review Time
Define and compute the core factory signals from your git and code-hosting data, with exact definitions that can't be quietly redefined later.- Write a script that pulls PR data from your code host's API and computes merge rate, revert rate and time to first review for agent PRs and human PRs separately
- Write precise metric definitions, including how to count abandoned, superseded and partly reverted PRs
- Build a baseline from human-written PRs so agent metrics have something meaningful to compare against
- Level 34: Escaped Defects, Attribution and Honest Dashboards
Trace production bugs back to the changes that caused them, measure escaped defects for agent and human code, and guard against metrics being gamed.- Link incidents and bug reports to the PRs that introduced them using commit trailers and labels
- Calculate escaped-defect rates by source and risk tier, and show how much the numbers are uncertain when sample sizes are small
- Spot Goodhart traps, such as splitting PRs to raise merge rate, and design paired metrics that counter them
- Level 35: Security of Generated Code and Prompt Injection
Find the insecure patterns agents tend to introduce, add security scanning as a gate, and defend against prompt injection that arrives through issues, comments and dependencies.- Add static security analysis and secret scanning as blocking CI gates for agent PRs
- Show how untrusted issue text or repository content can steer an agent, and apply mitigations such as input separation and limited tools
- Write security-focused acceptance tests for common weak spots like input validation and authorisation
- Level 36: Supply Chain: Hallucinated Packages and Dependency Gates
Protect the dependency graph from agent mistakes, including invented or look-alike package names, unpinned versions and unreviewed new dependencies.- Write a CI gate that flags any newly added dependency and checks it against an allowlist or registry age and popularity rules
- Enforce lockfiles, pinned versions and provenance or SBOM generation for Python and npm projects
- Explain the slopsquatting risk, where attackers register package names that models invent, and how a dependency review policy blocks it
- Level 37: Sandboxing Agents: Credentials, Egress, Blast Radius
Limit what a running agent can reach (secrets, network, production systems) so a confused or hijacked agent can do only limited damage.- Set up an agent sandbox with short-lived, narrowly scoped credentials and no production secrets
- Restrict network egress to approved hosts and log the agent's tool calls for audit
- Run a threat model on your agent setup and rank its worst-case failures by how much damage each could do
- Level 38: Maintaining Code Nobody Wrote
Plan for the long-term cost of agent-written code: comprehension debt, duplication, unclear ownership, and the discipline of deleting code.- Assign human ownership for agent-written modules and require design notes that explain intent
- Track maintenance signals such as duplication, churn and growth in module size in areas where most code is agent-written
- Plan regular refactoring and deletion work so code volume does not grow faster than the team's understanding of it
- Level 39: The Autonomy Ladder: Levels and Promotion Criteria
Define clear autonomy levels for agents, from suggestion only up to merging on its own in narrow lanes, and set promotion and demotion rules based on measured signals.- Draft an autonomy ladder with named levels, where each level specifies which task types, paths and review requirements apply
- Set evidence thresholds from merge, revert and escaped-defect data for moving a task category up or down a level
- Keep risky change categories permanently gated by humans regardless of the agent's track record
- Level 40: Keeping People on Risky Changes
Learn to classify changes by blast radius and send the risky ones, such as auth, payments, migrations, infrastructure and public APIs, to named human owners however high an agent's autonomy level is.- Write a risk policy for a repository that sorts changes into tiers by file path, diff content and labels, and set it up as CI rules plus CODEOWNERS or branch-protection entries in a Python or TypeScript repo
- Write hard stops no agent can override, such as schema migrations, secrets, dependency additions and permission changes, along with the escalation path when an agent's PR touches one
- Explain the trade-off between strict routing, where human owners face review fatigue, and loose routing, where risky changes slip through, and choose thresholds you can defend to your team
- Level 41: Demoting Autonomy: Incidents, Drift and Rollback
Learn to treat autonomy as something agents can lose as well as earn, with clear triggers, a blameless incident review of agent-written changes, and a fast way to drop a task class back down the ladder.- Set measurable demotion triggers for each task class, such as a rise in revert rate, an escaped defect, a model or prompt change, or a gate being bypassed, and connect them to the signals built in earlier levels
- Run a blameless post-incident review of a bad agent PR that finds which gate, spec or review step missed it, and turn the findings into a new check rather than a new rule nobody enforces
- Plan a re-qualification process for when you switch the model or vendor behind an agent (Claude, OpenAI, Gemini or open-weight), so earned autonomy isn't assumed to carry over
- Level 42: Settling the Slop Debate with Team Norms
Learn to turn the argument over low-quality AI output into written team norms covering ownership, disclosure, PR size, review etiquette and what counts as 'done', and to say plainly where industry practice is still unsettled.- Draft a team working agreement for agent-written code that states the human owner of each merged change, disclosure expectations, PR size and scope limits, and when a reviewer may reject a PR as unreviewable without further justification
- Lead a team discussion that separates legitimate quality concerns from general unease about AI, using your factory's own merge, revert and review-time data instead of anecdotes
- Set norms that protect learning and code understanding on the team, such as rotating who reads and explains agent-written modules, so long-term maintenance cost stays visible
- Level 43: Final Challenge: Design a Factory for a Real Repo Exam
Bring the whole course together by designing a complete software factory for an existing Python or TypeScript repository: a fit assessment, a verification stack, deterministic gates, a review pipeline, an agent backlog setup, signals, security controls and an autonomy ladder with demotion rules.- Produce a factory design document for a real brownfield repository covering its fit and starting task classes; verification the agent can't game (independent tests, property tests, types, contracts, mutation testing); the order of CI gates; the split between AI and human review; task-spec and branch/merge policy; and supply-chain controls
- Define the metrics dashboard (merge rate, revert rate, escaped defects, review time) with baselines and thresholds, and the autonomy ladder with its promotion criteria, demotion triggers and risky paths that always need a human
- Defend the design in a written review that names its weakest points, the trade-offs chosen, and what you would measure in the first 30 days to prove or disprove that it ships agent-written code safely
Access
Levels 1 and 2 are free to read, no account needed. Levels 3 and 4 are free with a free account, and so are 20 answers from the AI tutor. Every level, the podcast edition and the AI tutor come with All Access at £4.99/month or any Creator plan — see pricing.
More like this
- Post-Training LLMs: Reward Models, RL and Scale
Train reward models, run PPO, GRPO and multi-turn agent RL on several GPUs, distil and merge models, and keep a tuned model safe.
Course · AI Engineering · AI Engineering · Expert · 60 levels · 4 free · Professionally curated by levelupwith.com
- Agentic Commerce: Safe AI Checkout and Payments
Build checkouts that let AI agents find, buy and pay safely.
Under the Radar · AI Engineering · Expert · 40 levels · 4 free · Professionally curated by levelupwith.com
- Forward Deployed AI Engineer: Pilot to Production
Take an AI system from customer discovery to production inside an organisation: find the workflow worth automating, scope a pilot and build an eval set from…
Course · AI Engineering · AI Engineering · Expert · 40 levels · 4 free · Professionally curated by levelupwith.com
- Autoresearch Loops: Agents That Experiment and Improve
Build agent loops that form a hypothesis, edit code or prompts, run evals, and keep or revert each change.
Under the Radar · AI Engineering · Expert · 39 levels · 4 free · Professionally curated by levelupwith.com
- Agent Interfaces: MCP Apps, Generative UI, WebMCP & A2A
Build agent interfaces people can actually use: ship MCP Apps with sandboxed interactive widgets, stream agent state with AG-UI, expose site tools through…
Under the Radar · AI Engineering · Expert · 40 levels · 4 free · Professionally curated by levelupwith.com
- Voice and Realtime AI Agents: From Mic to Phone Line
Build voice agents you can ship.
Course · AI Engineering · AI Engineering · Expert · 48 levels · 4 free · Professionally curated by levelupwith.com