← all archetypes
multi agent flow
Fill {{SCENARIO}} and {{DOMAIN}}, copy, paste into your coding agent.
# Kickoff — Multi-Agent Flow
Paste everything below into your coding agent after filling {{SCENARIO}} and {{DOMAIN}}.
---
You are working in this repo: Next.js 16 App Router + TypeScript + Tailwind, Clerk auth
(wired), Drizzle + Neon Postgres (schema `perficient`, `runs` table exists), Anthropic SDK
with `ANTHROPIC_API_KEY` in env. Deployed on Vercel; keep it deployable (each agent step
is a bounded API call — no long-lived processes).
Build a multi-agent pipeline for this scenario: {{SCENARIO}} (domain: {{DOMAIN}}).
## Architecture — evaluator-optimizer + specialist workers (justify it out loud)
One orchestrator function (plain TypeScript, not an LLM) sequences three LLM roles.
Deterministic code owns control flow; models own judgment. That division is the point.
1. **Synthetic input data.** Script generates realistic {{DOMAIN}} inputs (e.g. incoming
requests/reports/claims) into a `perficient` table via one Claude call.
2. **Worker agents** in `lib/agents/`: two or three specialists with narrow prompts and
distinct jobs, e.g. (adapt to scenario):
- `analyst`: extracts facts + flags gaps from the input (structured JSON out),
- `writer`: drafts the deliverable from the analyst's facts ONLY (no outside knowledge),
- `critic`: grades the draft against an explicit rubric (structured verdict:
`{ reasoning, verdict: pass|revise, issues[] }` — reasoning field FIRST).
3. **The loop.** Orchestrator runs analyst → writer → critic; on `revise`, writer gets the
critic's issues and retries — max 2 revision rounds, then ship with a visible "shipped
after N revisions, remaining issues: …" note. Honesty is deterministic, not
model-dependent. Log every role call to `runs` (archetype "multi-agent") with tokens.
4. **UI** at `/app`: submit an input, then a live pipeline view showing each role's output
as it lands (analyst facts → draft v1 → critique → draft v2). The visible
generate-critique-revise loop IS the demo — it shows AI evaluating AI, with code in
charge.
5. **Why not one prompt?** Be ready to say it: separate roles mean separate rubrics, cheap
models for cheap roles, and a critic that isn't grading its own work. Concede the cost:
3-5x tokens per deliverable — worth it only where quality has stakes, which is why the
revision cap exists.
6. **Mini eval.** Run 3 fixed inputs through the pipeline; assert the critic catches a
seeded flaw (give one input a deliberate factual gap) and that round-2 drafts fix
round-1 issues.
## Constraints
- Milestone after each step. Per-role model choice: `claude-sonnet-4-6` default everywhere;
note where you'd downgrade the analyst to Haiku in production.
- All model calls through `lib/ai.ts`; structured outputs zod-validated with one retry
feeding the validation error back.