explaingit

humanlayer/12-factor-agents

20,513TypeScriptAudience · developerComplexity · 1/5QuietLicenseSetup · easy

TLDR

A guide of twelve engineering principles for building reliable, production-ready AI agents that embed language models into conventional software rather than fully autonomous loops.

Mindmap

mindmap
  root((12-Factor Agents))
    Design Principles
      Own your prompts
      Control context window
      Keep agents focused
      Make agents stateless
    Information Flow
      Curate model inputs
      Compact errors back
      Treat tool calls as data
    Production Readiness
      Human oversight design
      Avoid autonomous loops
      Embed AI strategically
    Use Cases
      Coding assistants
      Customer support bots
      Workflow automation

Things people build with this

USE CASE 1

Design a coding assistant that calls tools only when confident, with human review for uncertain decisions.

USE CASE 2

Build a customer support bot that escalates to a human agent via tool call when it encounters ambiguous requests.

USE CASE 3

Create a workflow automation system that pauses and resumes agent tasks without losing state between runs.

USE CASE 4

Architect an LLM-powered feature that carefully controls what context the model sees to reduce hallucinations.

Tech stack

TypeScriptMarkdown

Getting it running

Difficulty · easy Time to first run · 5min
Code is licensed under Apache 2.0 (use freely for any purpose including commercial, with attribution); content is Creative Commons BY-SA 4.0 (share and adapt with attribution and same license).

In plain English

12-Factor Agents is a guide, modeled after the well-known "12 Factor App" methodology for web applications, that proposes twelve concrete engineering principles for building AI-powered software that is reliable enough to deploy to real production customers. The core argument is that most successful AI agent products are not fully autonomous loops of an LLM calling tools until something works; they are mostly conventional software with AI steps embedded at precisely the right moments. The twelve factors cover the full lifecycle of building a production-grade AI agent. Several focus on controlling how information flows into the language model: own your prompts (write and version them yourself rather than relying on framework defaults), own your context window (carefully curate what the model sees rather than feeding it everything), and compact errors back into context rather than crashing. Others address architecture: keep agents small and focused on a single task, make agents stateless so they can be paused and resumed like a pure function, and treat tool calls as structured data outputs rather than magical actions. Factor 7 specifically addresses human oversight, designing the agent to contact a human through a tool call when it encounters uncertainty, rather than guessing. A developer or founder building LLM-powered features into a product, whether a coding assistant, customer support bot, or workflow automation, would use this guide to avoid common pitfalls and architectural dead ends. The content lives in Markdown files in the repository and the code examples are in TypeScript. It is published under Apache 2.0 (code) and Creative Commons BY-SA 4.0 (content).

Copy-paste prompts

Prompt 1
I'm building an AI agent for customer support. How do I apply the 12-Factor Agents principles to design human oversight so the agent asks for help when uncertain?
Prompt 2
Show me how to structure my agent's prompts and context window following the 12-Factor Agents guide to avoid feeding the model irrelevant information.
Prompt 3
I want to make my AI agent stateless so it can pause and resume. What does the 12-Factor Agents methodology say about storing and retrieving agent state?
Prompt 4
How should I handle tool calls in my agent according to 12-Factor Agents, as structured data outputs or as direct actions?
Prompt 5
What does 12-Factor Agents say about keeping agents small and focused instead of building one giant autonomous loop?
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.