Event Automation

Automated PR Review Agent with LangGraph

An event-driven agent that wakes on a GitHub pull_request webhook, fetches the diff, runs a LangGraph review graph for bugs, security, and style, and posts inline review comments back on the PR.

What This Builds

This recipe builds an agent that reviews pull requests automatically. When a PR is opened or updated, GitHub fires a pull_request webhook. The agent fetches the diff, reasons over the changed hunks for bugs, security issues, and style problems, then posts inline review comments and a summary back on the PR.

The review logic is a LangGraph state graph: a node fetches PR context, a node classifies and analyzes each changed file, and a node formats findings into review comments. Modeling it as a graph (rather than a single prompt) gives you crash recovery and lets you re-run a single node without re-reviewing the whole PR.

Product Shape

This is an event automation, not a chat bot. The trigger is a real webhook, the work is a durable task, and the output is a side effect on the PR itself. Run the graph as a background task so a slow LLM call or a large diff never blocks the webhook response.

The Stack

  • LangChain / LangGraph — orchestrates the review as a stateful graph with typed nodes and recoverable steps.
  • GitHub MCP Server — gives the agent tools to read the diff, list changed files, and post review comments without hand-writing REST calls.
  • GitHub repository — the source of pull_request webhook events and the target for review comments.
  • Trigger.dev — runs the review as a durable background task with retries and run tracing, so webhook handling stays fast.
  • An LLM provider such as the Anthropic Startup Program credits for the reasoning calls.

Step-by-Step Outline

  1. Register a GitHub webhook (or GitHub App) for pull_request events on the target repo.
  2. On the opened / synchronize action, enqueue a durable review task instead of reviewing inline.
  3. In the task, use the GitHub MCP Server tools to fetch the PR diff and the list of changed files.
  4. Run the LangGraph graph: fetch-context node, per-file analysis node (bugs, security, style), and a findings-formatter node.
  5. Post inline comments at the relevant line ranges and a single summary review via the GitHub tools.
  6. Optionally set a non-blocking status check so reviewers see the agent ran, without gating the merge.

Why This Shape Works

Separating the webhook ingress (fast, synchronous) from the review work (slow, durable) is the key design decision. The graph structure makes each step observable and retryable, and routing all GitHub access through the MCP server keeps the agent’s tool surface explicit and auditable.

Source