Examples
ReviewGuardPlugin 场景
用一个 guard 场景说明 plugin 如何在现有链路里做阻断型检查
ReviewGuardPlugin 场景
场景
你希望在某条运行链路里强制执行一条规则:
- 如果请求没有带
reviewed = true - 就直接阻断后续执行
这类“前置阻断判断”就是最典型的 guard 场景。
示例
import { Agent, BasePlugin, type PluginHooks } from "@downcity/agent";
class ReviewGuardPlugin extends BasePlugin {
readonly name = "review_guard";
readonly title = "Review Guard";
readonly description = "Blocks requests that were not reviewed.";
readonly hooks: PluginHooks = {
guard: {
"review.require_checked": [
async ({ value }) => {
const body = value as { reviewed?: unknown };
if (body.reviewed !== true) {
throw new Error("review is required before continuing");
}
},
],
},
};
}
const agent = new Agent({
id: "repo-helper",
path: "/path/to/project",
tools: {},
plugins: [new ReviewGuardPlugin()],
});
await agent.plugins.guard("review.require_checked", {
reviewed: true,
});为什么这里不是 pipeline
因为你不是想“改值”,而是想:
- 允许继续
- 或者直接阻断
这正是 guard 的语义。