技巧精选

Geoffrey Huntley:用 pre-commit hook 约束编码智能体的写法

Quoting Geoffrey Huntley

精选理由

与其反复改 AGENTS.md 提醒智能体,不如让 commit 直接失败并注入提示,这个技巧挺狠的。

Geoffrey Huntley 分享了一种管理编码智能体的做法:与其依赖 AGENTS.md 让智能体遵守规则,不如写一个 pre-commit hook,在 git diff 中检查绕过 diagnostics 库、直接调用 observability 模块的代码。检测到违规时让提交失败,并向智能体注入提示要求改用 diagnostics 库。Huntley 称这种方式让智能体的遵循效果达到十分。Simon Willison 引用了这段话并标注了 coding-agents 与 agentic-engineering 标签。

原文 · Simon Willison’s Weblog

Quoting Geoffrey Huntley

If the agent isn't using my diagnostics library, I could introspect and update AGENTS.md, but there's still a delta, and it'll drift. Instead, I write a pre-commit hook that checks the git diff for direct calls to observability modules that bypass my diagnostics module. Boom: fail the commit, inject a prompt telling the agent to use the diagnostics library. All of a sudden it's ten out of ten. — Geoffrey Huntley , nobody should type code by hand anymore. here's what's left. Tags: coding-agents , generative-ai , git , agentic-engineering , ai , geoffrey-huntley , llms