Chapter 31 · Capstone: Wiring the Five-Piece Set into a Complete Workflow
Chapter goals: Wire the course's five-piece set — Prompt Engineering, MCP, Skills, AGENTS.md, Loop Engineering — into a complete production-grade workflow;落地 end-to-end with a "daily code review loop" as the example; and画 the responsibility boundaries of each layer.
31.1 The Five-Piece Set's Position in the Pipeline
Reviewing the entire course: we didn't学 five isolated tools; we learned five layers of an agent system. Their自上而下的 collaboration relationship:
┌─ Prompt Engineering (Ch 01–09) ─────────────────────────────┐
│ Write each step's instructions well: Few-shot for examples, CoT for reasoning, │
│ ReAct thinking-while-acting —— this is the "language layer" of all links │
├─ MCP (Ch 10–15) ──────────────────────────────────────────┤
│ Connect the agent to the real world: GitHub / CI / databases, etc. │
│ Tools接入 via the standard protocol —— this is the "capability access layer" │
├─ Skills (Ch 16–18) ───────────────────────────────────────┤
│ Package reusable SOPs into SKILL.md capability packs; │
│ Progressive disclosure on-demand load —— this is the "process packaging layer" │
├─ AGENTS.md (Ch 23) ────────────────────────────────────────┤
│ 固化 project context and rules;常驻 each session —— "project convention layer" │
├─ Loop Engineering (Ch 19–22) ──────────────────────────────┤
│ Scheduling, state, budget, human gates —— let all of the above │
│ Run continuously and autonomously —— this is the "runtime and governance layer" │
└───────────────────────────────────────────────────────────┘One sentence tying it together: prompts决定单步质量; MCP决定能做什么; Skills决定怎么做才稳定; AGENTS.md决定在哪做守什么规矩; Loop决定何时做和做多久.
31.2 The Capstone Goal: Daily Code Review Loop
We will落地 the most classic variant from loop-engineering's seven patterns — Daily Triage — auto-reviewing yesterday's commits and PRs every morning;产出 a priority list; handing risk items to humanGate.
Step 1:固化工 Project Conventions with AGENTS.md
This is the "foundation" the loop runs on each time; the agent reads it every启动:
<!-- AGENTS.md -->
# Project Conventions
## Build and Test
- Install deps: `pip install -e ".[dev]"`
- Run tests: `pytest -x -q` (must be全部 green to count as done)
- Type check: `mypy src/`
## Code Style
- Follow PEP 8; functions must have type annotations and docstrings
- Never直接修改 applied migration files under migrations/
## Security Red Lines
- Don't move or rename files under .github/workflows/
- Credentials走 env vars only; hardcoding is禁止Step 2:封装 the Review Criteria as a Skill
Review rules will get长; stuffing them into AGENTS.md would blow up常驻 context — encapsulate as a skill per the progressive disclosure principle:
skills/review-checklist/
├── SKILL.md
└── references/
└── severity-rubric.md # Severity grading details; loaded on-demand<!-- skills/review-checklist/SKILL.md -->
---
name: review-checklist
description: Review commits and PRs per team standards: check test coverage, error handling, security hazards; output severity grading. Use when the user asks for a code review or to review changes.
---
# Code Review Checklist
## Steps
1. Collect待 review changes using `git log` and `gh pr list`;
2. Check each change item by item:
- Whether带 tests; whether错误 paths are handled; whether there are hardcoded credentials;
3. Grade per references/severity-rubric.md: blocker / major / minor;
4. Output as a Markdown table; blocker置顶.
## Rules
- Only report issues; don't顺手修复 (fixes are handled by the subsequent L2 loop).
- When unsure whether it's an issue,标记 as needs-human instead of guessing.Note the ReAct思想 learned in Chapter 6隐藏s in the steps: collect first (action) → thenjudge (reasoning) → then output, instead of letting the模型一气生成 from thin air.
Step 3:接入 GitHub and CI with MCP
The agent needs to read the real data of PRs and CI status. We wrote an MCP Server in Chapter 13; here we直接复用 the community's现成:
// .pi/agent/settings.json or Claude Code's mcpServers config
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_TOKEN": "<injected from env vars>" }
}
}
}This way, beyond gh pr list in the review-checklist skill, the model can also直接 query PR details, CI results, and diff via MCP tools — the protocol layer guarantees these tools are通用 to all MCP-supporting clients.
Step 4: Polish Key Nodes with Prompt Engineering
Apply the techniques from the first nine chapters to every prompt in the loop:
# Use Few-shot + structured output constraints in the triage phase
TRIAGE_PROMPT = """You are the on-call reviewer. Refer to the following historical grading examples:
Example 1: a patch fixing a login timeout without带 tests → major (core path缺 tests)
Example 2: a typo in README → minor
Example 3: removing input validation → blocker (security regression)
Now please grade the following changes; output only a JSON array;
each item contains pr_number, severity (=blocker/major/minor), reason:
{changes}
"""Few-shot examples anchor the grading scale; the output format constraint is可 parsed by programs — this正是 Chapters 3 and 5's combined application.
Step 5: Make It Run Continuously with Loop Engineering
Finally套上 the loop shell — state file + scheduling + humanGate:
<!-- STATE.md: the loop's memory backbone; updated after each run -->
# Loop State — review-loop
Last run: 2026-08-22 08:00 UTC
## High Priority (等待 human)
- [ ] PR #1241 — removed input validation (blocker)
Loop action: review意见 generated; waiting for maintainer confirmation
## Watch List
- PR #1238 open 4 days with no activity.
## Recent Noise (ignore this round)
- Dependabot dependency upgrade PR (走 independent automation)# Schedule at 8am every morning (starting in L1 report mode)
# GitHub Actions cron: 0 8 * * 1-5
npx @cobusgreyling/loop init . --pattern daily-triage --tool claude
npx @cobusgreyling/loop doctor . # Health check: audit + sync → top 3 action建议Advance per the节奏 in Chapter 21: week 1 L1 only report without auto-fix → after stabilizing升 L2 allowing drafting small fixes → after standing thetest consider L3 unattended.
31.3 Layer Responsibility Boundary Quick Reference
| Layer | Question it Answers | Change Frequency | Failure Symptom |
|---|---|---|---|
| Prompt Engineering | How to make the model do each stepright | May调 each iteration | Output unstable; formatdrifts |
| MCP | What data and actions the agent can reach | When the toolset changes | The agent "can't see" PRs/CI |
| Skills | How to沉淀 and reuse standard processes | When the process evolves | Inconsistent做法 each time |
| AGENTS.md | What the rules of this project are | When project conventions change | The agentviolates team conventions |
| Loop | When to do it; how long; who covers | When the运行策略调整s | Either doesn't动 or失控 burns money |
Troubleshootingmnemonic: wrong → check prompts; can'tdo → check MCP; messy → check Skill;不守规矩 → check AGENTS.md; won't动 or won'tstop → check Loop.
31.4 Common Combined Anti-Patterns
- Stuffing everything into AGENTS.md:常驻 context drowned by hundreds of lines of rules; the model反而抓不住 the重点 —长 processes should下沉 to Skills;
- Skipping L1直跳 L3: unattended without a report period验证, equivalent to handing the production repo to an unsupervised intern;
- Relying entirely on裸拼 prompts for tools: not using MCP; pasting API docs into the prompt and letting the模型 guess the调用方式 — brittle and wasteful of tokens;
- STATE.md无人 maintained: the loopmakes decisions基于过期 memory; moredangerous than no state (loop-sync类 tools exist to防 this);
- Write operations without a human gate: review-type loops can仅 report; but any auto-merge/deploy action必须有门禁 and allowlist (denylist / auto-merge allowlist).
31.5 Chapter Summary and Next Steps
This course has带你打通 the完整纵深 of the agent system:
- Ch 01–09: mastered Few-shot, CoT, ReAct, ToT, and other prompt techniques; can defend against prompt injection;
- Ch 10–15: understood andHands-on implemented MCP Servers; mastered the three primitives Tools/Resources/Prompts;
- Ch 16–18: can封装 reusable capabilities with the Agent Skills standard and do team governance;
- Ch 19–22: understood the loop's anatomy and five blocks; can do Loop Ready评估 for projects;
- Ch 23–24:固化 project conventions with AGENTS.md;组合 the five-piece set into a continuously运转 workflow.
Next建议 to continue深造 on this site:
| Direction | Course | Relation |
|---|---|---|
| Framework-built agents | Agno | Implement this course's手工 loops with industrial frameworks: tools, memory, Workflow all included |
| Multi-agent collaboration | CrewAI | 扩展 a single loop into a角色分工 team |
| Customize your harness | Pi | The终端实战版 of this course's Skills/AGENTS.md ideas; can also写 TS extensions |
🧪 随堂测验
点击你认为正确的选项。答错时会展示正确答案与原因解析。
1. In the five-piece architecture, which layer should you优先排查 when "the agent can't see the CI failure result"?
2. Why should the review rule checklist be封装 as a Skill rather than written into AGENTS.md?
3. Regarding the上线 path for a Daily Triage loop, which is correct?
4. Discovering the loop makes decisions based on an过期 STATE.md for three连续 days — which layer does this belong to?