Knowledges 3 min

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.

Also in: Tiếng Việt · 中文 · 한국어 · 日本語

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 🤦‍♂️

12 golden rules for production AI agents

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

Locked section: Lessons from the field

Locked section: Why does this approach work?

Locked section: My verdict

The rest is for Knowledges members

Plus 3 more sections (about 1 min) for members

You are reading roughly the first third. Knowledges, Combo and Community plans unlock paid articles in full; the Zuey AI plan reads previews only.