Skip to content
ML2
Multi-Step Agent SetupsUse caseprinciplesproductionarchitecture

12-Factor Agents

Added Updated

Published Last verified Released

Our verdict

A practical checklist for moving from demo to production: own your prompts, own your context window, own your control flow, and keep state explicit. It isn't a framework or a library, so there's nothing to install; it's a set of essays you apply to code you already have. Opinionated and useful, especially if your agent stalls at the point where 80% quality isn't good enough.

Who it's for
Builders taking agents to production
Leverage
Fewer production surprises
Effort
Low
Date added

What 12-Factor Agents does

12-Factor Agents is an open guide from HumanLayer, written in the spirit of the 12 Factor App methodology. Its author describes talking to more than 100 SaaS builders whose agents reached a 70–80% quality bar on a framework, then needed a rewrite to go further. The guide's answer is to take small, modular agent concepts and build them into your existing product. Each factor is a short essay with diagrams and code sketches, mostly in TypeScript, with an appendix on pre-fetching context.

How builders use 12-Factor Agents

  • Audit an agent you already run against the 12 factors and list the two or three it breaks.
  • Move control flow out of the prompt and into code: let the model choose the next step as structured output, and let your code decide what runs.
  • Write your own prompts and context format instead of relying on a framework's hidden defaults.
  • Make human approval a tool the agent calls, so a run can pause, wait for a reply in Slack or email, and resume.

The twelve factors, in one line each

FactorWhat it asks you to do
1. Natural language to tool callsTurn a request into a structured call your code can act on.
2. Own your promptsTreat prompts as code you write and version, not framework defaults.
3. Own your context windowDecide how history, tool results and errors are put in front of the model.
4. Tools are just structured outputsA tool call is JSON; deterministic code runs it.
5. Unify execution state and business stateKeep the agent's progress in the same place as your app's data.
6. Launch, pause, resume with simple APIsMake runs startable, stoppable and resumable like any job.
7. Contact humans with tool callsAsking a person is a tool, not a special case.
8. Own your control flowYour code owns the loop, retries and branching.
9. Compact errors into the context windowFeed errors back concisely so the model can recover.
10. Small, focused agentsKeep each agent's job narrow instead of one agent doing everything.
11. Trigger from anywhereStart agents from Slack, email, schedules or events where users already are.
12. Make your agent a stateless reducerNext state comes from current state plus the new event.

Where to start on an existing agent

  • If debugging is the pain, start with factors 3 and 9: log exactly what the model sees, and shorten tool errors before they go back into context.
  • If runs need sign-off, start with factors 6 and 7: a pause and resume API plus an ask-a-human tool.
  • If quality plateaus, start with factors 2 and 8: write the prompt yourself and move branching into code.
  • The guide's appendix (Factor 13) adds one more habit: pre-fetch context you know the agent will need instead of making it call a tool for it.

12-Factor Agents: limits and gotchas

  • It's a guide, not software. A create-12-factor-agent scaffold is only a discussion thread on GitHub so far.
  • The main repository's last change was on 21 September 2025, so newer patterns such as agent skills and subagent orchestration aren't covered.
  • The author says it's not meant as a dig at frameworks, and it explicitly skips MCP, so read it alongside your framework's docs rather than instead of them.
  • Examples are mostly TypeScript; the ideas apply in Python, but you translate the code yourself.
  • Licensing is split: code is Apache 2.0, the written content is CC BY-SA 4.0, so reusing the text requires attribution and share-alike.

12-Factor Agents compared with other tools here

  • Building Effective Agents (Anthropic): Anthropic's guide to workflows versus agents, which 12-Factor links to. Read it first for patterns, then 12-Factor for production habits.
  • OpenAI Agents SDK: a framework that runs the agent loop for you. Use 12-Factor to check that you still own prompts, context and approvals inside it.
  • LangGraph: graph-based control flow in code, which lines up with factors 6 and 8.
  • Claude Agent SDK: Anthropic's agent harness, for when you'd rather start from a working loop than write your own.

When to pick 12-Factor Agents

  • Read 12-Factor Agents if your agent works in demos but not reliably for customers.
  • Read it before you adopt a framework, so you know which parts you want to keep control of.
  • Skip it if you want a ready-made library; pick a framework from the comparisons above instead.

12-Factor Agents questions

Is 12-Factor Agents a framework?

No. It's a set of principles with diagrams and code sketches. There's nothing to install.

Who wrote 12-Factor Agents?

HumanLayer publishes it on GitHub at humanlayer/12-factor-agents, and it welcomes contributions.

Can I reuse the content?

Code in the repository is Apache 2.0 and the written content is CC BY-SA 4.0, so credit the source and share adaptations under the same licence.

Related discoveries

See the newest picks →
  • Use caseMulti-Step Agent Setups

    Building effective agents: the patterns

    Prompt chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer, and when to use a real agent.

    Effort: Low

  • ToolMulti-Step Agent Setups

    LangGraph

    Low-level framework for stateful, controllable agent workflows.

    Effort: High#Open source

Get the best new A.I. picks in your inbox

The best new agent workflows and tools we’ve vetted, with a clear verdict on each. Short, occasional, useful.

More in Multi-Step Agent Setups →

Free. No spam. Unsubscribe anytime.