Multi-agent review: design draft
Status: partly built, on agent processes rather than the direct client below. Built: the shared bar (step 1,
redpen_core::agent::BAR); specialists with only read tools and report_finding (step 3, by tool gating rather than an
allowlisted loop); fan-out three at a time, a collector agent that merges, checks and posts notes (step 4, by a model
rather than code); a tool-call cap and timeout (part of step 6); redpen review --specialists and Review It with
Specialists in the app. Not built: typecase-llm in Red Pen (a trial is on Typecase's feat/typecase-llm, on
rig-agent), fingerprints (step 5), costs and the estimate. Prior art: agentrun-code-review.md,
review-prompt-comparison.md, and the verbatim prompts beside them.
Goal #
A "Review this pull request" action that runs several independent reviewers over a pull request, each on a provider and model you choose, then merges what they find into ordinary Red Pen notes that you read, keep, edit or resolve. Red Pen never posts the result on the forge (as today: you promote a note or post a draft yourself).
What Red Pen already has (read from the code) #
- An Agent is a program:
typecase_agent::AgentKindisClaude,Pi,Omp,PigorAcp(anAcpAgentis a command such asgemini --acp).redpen_core::Settings.agentpicks one for the Agent panel. - A model and effort are chosen per agent kind:
Settings::chosen(agent) -> Chosen { model, effort }, kept in the settings file by the agent's name. A model can beprovider/model(Chosen'sprovider_of), which is how a harness like Pi names a provider. - A conversation has a
Session { id, begun }; Red Pen keeps one conversation per pull request. - The agent's tools come from
redpen_mcp(or theredpencommand):diff,search,files,read_file,definitions,checks,notes,note,suggest. Notes are the output channel; they carry a kind (wrong,consider,note,house) and a place in the diff. redpen_core::agent::prompt(command)is the one system prompt. It is an assistant prompt, with no review procedure, severity bar, never-flag list or verify step.
Proposed shape #
-
A reviewer is a named profile, kept in the settings file next to
agent:[[reviewer]] name = "contracts" # also the lens the reviewer is given provider = "openrouter" # a direct client (below); or agent = "pi" | "claude" | an ACP agent model = "anthropic/claude-sonnet-4.5" effort = "high" depth = "deep" # deep ~90 tool calls, quick ~30 (AgentRun's split)Different reviewers can use different providers, so a cheap model can do the quick lenses and a stronger one the deep ones. A reviewer with no
modeluses whatchosen(agent)already holds. A starter set (two quick, two deep, one per lens below) is written the first time, so the feature works before any setup. -
Lenses. One prompt each, taken from the prior art and kept short: contracts and callers; concurrency and state; removed behavior (the invariant each deleted line enforced); security and untrusted input; tests (would they pass if the behavior broke). Every reviewer also gets the same shared bar: a concrete failure, a changed line, a reachable scenario, a do-not-report list, impact-based severity.
-
Fan out. One run per reviewer, in parallel, each in its own
Session, each given only the read tools (diff,search,files,read_file,definitions,checks,notes) and nonote,suggestordraft_reply. A reviewer answers with one JSON block, never a note:{ "findings": [ { "path": "", "start": 0, "end": 0, "priority": "P1", "title": "", "failure": "", "evidence": "<quoted lines>", "fix": "" } ] }A reviewer that fails or returns no JSON counts as no answer; the run says which and carries on.
-
Merge and verify (in Red Pen, not a model). Group by path, start lines within 10, and the same failure; keep the one quoting the most lines at the highest priority any reviewer gave it; count how many reviewers raised it. Then one verify pass (a model call, or Red Pen reading the cited lines itself): drop a finding only on a quoted line that contradicts the failure, or over the cap. Rank by priority, then by reviewers agreeing. Cap the total.
-
Write notes. Each surviving finding becomes a note of the matching kind (
wrongfor P0/P1 with a reachable scenario,considerotherwise) with a fingerprint (path, a hash of the failure's first sentence). On a later run, a note you resolved or replied to with a dismissal is not written again, and only new head commits are re-reviewed. That uses state Red Pen already keeps. -
Spend control. A cost and call cap per run and per reviewer, shown before it starts ("5 reviewers, about N calls"), and a stop button. Parallelism is bounded (for example 3 at once) so a laptop and a rate limit survive.
Direct model client (decided direction) #
Reviewers should not have to be ACP agents. A fan-out of 5 to 8 reviewers over ACP means 5 to 8 child processes, each with its own session, no way to ask for a JSON answer, and no token or cost numbers. A direct client has none of those problems, and reaches every provider that speaks the OpenAI chat-completions shape.
A new Typecase crate, typecase-llm (beside typecase-agent), not part of the Agent panel:
- One wire format: OpenAI-compatible
chat/completionswith tool calling. A provider is a base URL, a key and a model name, so OpenAI, OpenRouter, Fireworks, Together, Groq, a local llama.cpp or Ollama server and any other compatible endpoint are one implementation with a table of defaults. Anthropic is reachable through OpenRouter; a native Messages client can come later if prompt caching or extended thinking is needed. - Returns what a caller needs and the ACP path cannot: the final message, structured output when the provider supports
response_format(else the JSON block is parsed out and checked against the schema), and theusageblock, so a run has real token counts and, where the provider reports it, cost. A provider that reports nothing shows "unknown", never zero. - Keys live in Typecase's keychain crate (
Keychain::get/save/remove(account)), one account per provider, never in the settings file. The settings file names the provider and its base URL only. - Built on
async-openai(0.43, the most used Rust client for this wire format), not a hand-written client. Usedefault-features = falsewithchat-completionandrustlsonly, so the rest of its API surface isn't compiled, andbyotwhere a provider returns fields its typed structs lack (OpenRouter's cost inusage).genai(0.7) is the fallback if a native Anthropic or Gemini adapter is needed later; it makes the same async trade. - It is async: it brings
tokioandreqwestinto the Typecase workspace for the first time (typecase-agenthas neither). Keep that insidetypecase-llm: the crate owns one small runtime and offers a blocking entry point and a channel of events (Started,ToolCall,Finished { usage },Failed) to GPUI code, so notokiotypes cross the crate's edge and the app's other code stays blocking.redpen-forgeskeepsureq. - Reviewers run as concurrent tasks on that runtime, bounded by a semaphore (for example 3 at once). A stop button cancels the tasks; each checks between calls.
The review loop, in Red Pen (redpen_core, next to agent::prompt): call the model with the lens prompt and the
tool schemas; run each tool call; feed the results back; stop on a final JSON answer, the call cap, or the cost cap.
The tools are redpen_mcp's own: tools() already produces the JSON schemas and call(database, name, arguments)
dispatches in process, so no MCP server or redpen child process is needed. Both are private today and need a small
public surface, with an allowlist: the loop advertises only the read tools (diff, search, files, read_file,
definitions, checks, notes) and refuses any other name, so a reviewer cannot write notes whatever it asks for.
What this decides: it removes the reviewers' dependence on typecase_agent running several agents at once, on
capturing a final JSON answer from each agent kind, and on a per-run tool allowlist (the first three open questions
below, for reviewers). The Agent panel and its ACP path stay as they are for conversation. The agent kinds in a
reviewer profile stay possible for someone who wants a reviewer to be a Claude Code or Pi session, at the cost of those
limits.
New costs it takes on: Red Pen owns the tool loop (retries, rate limits and 429 backoff, malformed tool calls, context growth over a long read, truncating big tool output), provider quirks in the "compatible" API, and key handling. Keep each to a small, tested part: a context budget that trims old tool output first, one retry with backoff on 429 and 5xx, and a hard call cap.
Open questions #
- (Answered by the direct client, for reviewers.) Can
typecase_agentrun several agent processes at once for one pull request? Still open for reviewers that are agent kinds. - (Answered by the direct client.) How is a final JSON answer captured from each kind of agent? Still open for agent kinds.
- (Answered by the loop's allowlist.) Can a reviewer be given a restricted tool set per run?
- Where does cost come from for each provider? OpenRouter reports cost in
usage; most others report tokens only, so a price table per model is needed, and unknown models show cost as unknown. - Which structured-output mode works across the providers you would use? Fireworks and OpenAI support JSON-schema
response_format; some models behind OpenRouter do not. Test each before relying on it, with the parse-and-check fallback. - Does Local Changes review (no forge, no pull request) use the same machinery? It should, with
diffover the branch, but the fingerprint and re-review rules differ. - Is the verify pass a model call, or code reading the cited lines? Code is cheaper and cannot be talked out of it; a model catches a failure the cited lines don't show. AgentRun uses the agent itself, capped at 8 calls.
Suggested order #
- Tighten
agent::promptwith the shared bar and never-flag list (prompt text only). typecase-llmonasync-openai: the contained runtime, keychain keys, usage, one provider tested end to end (OpenRouter), and a check that its tool calling andbyotcost field work against OpenRouter and Fireworks.- The review loop with the read-only allowlist, and one reviewer profile run on one pull request, result printed.
- Fan-out over a thread pool, merge and verify, and notes from findings.
- Fingerprints and re-review of only what a push changed.
- Cost and call caps, and the pre-run estimate.
Phin Tech docs
Red Pen in the store →