@wsl8297: 逛 GitHub 时挖到一个真·宝藏开源项目:12-Factor Agents。它把「AI Agent 应用怎么做才像工程、能上线」这件事,浓缩成 12 条核心设计原则,GitHub 已拿下 11k+ Star。 这套原则不是拍脑袋总结,…
摘要
12-Factor Agents 是一个开源项目,将构建生产级 AI Agent 应用的核心设计原则浓缩为 12 条可落地的工程方法论,覆盖上下文管理、工具调用、状态建模等关键环节,已获得 11k+ GitHub Star。
查看缓存全文
缓存时间: 2026/05/17 15:35
逛 GitHub 时挖到一个真·宝藏开源项目:12-Factor Agents。它把「AI Agent 应用怎么做才像工程、能上线」这件事,浓缩成 12 条核心设计原则,GitHub 已拿下 11k+ Star。
这套原则不是拍脑袋总结,而是作者与上百位技术创始人深度交流后提炼出的可执行方法论。覆盖上下文管理、工具调用、状态建模、控制流设计、错误收敛、模块化架构等关键环节,讲的不是概念,而是能直接落地的工程做法。
GitHub:https://github.com/humanlayer/12-factor-agents…
你将收获:
- 12 条核心原则:从自然语言交互到工具编排、状态与错误处理的全链路指导
- 生产级设计模式:来自真实项目的架构套路与最佳实践
- 模块化思路:把 agent 拆成可复用、可组合的独立模块
- 实战案例:完整流程 + 常见坑位与解决方案
- 框架无关:不绑任何特定技术栈,怎么做都能套用
还附带清晰的视觉图解和深度讲解,适合边学边搭。希望能帮你把 agent 从 demo 做到可投产的 AI 产品。
humanlayer/12-factor-agents
Source: https://github.com/humanlayer/12-factor-agents
12-Factor Agents - Principles for building reliable LLM applications
In the spirit of 12 Factor Apps. The source for this project is public at https://github.com/humanlayer/12-factor-agents, and I welcome your feedback and contributions. Let’s figure this out together!
Missed the AI Engineer World’s Fair? Catch the talk here
Looking for Context Engineering? Jump straight to factor 3
Want to contribute to
npx/uvx create-12-factor-agent- check out the discussion thread
Hi, I’m Dex. I’ve been hacking on AI agents for a while.
I’ve tried every agent framework out there, from the plug-and-play crew/langchains to the “minimalist” smolagents of the world to the “production grade” langraph, griptape, etc.
I’ve talked to a lot of really strong founders, in and out of YC, who are all building really impressive things with AI. Most of them are rolling the stack themselves. I don’t see a lot of frameworks in production customer-facing agents.
I’ve been surprised to find that 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.
Agents, at least the good ones, don’t follow the “here’s your prompt, here’s a bag of tools, loop until you hit the goal” pattern. Rather, they are comprised of mostly just software.
So, I set out to answer:
What are the principles we can use to build LLM-powered software that is actually good enough to put in the hands of production customers?
Welcome to 12-factor agents. As every Chicago mayor since Daley has consistently plastered all over the city’s major airports, we’re glad you’re here.
Special thanks to @iantbutler01, @tnm, @hellovai, @stantonk, @balanceiskey, @AdjectiveAllison, @pfbyjy, @a-churchill, and the SF MLOps community for early feedback on this guide.
The Short Version: The 12 Factors
Even if LLMs continue to get exponentially more powerful, there will be core engineering techniques that make LLM-powered software more reliable, more scalable, and easier to maintain.
- How We Got Here: A Brief History of Software
- Factor 1: Natural Language to Tool Calls
- Factor 2: Own your prompts
- Factor 3: Own your context window
- Factor 4: Tools are just structured outputs
- Factor 5: Unify execution state and business state
- Factor 6: Launch/Pause/Resume with simple APIs
- Factor 7: Contact humans with tool calls
- Factor 8: Own your control flow
- Factor 9: Compact Errors into Context Window
- Factor 10: Small, Focused Agents
- Factor 11: Trigger from anywhere, meet users where they are
- Factor 12: Make your agent a stateless reducer
Visual Nav
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
How we got here
For a deeper dive on my agent journey and what led us here, check out A Brief History of Software - a quick summary here:
The promise of agents
We’re gonna talk a lot about Directed Graphs (DGs) and their Acyclic friends, DAGs. I’ll start by pointing out that…well…software is a directed graph. There’s a reason we used to represent programs as flow charts.

