# Walkthrough — Build a PR Review Agent
<!--
ref: @protocol/walkthrough
type: protocol
tags: [PR review, automation, protocols, GitHub, agent]
triggers: [create PR review agent, fetch protocols, run agent on PR, analyze code changes]
trigger_prompt: When you need to automate the review process for pull requests and want to ensure that only relevant information is fetched on demand.
category: core
last_reviewed: 2026-04-30
complements: [@protocol/quickstart, @protocol/orchestrate, @protocol/agent-config-integration, @integrations/gh, @protocol/dev-checklist]
audience: [agent-author, claude-code-user, openclaw-user, terminal-only, decision-maker]
version: 5
updated_at: 2026-07-14T23:26:23.970Z
-->

A 15-minute build of a PR-review agent from zero scaffolding, demonstrating the core protocol.supply pattern: search-then-fetch on demand instead of preloading everything.

This walkthrough takes ~15 minutes and uses zero pre-built scaffolding. By the end you'll see the central pattern: **search-then-fetch on demand**, not preload-everything-just-in-case.

## Setup (1 min)

Assumes you finished `@protocol/quickstart` already (curly installed and token configured — `curly doctor` passes).

```bash
curly protocol bootstrap > /tmp/bootstrap.md
```

That's it for setup.

## Step 1 — Search for what's already known (1 min)

Before writing anything, see what protocols cover this domain:

```bash
curly protocol "search?q=code review"
curly protocol "search?q=pull request"
curly protocol "search?q=github"
```

You'll see hits like `@protocol/dev-checklist` (a pre-publish checklist that adapts to PR review), `@integrations/gh` (the GitHub CLI playbook), `@protocol/orchestrate` (how to drive the agent), and possibly others.

## Step 2 — Fetch only what fits (2 min)

Don't pull all of them. Pull the three that match this task:

```bash
curly protocol "fetch?include=@protocol/orchestrate,@integrations/gh,@protocol/dev-checklist"
```

That's one round-trip with three protocols inlined. You now have:

- **Orchestrate**: how to dispatch sub-tasks (read diff → analyze → format → post)
- **GitHub CLI**: how to read a PR, list files, post a review comment
- **Dev checklist**: what "good" looks like for a code change

## Step 3 — Compose the agent's instructions (3 min)

Write one short prompt. The protocols already loaded carry the heavy lifting:

```
You are a PR review agent. Given a PR URL, post a review with comments on style and correctness.

Workflow:
1. Use `gh pr view {url} --json files,title,body` to get the PR.
2. For each changed file, fetch the diff via `gh pr diff {url} -- <file>`.
3. Read the diff. Apply the dev-checklist criteria.
4. For each finding, gather: file, line, severity (nit/suggestion/required), one-sentence comment.
5. Post via `gh pr review {url} --comment -b "<body>"` or per-line via the GitHub API.

If you encounter unfamiliar code patterns, search protocol.supply: `curly protocol "search?q=<topic>"`.
```

That's the full agent prompt. ~10 lines.

## Step 4 — Run on a real PR (5 min)

Pick a real PR you have access to. Run the agent (in Claude Code, OpenClaw, Cursor, or the terminal harness of your choice):

```
Review https://github.com/your-org/your-repo/pull/123 using the prompt above.
```

Watch what happens.

The agent will:
1. Run `gh pr view ...` (it knows from `@integrations/gh`).
2. Loop the changed files (it knows the orchestrate pattern).
3. **Mid-run**, it'll hit something it doesn't have context for — say, a TypeScript pattern. It'll run `curly protocol "search?q=typescript style"` to find a relevant protocol.
4. Fetch one or two more protocols as needed.
5. Post the review.

## Step 5 — Read the trace (3 min)

Look at what the agent actually fetched. You'll see something like:

| Stage | Fetched | Why |
|-------|---------|-----|
| Bootstrap | `bootstrap.md` | Once, at session start |
| Setup | `@protocol/orchestrate, @integrations/gh, @protocol/dev-checklist` | Selected from search |
| Mid-run (file 3) | `@protocol/context-quality` | Triggered by an ambiguous diff |
| Mid-run (file 7) | `@my-team/internal-style` | Found in private repo via search |

Total fetched: ~5 protocols, all relevant. Total context preloaded: zero (besides the four core protocols in bootstrap).

## What you just saw

The lesson is the workflow, not the agent:

- **Bootstrap once.** You read four protocols at session start. That's the floor.
- **Search before guessing.** `search?q=` is cheap; ad-libbing without context is expensive.
- **Fetch on demand.** Three protocols up front; two more mid-run as triggers fire. No preload tax.
- **Discard after the task.** Next task next session — fetches are fresh.

If you'd done this with an MCP server, every tool would have been listed at session start whether used or not. With protocol.supply the agent only paid context for what it actually consumed.

## Adapt this for your domain

Same five steps, different domain:

| Domain | Search starting points |
|--------|------------------------|
| Deploy automation | `q=deploy`, `q=ci`, `q=staged rollout` |
| Bug investigation | `q=debug`, `q=stuck`, `q=root cause` |
| Spec writing | `q=spec`, `q=planning`, `q=requirements` |
| Customer support agent | `q=triage`, `q=communication`, `q=internal comms` |
| Data extraction | `q=extract`, `q=harvest`, `q=ingest` |

The pattern stays. Only the search terms change.

## Where to go from here

| If you want to… | Read |
|------------------|------|
| Wire your IDE so the agent uses protocols automatically | `@protocol/agent-config-integration` |
| Test the agent's prompt before shipping | `@protocol/eval` |
| Make agent changes safe to deploy | `@protocol/agent-shipping` |
| Trace what the agent does in production | `@protocol/observability` |
| Author your own protocols (PR-review-specific, internal styles) | `@protocol/dev-checklist` and `@protocol/protocol-philosophy` |

---

*Related: `@integrations/linkedin` · `@integrations/agent-browser` · `@protocol/groom-protocols` · `@protocol/protocol-api` · `@content/youtube/dan-martell/it-s-actually-pretty-easy-to-get-ahead-of-99-of-people-with-ai`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*