/** @jsxImportSource smithers-orchestrator */
// multi-agent-review.tsx
import { createSmithers, Task, Sequence, Parallel } from "smithers-orchestrator";
import { ToolLoopAgent as Agent } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { z } from "zod";
const { Workflow, smithers, outputs } = createSmithers({
review: z.object({
approved: z.boolean(),
feedback: z.string(),
}),
verdict: z.object({
approved: z.boolean(),
summary: z.string(),
}),
});
const securityReviewer = new Agent({
model: anthropic("claude-sonnet-5"),
instructions:
"You are a security-focused code reviewer. Look for vulnerabilities, injection risks, and auth issues. Return your verdict and detailed feedback.",
});
const qualityReviewer = new Agent({
model: anthropic("claude-sonnet-5"),
instructions:
"You are a code quality reviewer. Evaluate readability, test coverage, error handling, and adherence to best practices. Return your verdict and detailed feedback.",
});
const aggregator = new Agent({
model: anthropic("claude-sonnet-5"),
instructions:
"You receive two code reviews. Synthesize them into a single verdict. Approve only if both reviewers approve.",
});
export default smithers((ctx) => {
const diff = [
"- const token = req.query.token;",
"+ const token = sanitize(req.headers.authorization);",
].join("\n");
return (
<Workflow name="multi-agent-review">
<Sequence>
<Parallel maxConcurrency={2}>
<Task id="security-review" output={outputs.review} agent={securityReviewer}>
{`Review this PR diff for security issues:\n\n${diff}`}
</Task>
<Task id="quality-review" output={outputs.review} agent={qualityReviewer}>
{`Review this PR diff for code quality:\n\n${diff}`}
</Task>
</Parallel>
<Task
id="aggregate"
output={outputs.verdict}
agent={aggregator}
needs={{ secReview: "security-review", qualReview: "quality-review" }}
deps={{ secReview: outputs.review, qualReview: outputs.review }}
>
{(deps) => (
<>
Combine these two reviews into a final verdict:{"\n\n"}
Security review: {deps.secReview.approved ? "APPROVED" : "REJECTED"} -{" "}
{deps.secReview.feedback}
{"\n\n"}
Quality review: {deps.qualReview.approved ? "APPROVED" : "REJECTED"} -{" "}
{deps.qualReview.feedback}
</>
)}
</Task>
</Sequence>
</Workflow>
);
});