Twelve engineering principles for LLM-powered software that is good enough to put in front of paying customers. Written by Dex Horthy (HumanLayer, April 2025), explicitly modelled on Heroku’s 12 Factor App. Source: 12-Factor Agents — Principles for Building Reliable LLM Applications.

The founding observation is deflationary:

Quote

“Most of the products out there billing themselves as ‘AI Agents’ are not all that agentic. A lot of them are mostly deterministic code, with LLM steps sprinkled in at just the right points to make the experience truly magical.”

Horthy names the pattern he is arguing against directly — Anthropic’s “here’s your prompt, here’s a bag of tools, loop until you hit the goal” definition of an agent (see Building Effective Agents). His claim is that the good ones “are comprised of mostly just software.”

The failure story the whole document is built on

From ~100 conversations with technical founders adding agents to existing SaaS products, the journey is always the same:

  1. Decide to build an agent
  2. Do the product design and UX work
  3. Grab $FRAMEWORK to move fast
  4. Hit a 70-80% quality bar
  5. Discover 80% isn’t good enough for a customer-facing feature
  6. Discover that getting past 80% requires reverse-engineering the framework’s prompts and control flow
  7. Start over from scratch

The 12 factors exist so that step 7 never happens. The prescription is not “don’t use frameworks” — it’s that the concepts are modular, and the fastest path to shipping is bolting individual factors onto software you already own rather than a greenfield rewrite around someone else’s abstraction.

The operative sentence

“The fastest way I’ve seen for builders to get good AI software in the hands of customers is to take small, modular concepts from agent building, and incorporate them into their existing product.”

This is the same argument as Fat Skills Fat Code Thin Harness arriving from the production-SaaS direction instead of the personal-AI direction.

Why throwing away the DAG didn’t work


Software has always been a directed graph. Twenty years of DAG orchestrators (Airflow, Prefect, Dagster, Inngest) added observability, retries, and modularity on top of that shape.

The promise of agents was that you throw the DAG away: give the LLM the edges (a goal and a set of transitions) and let it discover the nodes at runtime.

Horthy’s verdict: “it turns out this doesn’t quite work.” The 12 factors are what you do instead — keep most of the graph, put the LLM where it earns its keep.


The Twelve Factors

1. Natural Language to Tool Calls

Translate a phrase into a structured object, then let deterministic code act on it. “Create a payment link for $750 to Terri” becomes a JSON payload a switch statement dispatches. This is the atomic unit; everything else is composition. → Agent Tools - Design Principles

2. Own your prompts

Don’t outsource prompt engineering to a framework. A black-box Agent(role=..., goal=..., tools=[...]) is great for TOP NOTCH starter prompts and terrible for getting exactly the right tokens into the model. Treat prompts as first-class code: full control, testable, iterable, transparent, and open to role hacking (nonstandard user/assistant role usage). → Harness Engineering, Evaluation-First Prompting

“I don’t know what’s the best prompt, but I know you want the flexibility to be able to try EVERYTHING.”

3. Own your context window

The factor Horthy now points people to when they ask about context engineering. Two claims:

  • You are not obliged to use the standard messages array. Build a custom context format (he uses XML-ish event blocks packed into a single user message) optimised for token and attention efficiency.
  • At any given point, your input to an LLM in an agent is “here’s what’s happened so far, what’s the next step.” Everything else is dressing.

→ Context Engineering, Context Window Management Strategies

4. Tools are just structured outputs

There is no such thing as a tool. There is a model emitting JSON with an intent field, and code that decides what to do with it. Nothing forces you to run the same function the same way every time the model “calls a tool.” → Tool Design for Agent Harnesses, Latent vs Deterministic

5. Unify execution state and business state

Most infrastructure separates execution state (current step, next step, waiting status, retry counts) from business state (the messages, tool calls, and results so far). For agents, don’t. Engineer the app so all execution state is inferable from the context window, and you get one serializable thread that gives you debugging, recovery, forking, and a human-readable UI for free. → Agent State and Resumability

6. Launch/Pause/Resume with simple APIs

Agents are just programs. Users, pipelines, webhooks, and other agents should be able to start one, pause it for a long-running operation, and resume it later without deep integration with the orchestrator. The specific gap he calls out: most frameworks can pause between turns but not between tool selection and tool execution — which is exactly where approval has to happen. → Agent State and Resumability

7. Contact humans with tool calls

Make “ask a human” a structured output like any other (request_human_input, done_for_now) rather than relying on the model’s high-stakes first-token choice between prose and JSON. The payoff isn’t ergonomics, it’s the inner loop / outer loop inversion: once the agent can reach a human through a durable channel, control flow can start Agent → Human (cron, webhook, outage) instead of only Human → Agent. → Human-in-the-Loop as a Tool Call

8. Own your control flow