From code to DAGs
Around 20 years ago, we started to see DAG orchestrators become popular. We’re talking classics like Airflow, Prefect, some predecessors, and some newer ones like (dagster, inggest, windmill). These followed the same graph pattern, with the added benefit of observability, modularity, retries, administration, etc.

The promise of agents
I’m not the first person to say this, but my biggest takeaway when I started learning about agents, was that you get to throw the DAG away. Instead of software engineers coding each step and edge case, you can give the agent a goal and a set of transitions:

And let the LLM make decisions in real time to figure out the path

The promise here is that you write less software, you just give the LLM the “edges” of the graph and let it figure out the nodes. You can recover from errors, you can write less code, and you may find that LLMs find novel solutions to problems.
Agents as loops
As we’ll see later, it turns out this doesn’t quite work.
Let’s dive one step deeper - with agents you’ve got this loop consisting of 3 steps:
- LLM determines the next step in the workflow, outputting structured json (“tool calling”)
- Deterministic code executes the tool call
- The result is appended to the context window
- Repeat until the next step is determined to be “done”
initial_event = {"message": "..."}
context = [initial_event]
while True:
next_step = await llm.determine_next_step(context)
context.append(next_step)
if (next_step.intent === "done"):
return next_step.final_answer
result = await execute_step(next_step)
context.append(result)
Our initial context is just the starting event (maybe a user message, maybe a cron fired, maybe a webhook, etc), and we ask the llm to choose the next step (tool) or to determine that we’re done.
Here’s a multi-step example:
Why 12-factor agents?
At the end of the day, this approach just doesn’t work as well as we want it to.
In building HumanLayer, I’ve talked to at least 100 SaaS builders (mostly technical founders) looking to make their existing product more agentic. The journey usually goes something like:
- Decide you want to build an agent
- Product design, UX mapping, what problems to solve
- Want to move fast, so grab $FRAMEWORK and get to building
- Get to 70-80% quality bar
- Realize that 80% isn’t good enough for most customer-facing features
- Realize that getting past 80% requires reverse-engineering the framework, prompts, flow, etc.
- Start over from scratch
Random Disclaimers
DISCLAIMER: I’m not sure the exact right place to say this, but here seems as good as any: this in BY NO MEANS meant to be a dig on either the many frameworks out there, or the pretty dang smart people who work on them. They enable incredible things and have accelerated the AI ecosystem.
I hope that one outcome of this post is that agent framework builders can learn from the journeys of myself and others, and make frameworks even better.
Especially for builders who want to move fast but need deep control.
DISCLAIMER 2: I’m not going to talk about MCP. I’m sure you can see where it fits in.
DISCLAIMER 3: I’m using mostly typescript, for reasons but all this stuff works in python or any other language you prefer.
Anyways back to the thing…
Design Patterns for great LLM applications
After digging through hundreds of AI libriaries and working with dozens of founders, my instinct is this:
- There are some core things that make agents great
- Going all in on a framework and building what is essentially a greenfield rewrite may be counter-productive
- There are some core principles that make agents great, and you will get most/all of them if you pull in a framework
- BUT, the fastest way I’ve seen for builders to get high-quality AI software in the hands of customers is to take small, modular concepts from agent building, and incorporate them into their existing product
- These modular concepts from agents can be defined and applied by most skilled software engineers, even if they don’t have an AI background
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
The 12 Factors (again)
- How We Got Here: A Brief History of Software
- Factor 1: Natural Language to Tool Calls
- Factor 2: Own your prompts
- Factor 3: Own your context window
- Factor 4: Tools are just structured outputs
- Factor 5: Unify execution state and business state
- Factor 6: Launch/Pause/Resume with simple APIs
- Factor 7: Contact humans with tool calls
- Factor 8: Own your control flow
- Factor 9: Compact Errors into Context Window
- Factor 10: Small, Focused Agents
- Factor 11: Trigger from anywhere, meet users where they are
- Factor 12: Make your agent a stateless reducer
Honorable Mentions / other advice
Related Resources
- Contribute to this guide here
- I talked about a lot of this on an episode of the Tool Use podcast in March 2025
- I write about some of this stuff at The Outer Loop
- I do webinars about Maximizing LLM Performance with @hellovai
- We build OSS agents with this methodology under got-agents/agents
- We ignored all our own advice and built a framework for running distributed agents in kubernetes
- Other links from this guide:
- 12 Factor Apps
- Building Effective Agents (Anthropic)
- Prompts are Functions
- Library patterns: Why frameworks are evil
- The Wrong Abstraction
- Mailcrew Agent
- Mailcrew Demo Video
- Chainlit Demo
- TypeScript for LLMs
- Schema Aligned Parsing
- Function Calling vs Structured Outputs vs JSON Mode
- BAML on GitHub
- OpenAI JSON vs Function Calling
- Outer Loop Agents
- Airflow
- Prefect
- Dagster
- Inngest
- Windmill
- The AI Agent Index (MIT)
- NotebookLM on Finding Model Capability Boundaries
Contributors
Thanks to everyone who has contributed to 12-factor agents!
License
All content and images are licensed under a CC BY-SA 4.0 License
Code is licensed under the Apache 2.0 License
相似文章
@GitTrend0x: 今天 GitHub Agent & AI 工具继续霸榜 5 个星标暴增最狠的项目,专业拆解+实用场景,一文看懂! 1. anthropics/financial-services Anthropic 官方推出的金融服务智能体框架!支持复杂…
文章盘点 GitHub 上近期星标增长最快的五个 AI Agent 项目,重点介绍了 Anthropic 的金融服务智能体框架、字节跳动的 UI-TARS 桌面端以及各类编码 Agent 工具。
@VincentLogic: 发现个十万星级炸裂开源项目! agency-agents —— 直接给你配140个AI员工的“数字机构”,GitHub 近十万 star 不是吹的! 这可不是单个 AI 工具,而是一整套岗位说明书级别的多智能体集合: 14 个部门全覆盖:…
介绍一个GitHub近十万星的开源项目agency-agents,它提供涵盖14个部门的140个专业化AI员工角色,可直接集成到Claude Code等AI编程助手中使用。
@xiaojianjian567: GitHub 45k星星优秀项目介绍:hello-agents Datawhale 出品,7天涨1200+,正在疯涨 这个项目是干什么的? 一句话描述:从零开始教你构建真正的 AI Agent,不是调 API 那种,是理解核心原理、系统设…
Datawhale 开源项目 hello-agents 在 GitHub 上迅速走红,旨在通过 16 个章节系统性地教授开发者从零构建 AI Agent 的核心原理、多智能体协作及系统设计,而非仅停留在 API 调用层面。
@wsl8297: 学 AI 最怕停在“懂原理”,一到写代码就卡壳:不知道从哪下手,也找不到像样的练手项目。 我在 GitHub 挖到一个实战向宝藏库:AI-Project-Gallery。 它收录了 30+ 高质量 AI 项目,覆盖从房价预测、疾病分类等经…
This post shares a curated GitHub repository containing over 30 practical AI projects, covering domains from regression to generative AI, with many end-to-end examples, suitable for learners and developers.
@qloog: #每日推荐 Google ADK Go - 是 Google 推出的开源 Agent 开发框架 目标:用软件工程的原则来构建 AI Agent 核心设计理念: 1、Code-first:用 Go 代码定义 Agent 逻辑、工具和编排,而…
Google 发布了开源的 Agent 开发框架 ADK for Go,旨在通过软件工程原则构建 AI 代理,支持代码优先、模型无关和云原生部署。












