Examples
ReviewGuardPlugin Scenario
Use a guard scenario to show how a plugin can block a flow before the main chain continues
ReviewGuardPlugin Scenario
Scenario
You want to enforce one rule in a runtime chain:
- if a request does not carry
reviewed = true - block the rest of the flow
That is the most natural kind of guard scenario.
Example
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,
});Why this is not a pipeline
Because you are not trying to rewrite a value. You are trying to:
- allow the flow
- or stop it immediately
That is exactly what guards are for.