创建项目章程
Creating the constitution
Summary
The longest lesson (10 mins) demonstrates how to collaborate with an agent to write the project constitution — mission, tech stack, and roadmap — for the AgentClinic project. Shows both detailed and lightweight spec approaches, iterative refinement through agent dialogue, and committing the constitution as a living document.
Key Takeaways
- Three pillars of the constitution: mission (why), tech stack (how), and roadmap (what’s next)
- Write specs with the agent: collaborative conversation reveals architecture patterns, tradeoffs, and gaps you might miss alone
- Mission and tech stack as separate files: separating architectural decisions from product vision improves clarity
视频信息:Creating the constitution
English Script
You need to tell your agent about your project, the mission, audience, and other decisions. In this lesson, we’ll work together with the agent to write the Constitution. What really is your project? Say you’re working on a new web app for your company. What’s the core idea behind its development? How does it fit within your company’s preferred tech stack? What features are planned? These three foundational principles form the Constitution, a global set of high-level requirements that will guide future feature development and explain the project’s shape to stakeholders. For example, you have so many choices for your tech stack. You’ll want to narrow down your options based on appropriate tradeoffs and what you use at your company. We need to write this down. for the agent, for your teammates, for the future. But we don’t write it alone. We write it in a conversation with the agent. You’ll be surprised at the great questions it will ask. architecture patterns you hadn’t considered, external packages that already do the work, or tradeoffs. For example, speed versus data fidelity. The mission, tech stack, and roadmap aren’t just properties of a Greenfield project you’re starting from scratch. Existing codebases use these three pillars too. We will talk about bringing the SDD workflow to existing projects in just a few videos from now.
Now, let’s talk about completely new projects. We are writing AgentClinic, a place for AI agents to get relief from their humans. AgentClinic is a fun parody of the popular learning project Pet Clinic. Coding agents are doing a lot of work. It’s stressful. Hallucinations, context rot, memory issues and co-worker sub-agent coordination all take a toll on agent health. Let’s build a clinic where they can get help with their issues. It’s a full stack web app with a Next.js back end and a React front end. The app allows you to manage appointments, ailments like hallucination, and treatments like a context infusion. Let’s get started on the development. Let’s take a look at how you might go about writing a detailed spec for a project like this.
We’re about to look at a lot of text, but this technique will pay off for you down the line. Yes, it’s common to have a spec this long. This document contains a lot of information that the average Claude code instance isn’t going to know. For example, lines 37 through 43 real problems we’re trying to solve. Agents can check themselves in via API and their issues persist over time. So we can see how effective treatments are. Line 57. The visit lifecycle is mapped out including a TRIAGE step to route them to the right place and a FOLLOW-UP with three possible states. Line 379, we also have an ailment catalog plus the ability to have custom ailments. Ailments have codes and severity levels, which can be modified if the agent, for example, handles medical or legal data. Line 430. We’ll auto-create a custom ailment when symptoms don’t match any existing ailment above a 0.6 similarity threshold. Line 581, we specify the exact algorithm used to update a treatment’s effectiveness.
Let’s chat with the agent to see if there’s anything that could be cleared up. We’ve already done a few rounds of this, but there will still be some lingering questions and you could pretty much always clarify more. The agent says there’s a threshold inconsistency in the diagnosis flow. Let’s scroll to line 143 and check it out. It looks like three is actually the correct option. If a diagnosis is between 0.4 and 0.6 confidence, then it’s included but flagged as uncertain. So, this is a great sign. There’s no issue with the spec. We’re just confirming our understanding with the agent. For this question, let’s just say having an unprotected dashboard is fine because we expect to deploy this privately in a secure environment to our company. For the LLM, let’s leave that configurable because we don’t know how soon a new model will be released. For archiving, we’re not sure about this behavior right now, so let’s choose the first option, soft-delete, which gives us the most flexibility later. We’ll be moving forward with a somewhat more pared down mission document. In the repo, you’ll find both. You can choose to use either version. For a challenge, try the most complex one shown here, to follow the course exactly, use the shorter ones.
Next, let’s take a look at the tech-stack file. This document separates out the key architecture decisions from the mission document. The product can be implemented in many ways, but some are better than others. Let’s walk through some key ideas to include. Line 51, the full pipeline that happens when an agent hits the /visits route with a post request and involves validating the request, searching for previous visits, and so on. Line 588. The database schema for all the tables. This is great to have in advance because it’s such a headache to update the schema later. Line 738, A list of all possible treatments like Temperature Reduction. Then on line 706, we see which ailments get which treatments. Line 899. We go through some basic smoke tests like checking to make sure that chronic ailments are detected.
Again, let’s see if anything needs to be cleared up. This is a great question to help us align our mission and tech-stack. We’ll select option two so that our environment variable for the LLM matches in both places. This is a debatable point, but let’s keep it open for now. If we’re assuming the MVP is on a private secured network. We can refactor this later. Let’s accept the stale state when the dashboard reconnects after a dropped SSE connection, because a full refresh will pull the fresh state anyway. That’s good enough for an MVP. For the prescription payloads, let’s add the schema_version now. It’s a super lightweight change that makes things a lot easier down the line. Again, we’ll be using a smaller document moving forward. You can choose to use either version to follow along with.
To generate the more lightweight documents, let’s chat with the agent. First, we provide our project description to the agent and tell it that our stakeholders gave their input in README.md, which we added to the repo. In the important note, we directly mention Claude code’s AskUserQuestion tool. This tool is totally optional, but we just like the way it looks in the interface. Also, for the project’s constitution, tell the agent to work with you on a mission, tech stack, and roadmap. Spec-driven development works best with a human-in-the-loop approach where you review small changes. So tell the agent to organize the roadmap in small steps. As we work together, you’ll see the agent ask some really good questions. You might see different ones. The first question says, what tone should the mission.md take? I’ll choose, you guessed it, playful. That covers the mission. Now some questions for the tech stack. Our engineers are used to TypeScript on the back end, so let’s add that to the requirements. Next for our roadmap. It asks how granular it should be. I’ll choose the first option. We finished the initial interview. Let’s choose submit answers.
The agent will ask you for write permissions. This keeps changes under your control. If you are comfortable with the security tradeoffs, you can select the option to approve all instances of a particular command for this session. You’ll see this in the rest of the course. Now we’re done and we have three files in the specs directory. mission.md, tech-stack.md, roadmap.md. It’s human in the loop time. Let’s review. For example, the mission left out a target audience. That’s reasonable. How could the agent know your business? Instead of editing directly, let’s continue the conversation. To keep all artifacts consistent, it is better practice to ask the agent to make changes to them. Manually, and you might miss updating related documents. We want to use SQLite for this project since this is a quick prototype. We didn’t mention it, but the agent figured it out in recommendations. It’s now part of our tech stack. Do one final review. It’s important to get everything right up front. Let’s commit the Constitution so it will be a living document for the project. AgentClinic now has a constitution, mission, roadmap, tech stack, to guide our project. We’re ready to tackle our first feature.
创建项目章程
摘要
本课最长(10 分钟),演示如何与智能体协作编写项目章程——包括 AgentClinic 项目的任务愿景、技术栈和路线图。展示了详细和轻量级两种规格说明方法,通过智能体对话进行迭代优化,以及将章程作为活文档提交。
关键要点
- 章程三大支柱:任务愿景(为什么做)、技术栈(怎么做)、路线图(下一步做什么)
- 与智能体协作编写规格:对话式协作能发现你独自可能遗漏的架构模式、权衡取舍和空白
- 任务与技术栈分开存档:将架构决策与产品愿景分离能提高清晰度
视频信息:创建项目章程
视频脚本(中文翻译)
你需要告诉智能体关于你的项目、任务愿景、目标受众以及其他决策。在本节课中,我们将与智能体合作编写”项目章程”。你的项目到底是什么?假设你正在为公司开发一个新的 Web 应用。其开发背后的核心理念是什么?它如何与你公司首选的技术栈相契合?计划了哪些功能?这三个基本要素构成了项目章程——这是一组全局性的高层需求,将指导未来的功能开发,并向利益相关者解释项目的形态。例如,你在技术栈上有很多选择。你需要根据适当的权衡以及公司内部使用的技术来缩小选项范围。我们需要把这些写下来,为智能体、为你的队友、为未来写下来。但我们不是独自编写。我们在与智能体的对话中共同编写。你会惊讶于它能问出多么好的问题。比如你未曾考虑过的架构模式、已经实现该功能的外部库,或者是权衡取舍(例如:速度与数据保真度之间的权衡)。任务、技术栈和路线图不仅是从零开始的全新项目(Greenfield)才有的属性,现有的代码库(传统项目)也依赖这三大支柱。几节课后我们就会讨论如何将 SDD 工作流引入现有项目中。
现在,让我们谈谈全新的项目。我们正在编写”智能体诊所(AgentClinic)“,这是一个让人工智能体从人类压力中获得解脱的地方。AgentClinic 是对流行的教学项目 Pet Clinic(宠物诊所)的一个有趣的恶搞。编程智能体在做大量的工作,这压力很大。幻觉、上下文腐烂、内存问题以及同事子智能体之间的协调问题,都在影响智能体的健康。让我们建一个诊所,它们可以在那里获得针对自身问题的帮助。这是一个全栈 Web 应用,后端采用 Next.js,前端采用 React。该应用程序允许你管理预约、管理”幻觉”这样的疾病,以及”上下文注入”这样的疗法。让我们开始开发吧。让我们看看你要如何为一个像这样的项目编写一份详细的规格说明。
我们要看大量的文字了,但这项技术会在后续为你带来回报。是的,这么长的规格说明很常见。这份文档包含了许多普通 Claude Code 实例不可能知道的信息。例如,第 37 行到 43 行,这是我们试图解决的真实问题:智能体可以通过 API 自己挂号,且它们的问题会随时间持续存在,这样我们就能看到治疗的有效性。第 57 行,规划了就诊的生命周期,包括一个将它们路由到正确科室的”分诊(TRIAGE)“步骤,以及包含三种可能状态的”随访(FOLLOW-UP)“。第 379 行,我们还有一个疾病目录,加上自定义疾病的能力。疾病有代码和严重程度,如果智能体处理医疗或法律数据,这些级别可以被修改。第 430 行,当症状与现有疾病的相似度阈值未超过 0.6 时,我们将自动创建一个自定义疾病。第 581 行,我们指定了用于更新治疗有效性的确切算法。
让我们与智能体聊聊,看看是否有什么需要澄清的地方。我们已经进行过几轮对话了,但仍然会有一些遗留问题,并且你几乎总是可以进一步澄清。智能体表示在诊断流程中存在阈值不一致的问题。让我们滚动到第 143 行看看。看起来选项三实际上是正确的选项。如果一个诊断的置信度在 0.4 到 0.6 之间,那么它会被包含在内,但会标记为”不确定”。所以,这是一个好现象。规格说明本身没问题,我们只是在与智能体确认我们的理解。对于这个问题,我们可以直接说使用无保护的仪表盘(dashboard)没问题,因为我们预计将其部署在我们公司安全的私有环境中。对于大语言模型(LLM),我们将其设为可配置的,因为我们不知道新模型多快会发布。至于归档功能,我们现在还不确定其行为,所以让我们选择第一个选项——软删除(soft-delete),这能为我们以后提供最大的灵活性。我们将使用一份稍微精简的任务文档继续推进。在代码库中,你会找到这两个版本。你可以选择使用其中任何一个。为了挑战自己,你可以尝试这里展示的最复杂的版本;为了完全跟随课程,请使用较短的版本。
接下来,让我们看看 tech-stack(技术栈)文件。这份文档将关键的架构决策从任务文档中分离出来。该产品可以用很多方式实现,但有些方式比其他方式更好。让我们浏览一下其中包含的一些关键理念。第 51 行,详细说明了当智能体通过 POST 请求命中 /visits 路由时发生的完整管道流程,涉及验证请求、搜索之前的就诊记录等等。第 588 行,所有数据表的数据库结构(schema)。能提前拥有这个太棒了,因为以后再更新结构是一件非常令人头疼的事情。第 738 行,列出了所有可能的治疗方法,比如”降温处理”。然后在第 706 行,我们能看到哪些疾病对应哪些治疗。第 899 行。我们进行了一些基本的冒烟测试,比如检查以确保慢性病能被检测出来。
同样,让我们看看是否有什么需要澄清的地方。这是一个极好的问题,能帮助我们对齐任务和技术栈。我们将选择选项二,以便我们在两个地方关于 LLM 的环境变量保持一致。这是一个有争议的点,但目前我们先持开放态度。如果我们假设 MVP 是在一个私有安全网络上运行的话。我们以后可以重构这个。让我们接受仪表盘在 SSE 连接断开后重新连接时的陈旧状态(stale state),因为不管怎样,全面刷新都会拉取最新状态。这对于 MVP 来说已经足够好了。对于处方有效载荷,让我们现在就添加 schema_version(模式版本)。这是一个超级轻量级的修改,会让后续的事情容易得多。再次说明,接下来我们将使用一个较小的文档推进。你可以选择使用任一版本来跟着学习。
为了生成更轻量级的文档,我们来和智能体聊聊。首先,我们把项目描述提供给智能体,并告诉它我们的干系人在 README.md 中给出了他们的意见,我们已将其添加到仓库中。在重要提示中,我们直接提到了 Claude Code 的 AskUserQuestion(询问用户问题)工具。这个工具完全是可选的,但我们就是喜欢它在界面中的显示方式。此外,对于项目章程,告诉智能体与你一起制定任务、技术栈和路线图。规格驱动开发在采用人类干预(human-in-the-loop)方法、审查小范围变更时效果最好。所以告诉智能体将路线图分成小步骤来组织。在我们合作的过程中,你会看到智能体提出一些非常好的问题。你可能看到的问题和我不完全一样。第一个问题问的是,mission.md 应该采用什么语调?你猜对了,我会选择”俏皮的(playful)“。这涵盖了任务部分。现在是关于技术栈的一些问题。我们的工程师习惯在后端使用 TypeScript,所以我们把它加到需求中。接下来是我们的路线图。它问颗粒度应该有多细。我选择第一个选项。我们完成了初步的访谈。让我们选择提交答案。
智能体会向你请求写入权限。这能将变更保持在你的控制之下。如果你对相关的安全风险权衡感到放心,你可以选择在此会话中批准该特定命令的所有实例。你会在本课程接下来的内容中看到这一点。现在我们完成了,在 specs 目录中有三个文件:mission.md、tech-stack.md、roadmap.md。现在是人工干预检查的时间。让我们审查一下。例如,任务文件中遗漏了目标受众。这很合理,智能体怎么可能知道你的业务细节呢?我们不要直接手动编辑,而是继续对话。为了保持所有工件的一致性,更好的做法是要求智能体对它们进行修改。如果手动改,你可能会漏掉更新相关的文档。我们想在这个项目中使用 SQLite,因为这是一个快速原型。我们没提到它,但智能体在推荐选项中想到了。它现在是我们技术栈的一部分了。做最后一次审查。一开始就把所有事情做对很重要。让我们提交(commit)这份项目章程,这样它将成为项目的活文档。AgentClinic 现在有了章程——任务、路线图、技术栈,来指导我们的项目。我们准备好处理我们的第一个功能了。