Write the loop yourself, with a switch statement you can read. Then you can insert summarisation of tool results, LLM-as-judge on structured output, compaction, tracing, rate limiting, and durable sleep — and you can break the loop on high-stakes intents. Without this granularity you are stuck choosing between blocking in memory, restricting the agent to research-and-summarise, or “just yolo hope it doesn’t screw up.” → Five Workflow Patterns for AI Agents, Agent Harness

9. Compact errors into context window

Append the formatted error to the thread and let the model self-heal. Then add a consecutive_errors counter, cap it around three, and on the cap either restructure the context, reset part of it, or escalate to a human. Raw stack traces forever produces spin-out. → Making Your Agent Reliable

10. Small, focused agents

3-10 steps, maybe 20 max, one domain each. Agents are one building block inside a mostly deterministic system, not the system. The mechanism is context length: “as context grows, LLMs are more likely to get lost or lose focus.”

On the obvious objection — what if models get smart enough for 100-step workflows? — his answer is that this still wins, because it lets you ship today and expand agent scope incrementally as reliability allows. → Multi-Agent Systems, Agent Swarms

11. Trigger from anywhere, meet users where they are

Slack, email, SMS, cron, webhook, outage alert. This is the HumanLayer pitch and he says so. It composes with 6 and 7: durable pause plus a human channel is what makes it safe to give an agent higher-stakes tools like sending external email or touching production data. → Cloud Agent Infrastructure, Claude Code Automation Stack

12. Make your agent a stateless reducer

agent = foldl(step, initial_state, events). The agent is a pure function from (thread, event) to next thread. Horthy admits this one “is mostly just for fun” — it’s the formal restatement of factor 5, not a new requirement. → Agent State and Resumability


What this adds to the vault

The vault already had eight of these twelve under other names, mostly from Building Effective Agents and the harness cluster. The overlap map:

FactorAlready in the vault as
1. NL → tool callsAgent Tools - Design Principles, Agent-Computer Interface (ACI)
2. Own your promptsHarness Engineering, Fat Skills Fat Code Thin Harness
3. Own your context windowContext Engineering, Context Window Management Strategies
4. Tools are structured outputsTool Design for Agent Harnesses, Latent vs Deterministic
5. Unify statenew → Agent State and Resumability
6. Launch/pause/resumepartial: Long-Running Agents, Brain Hands Session Split, Session Observability and Replay
7. Contact humans with tool callsnew → Human-in-the-Loop as a Tool Call
8. Own your control flowFive Workflow Patterns for AI Agents (workflows vs agents is this argument)
9. Compact errorspartial: Context Window Management Strategies, Making Your Agent Reliable
10. Small, focused agentsMulti-Agent Systems, Agent Swarms
11. Trigger from anywhereClaude Code Automation Stack, Cloud Agent Infrastructure
12. Stateless reducernew → Agent State and Resumability

12-Factor vs Building Effective Agents

Both documents tell you to keep things simple and not to hide the prompt behind a framework. They differ in what question they answer.

Building Effective Agents12-Factor Agents
QuestionWhich shape of system should I build?How do I keep the thing shippable once built?
OutputA taxonomy: augmented LLM → five workflows → autonomous agentA checklist of twelve engineering properties
Unit of adviceArchitecture patternImplementation property
Position on agencyAdd it when flexibility is worth the latency and costMost of your system should stay deterministic; agents are components
Blind spot it fills—State, resumability, human contact, triggers

Anthropic tells you when to reach for an agent. Horthy assumes you already did and asks whether you can debug it at 3am. The two are complements, and reading only the first is how teams end up at step 5 of the failure story.

Where it fits with the rest of the vault

  • Harness Engineering — Horthy is one of the named threads Osmani pulls together. 12-Factor is the most concrete artifact of that discipline: factors 2, 3, 4, 8, 9 are all “the harness is yours, write it down.”

  • Agent Harness — the five ingredients map cleanly. Factor 8 is the loop, 1/4 are tools, 3 is context management, 6/11 are the I/O surface. Factor 5 argues the harness needs a sixth explicit ingredient the vault hadn’t isolated: the thread.

  • The Ratchet - Every Mistake Becomes a Rule — factor 9 is the ratchet at runtime instead of at rulebook level. The error goes into the context; the counter and the escalation are the permanent fix.

  • Loop Engineering — factor 11’s outer-loop agents are Osmani’s automations. Factor 7 is how a loop running while you sleep asks for permission without stopping dead.

  • Agentic Coding - Risks and Discipline — factor 10’s step budget is the same instinct as booboo compounding: bound the blast radius per unit of autonomy.

  • Pi vs Claude Code - Scored Against the 12 Factors — the rubric turned on this vault’s two harnesses. The factors split along one line: ownership of prompt/context/state vs operation in the world.

Open questions

  • Factor 3’s custom context format vs the standard messages array: does the token efficiency survive now that providers cache the messages array so aggressively? The doc predates widespread prompt caching.
  • Factor 5’s “infer all execution state from the context window” is clean for a single agent. Does it hold for the orchestrator-worker shape in Multi-Agent Research System - Production Lessons, where subagent threads are separate contexts?

Sources