Phin Tech docs Red Pen in the store →

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) #

Proposed shape #

  1. 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 model uses what chosen(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.

  2. 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.

  3. 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 no note, suggest or draft_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.

  4. 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.

  5. Write notes. Each surviving finding becomes a note of the matching kind (wrong for P0/P1 with a reachable scenario, consider otherwise) 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.

  6. 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:

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 #

Suggested order #

  1. Tighten agent::prompt with the shared bar and never-flag list (prompt text only).
  2. typecase-llm on async-openai: the contained runtime, keychain keys, usage, one provider tested end to end (OpenRouter), and a check that its tool calling and byot cost field work against OpenRouter and Fireworks.
  3. The review loop with the read-only allowlist, and one reviewer profile run on one pull request, result printed.
  4. Fan-out over a thread pool, merge and verify, and notes from findings.
  5. Fingerprints and re-review of only what a push changed.
  6. Cost and call caps, and the pre-run estimate.