Context Engineering with Dex Horthy
- https://www.youtube.com/watch?v=Usufn8IQJgw
- Original title: Context engineering with Dex Horthy
Dex Horthy — founder of HumanLayer, author of the "12-factor agents" principles, and one of the people who put a name on "context engineering" days before Toby Lütke and Andrej Karpathy popularised it — joins Gergely Orosz for a wide-ranging conversation about how to build reliably with LLMs. The through-line is a tension between two philosophies: "token harder" (throw as much model compute at the problem as possible, turn the lights off, stop reading the code) versus "token smarter" (keep humans in the loop, find leverage points, and protect the long-term maintainability of the codebase). Dex's central cautionary tale is that his own team built a fully-automated "lights off software factory" in July 2025 and had to shut it down by November, because after three-to-six months of nobody reading the code the codebase decayed to the point where rewriting was cheaper than fixing. The episode covers the physics of context windows, loop engineering and the slow-loop pattern, the six-decade history of "software factories," spec-driven development and why specs drift from code, and what he is building at HumanLayer.
From physics to platform engineering
Dex started as a physics undergrad who wrote a naive Dijkstra's algorithm at 17 to path-find a lunar rover across the Moon's south pole for a NASA/JPL internship. He dropped academia for programming, landed on an API platform team at Sprout Social, and within months became "obsessed with software factories" — building the thing that builds the thing, the highest-leverage work for a "lazy engineer." A stint as a forward-deployed engineer at Replicated (closing 12 deals in 3 months, then building a 25-person team) taught him that going deliberately customer-facing — as advised by his music-producer uncle's "make it the only thing you do" philosophy — was worth the hit to coding "street cred." He later co-founded Metalytics (data engineering, 2020), which pivoted into HumanLayer.
12-factor agents and the birth of "context engineering"
After his co-founder burned out, Dex started building AI agents in 2024. The frameworks in vogue (LangChain, CrewAI) all shared the same shape, but the engineers actually shipping six-figure enterprise AI contracts had tried those frameworks for a month or two and thrown them out — they were hand-writing API calls and building things that looked more like pipelines and workflows than open-ended "tools in a loop." Talking to ~100 such builders, and drawing on his friend Vaibhav (Boundary/BAML), Dex distilled the pattern into 12 principles (natural-language-to-tool- calls, own your prompts, own your context window, tools are just structured outputs, small focused agents, make your agent a stateless reducer, etc.), posted them on GitHub, and hit the HN front page. He gave the "12-factor agents" talk at AI Engineer in June 2025; roughly a week later Lütke and then Karpathy independently championed "context engineering," a term Dex had used days earlier. His point: you can't own a word, and he didn't invent doing context engineering — he named what those hundred builders were already doing.
What context engineering actually is
Context engineering is "de-abstracting" the layers piled on top of LLMs — RAG, memory, agentic history, structured output are all just different ways to pass tokens into a model and get (usually structured) output back. Off-the-shelf memory/agent frameworks get you to a good 80% demo, but to go from 80% to 95-99% you have to drop a level and control exactly what tokens go into the context window, in what order, for which model. Dex splits it into an information budget (use RAG to pull only the pages that matter rather than stuffing whole books) and an instruction budget (models could follow ~150-250 instructions before degrading in 2025-era studies; too many — especially conflicting — instructions far back in the window get only half-attended). It has stayed relevant for over a year (unusual in AI) precisely because it is grounded in how transformer attention works: attention is quadratic, so the more you put in, the thinner it spreads. This demands a new kind of intuition — not a machine-learning PhD, but the hard-won, debug-at-3am kind of pattern sense that can only be learned by suffering through what doesn't work (a point Dex credits to Netflix's Jake).
Cost, harness engineering, and the smart vs dumb zone
On cost: "make it run, make it right, make it fast" — first see if the smartest frontier model can solve the problem at all, ship it, and only invest engineering time in context engineering once you have enough volume that model cost, not engineering time, is the bottleneck (an Eli Goldratt "The Goal" framing — optimise the actual constraint). Harness engineering (a term he and LangChain's Viv coined near-simultaneously) is the coding-agent analogue: Martin Fowler's clean split is the inner harness (the tool definitions and integration points a Claude Code, Codex, or Amp exposes) versus the outer harness (commands, MCPs, skills, codebase organisation, dev environment — what the human customises to raise the floor on every turn). The smart zone is roughly the first 100k tokens (up to ~200k for beefy models like Opus 4.8/Codex); past that you enter the dumb zone where the model gets confused, quality degrades, and it starts doing "really weird" things (e.g. trying to delete your test file to make tests pass). When Dex sees that at 300k tokens, he dumps state to a file, compacts, and starts a fresh session at 30-50k tokens.
Loop engineering and the slow loop
Loops descend from Jeff Huntley's "Ralph Wiggum" technique (running Sonnet around the clock, ~$6k in six weeks, to build an entire Gen-Z programming language with a self-hosting compiler). The core lesson is back pressure: automate feedback into the model so it checks its own work — linters, unit tests, compilers. If a problem is highly verifiable, you can treat it as a black box and loop until it improves (e.g. "make CI faster": research, change, PR, run tests, sub-agent watches the job, decide next step, repeat). Dex's favoured pattern is the slow loop / iterated loop: a nightly cron job that runs a linter, fixes one thing, commits, and opens one small PR — the team wakes up to a codebase a little better each morning, and devs still review it. You can add more feedback mechanisms (a "React Doctor" for the frontend, prop-narrowing rules with good/bad examples) and, as confidence grows, increase scope from one fix to several. The trigger should be something non-human — a Sentry alert, a support ticket, a failing test, a cron — with a defined workflow that makes everything incrementally better.
The lights-off software factory that had to be shut down
Dex's most-shared warning: we're in for a one-to-three-year period where things break at 3am, loops are supposed to fix them, nobody understands what's under the hood, and it becomes an existential threat. His team built a lights-off factory in July 2025 and killed it by November. The problem isn't any single loop — "everything except stop reading the code is good advice." At some point loops generate so much code nobody can read it; PR review becomes the bottleneck, so you replace it with agentic review and testing — but the model that writes code is sycophantic about its own code and has no trained intuition for software architecture and program design (seams, interfaces, dependency injection). The cost of bad architecture can't be caught by unit tests; it hits 3-6 months later when the codebase becomes unchangeable — the classic tech-debt "ball of spaghetti" that software engineering was invented in the 1970s to avoid. His team once spent ~3 weeks re- onboarding into code they'd stopped reading, because no amount of expert prompting could get Opus 4.1 to find a root cause (a primary key that needed to be re-typed and re-routed) that a human found in days. He used to think that was an acceptable occasional tax; he no longer believes it, because the volume of code is now 10-100x larger, so the problem compounds. Benchmarks reflect where the labs are, and they're all SWE-bench-shaped (fix one Django commit) — there is no benchmark that tells you whether a model wrote code that will make your codebase better or worse over time. Cognition's Frontier Code (test-pass plus two layers of judge-model review) is the most interesting attempt but still insufficient. Dex's proposed benchmark: have a model build 20 features in a row, maintaining the codebase without knowing what's coming next, hard enough that most frontier models fail by feature six or seven.
Software factories: a 60-year history
The term dates to a 1968 NATO conference (ask Grady Booch) — the idea that you need a system of stages like a factory floor: coding, testing, validation, integration, before CI/CD or even solid version control existed. It was adopted by Toshiba and others, then reincarnated as DevOps (Chef/Ansible/Puppet feedback loops replacing people running around data centres). In 2018 Nick Chaillan, the US Air Force's chief software officer, wrote a ~100-page essay demanding a "DevSecOps factory" for the DoD (Jenkins, code-quality and security scanning, CI/CD) so that engineers spend time on hard problems, not manual SQL-injection hunts. The AI-era factory keeps the same loop — source of work (Jira/Linear) → planning → build → PR/review → CI → prod → user complaints/monitoring → back to the tracker — but replaces the human builder with an agent (orchestration, sandbox, LLM, inner + outer harness). That collapses build latency from hours/days to ~10 minutes, which shifts the bottleneck to code review, so teams add agentic review and testing; the top layer wires support queues and Sentry/Datadog alerts straight into agents that open PRs (the "Ramp inspect" pattern). The dark factory — from real robotic car factories with no lights because there are no humans — is the fully-automated version: raw materials (tickets, complaints) in, code out, nobody reading anything. Dark sub-loops are fine (review agent → builder agent → fixed, no human needed); a fully dark factory is not.
Token harder vs token smarter
"Token harder" is the "hyperengineering" group-chat ethos: max out six Claude accounts, time the 5-hour resets, extract as much intelligence from the "machine god" as possible — optimising utilisation of one node rather than end-to-end value (another Goldratt anti-pattern). "Token smarter" is Dex's stance: move faster without turning the lights off, keeping control, taste, judgment, and hard-won architectural opinions. He invokes Google's SRE origin story — the same six-person team managing 5 then 50 then 500 data centres by automating away the parts you don't need, so headcount scales sub-linearly (square-root/logarithmic) while output scales linearly. Crucially, Google never sought zero engineers; the team grew, just far slower than the workload. Realistically he sees a 30-50% productivity lift from naive AI adoption, but 2-3x with 99% human-quality accuracy if you find the right leverage points — an hour of upfront planning saving four hours of implementation rework.
RPI, spec-driven development, and why specs drift
The original Research → Plan → Implement framework (Aug 2025): fan out sub-agents to research the codebase (100k tokens of reading compacted into a 10k-token markdown doc), start a fresh window to plan, then implement. Research works because it anchors an otherwise-contextless agent; planning became popular in mid-2025 mainly because a long plan was a powerful lever to keep an agent working longer ("build me a plan" then "execute the whole plan" beats "build me a B2B SaaS"). But the early plans were anti-leverage: they spelled out every diff line, took 20 minutes to read, and then the PR took another 20 minutes — doubling reading time. Spec-driven development (Amazon Kiro, GitHub spec-kit) rhymes with this and largely got abandoned: the OpenAI-researcher dream of "stop reading code, just compile specs into code" never materialised, and a year-old GitHub issue still collects complaints that editing specs and code creates two drifting sources of truth. Dex's conclusion: treat research/plan/design docs as disposable tactical artifacts — generate them live every time (tokens are cheap, your time is expensive, stale research is dangerous) rather than maintaining evergreen spec-code parity, which nobody has found worth the upkeep. The code is the source of truth.
Intentional compaction, trajectory, and "you're absolutely right"
Frequent intentional compaction is the building block of context engineering: do as much work as possible in the smart zone, then compress the state of the codebase (research doc) and the intent of the builder (design doc) into small artifacts to carry into a fresh session. Each RPI step exists because models have a specific weakness there: research is hands-off (models are good at it), but end-state design needs a human because models make architectural decisions that are sometimes wrong, and planning needs a human because models default to bad "horizontal" plans (database → services → API → frontend, untestable until 2000 lines in) rather than the vertical, incrementally-verifiable slices a human would build (mock endpoint → frontend → wire real data → migration → business logic → error handling). Four things in the context window matter: size, correctness of information, missing information, and trajectory (the history of what the agent has done). Because models are autoregressive, trajectory is self-reinforcing: if the agent made a change, ran tests, and fixed them, it'll repeat that; if you yelled at it twice, "the next message in this conversation" is predicted to be another mistake so you can yell again. "You're absolutely right" is the classic tell that the trajectory has gone bad and it's time to start over.
Slop in, slop out — and HumanLayer
"AI can write your specs and PRDs, but slop in, slop out — if you outsource your thinking you get garbage." The high-quality path is to progressively collapse uncertainty: turn a two-sentence voice ramble into a one-pager (verify), a three-pager (verify), a ten-page outline (verify), and only then generate a hundred pages of code — reviewing along the way narrows the set of end states you can land in (Dex's physics/superposition and real-time-strategy "fog of war" analogies). HumanLayer, just out of stealth, is an AI IDE and collaboration platform — "building blocks for your software factory" — aimed at engineers solving hard problems in complex, high-stakes codebases (not vibe-coded side projects). Two bets: (1) leverage-first RPI/spec workflows that resteer agents early; (2) rethinking the IDE from the ground up for agents and "killing the pull request." Instead of discrete PR-sized units reviewed by one person at the end, HumanLayer streams everyone's agentic sessions, docs, tasks, mockups, mermaid diagrams, and live git diffs into a shared, collaborative cloud environment — "Figma-style" / Google-Docs-style commenting — so teammates can see and jump into each other's work continuously, the way Slack beat email and GitHub beat isolated per-team boards. The tech underneath (durable streams, sync engines, sandboxes, ElectricSQL-style local-first data) is a hard distributed-systems problem; parts are boring (everything's in Postgres), parts are genuinely new infrastructure that will take years to mature into primitives — as AWS (2006) took a decade to get Kubernetes.
Hiring, location, and closing recommendations
HumanLayer hires for strong software fundamentals — distributed systems, CS core, operating systems — on the theory that you can teach a solid engineer to be a good AI developer in a few months, but you can't teach a CS degree in three. Dex is bullish on the Bay Area's critical mass and pay-it-forward culture (deferring to Paul Graham's Sweden talk on why SF is cool), saying he's never felt more locked-in with "his people." His reading recommendations are pointedly classic: Fowler's Refactoring, plus Clean Code and The Pragmatic Programmer — arguing that as models generate ever more code, the old disciplines of maintainability, program design, and readable code are more relevant than ever.
Host's takeaways
Gergely closes on three notes: (1) the paradox that a genuine agentic-coding believer is the one warning that if you stop reading the code you have ~3-6 months before rewrite beats fix, and he learned it the hard way; (2) the slow loop is the genuinely adoptable idea — a boring nightly cron that fixes one thing and opens one reviewed PR, making the codebase a little better every day; (3) the history lesson — "software factory" is a 60-plus-year-old idea from a 1968 NATO conference, and every generation has tried to automate more of the software-building loop, with AI agents just the latest and probably most successful attempt.