---
title: "12-Factor Agents: The Playbook for Real-World AI Agents, Not Just Demos"
url: "https://zuey.me/articles/12-factor-agents-bi-kip-lam-ai-agent-thuc-chien-thay-vi-chi-demo?lang=en"
locale: en
access: members
full_text: false
published_at: "2025-08-18T14:10:09.000Z"
tags: ["AI Agents", "AI", "Programming"]
translations:
  vi: "https://zuey.me/articles/12-factor-agents-bi-kip-lam-ai-agent-thuc-chien-thay-vi-chi-demo.md?lang=vi"
  zh: "https://zuey.me/articles/12-factor-agents-bi-kip-lam-ai-agent-thuc-chien-thay-vi-chi-demo.md?lang=zh"
  ko: "https://zuey.me/articles/12-factor-agents-bi-kip-lam-ai-agent-thuc-chien-thay-vi-chi-demo.md?lang=ko"
  ja: "https://zuey.me/articles/12-factor-agents-bi-kip-lam-ai-agent-thuc-chien-thay-vi-chi-demo.md?lang=ja"
---
# 12-Factor Agents: The Playbook for Real-World AI Agents, Not Just Demos

> Your AI agent demo nails 70-80%, the client loves it, then production hits and... boom 😅 Here are the 12 principles from HumanLayer's 12-factor-agents repo for agents that actually survive the real world.

If you've ever built an AI agent, you've probably been here: the demo works 70-80% of the way, the client is thrilled, and then you ship to production and... boom! 😅

HumanLayer's **12-factor-agents** repo is the "cure" for exactly this. The author, Dex (a guy who has "been through the trenches" with every framework from LangChain and LangGraph to all the "minimalist" ones), distilled lessons from 100+ founders/builders into 12 design principles for truly production-ready AI agents.

### The core problem: why do AI agents usually "die" at 80%?

Most of us follow this pattern when we start building agents:

1. Pick a popular framework (LangChain, CrewAI, etc.)
2. Set it up fast, demo 70-80% of the features
3. To reach 100% you have to "dissect" the framework and debug 7 layers of abstraction
4. In the end... rewrite from scratch 🤦‍♂️

> **TIP:** **Key insight:** AI agents that succeed in production actually aren't that "agentic". They're mostly **deterministic code** with LLM steps "sprinkled" in exactly the right places to create a "magical" experience.

### 12 golden rules for production AI agents

| # | Principle | Key idea |
| --- | --- | --- |
| 1 | **Natural Language to Tool Calls** | An LLM's superpower is turning natural language into structured data (JSON). That's the foundation, not fancy "tool calling". |
| 2 | **Own Your Prompts** | Don't trust a framework's prompt templates. Production quality needs hand-crafted prompts tuned for each specific use case. |
| 3 | **Own Your Context Window** | Don't just append blindly. Actively manage what the LLM sees — that's the art of context engineering. |
| 4 | **Tools Are Just Structured Outputs** | "Tool use" sounds fancy, but it's really just JSON routing. Demystify it into simple logic. |
| 5 | **Unify Execution State and Business State** | These two kinds of state have different lifecycles and need to be handled differently — don't let them end up scattered all over the place. |
| 6 | **Launch/Pause/Resume with Simple APIs** | Agents must support pause/resume to handle long-running tasks and human intervention. |
| 7 | **Contact Humans with Tool Calls** | Human-in-the-loop isn't an edge case, it's **core functionality**. Treat it as a first-class citizen. |
| 8 | **Own Your Control Flow** | Agent = prompt + switch statement + context + loop. Don't let a framework hide your control flow. |
| 9 | **Compact Errors into Context Window** | Don't append errors blindly. Process them intelligently and compact them so the LLM understands. |
| 10 | **Small, Focused Agents** | Instead of one agent doing everything, have many micro-agents (3-10 steps max) doing specific jobs. |
| 11 | **Trigger from Anywhere** | Meet users where they are: email, Slack, Discord... Multi-channel by design. |
| 12 | **Stateless Reducer Pattern** | The agent shouldn't manage state — your application should. That enables horizontal scaling and reliability. |

---

*Phần còn lại dành cho thành viên có quyền đọc toàn bài (Knowledges, Kết hợp, Cộng đồng) — see plans at https://zuey.me/pricing*
