GitHub PR Review Agent
Deploy an AI agent that reviews pull requests and posts comments — callable via a single API endpoint.
What You’ll Build
An agent endpoint at /api/run/pr-reviewer that:
- Accepts a PR URL or diff as input
- Uses GitHub MCP tools to read files, check CI status
- Analyzes code quality, security, and best practices
- Returns structured review comments
Step 1: Create the Agent Endpoint
Dashboard → Agent Endpoints → Create
{
"name": "PR Reviewer",
"slug": "pr-reviewer",
"system_prompt": "You are an expert code reviewer. Analyze the provided code changes and provide actionable feedback. Focus on: bugs, security issues, performance, and readability. Be specific — reference line numbers and suggest fixes.",
"workspace_id": "your-workspace-id",
"llm_provider": "anthropic",
"llm_model": "claude-sonnet-4-6",
"output_format": "json",
"output_schema": {
"type": "object",
"properties": {
"summary": { "type": "string" },
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"severity": { "type": "string", "enum": ["critical", "high", "medium", "low"] },
"file": { "type": "string" },
"line": { "type": "number" },
"message": { "type": "string" },
"suggestion": { "type": "string" }
}
}
},
"approved": { "type": "boolean" }
}
},
"enable_streaming": true
}Step 2: Add GitHub MCP to Your Workspace
Add the GitHub MCP server to your workspace so the agent can access PR data:
- Browse MCP Marketplace → GitHub
- Install to your workspace
- Add your GitHub token as a workspace secret
Step 3: Call the Agent
curl -X POST https://api.aerostack.dev/api/run/pr-reviewer \
-H "Authorization: Bearer aek_your_api_key" \
-H "Content-Type: application/json" \
-d '{"input": "Review PR #42 in repo myorg/myapp"}'Response (JSON output format):
{
"output": {
"summary": "3 issues found. The auth middleware change has a potential bypass.",
"issues": [
{
"severity": "critical",
"file": "src/middleware/auth.ts",
"line": 45,
"message": "JWT verification skipped when header is empty string",
"suggestion": "Change `if (!token)` to `if (!token || token.trim() === '')`"
}
],
"approved": false
},
"usage": {
"tokens_input": 2400,
"tokens_output": 800,
"cost_cents": 12,
"latency_ms": 3200
}
}With SSE Streaming:
const response = await fetch('https://api.aerostack.dev/api/run/pr-reviewer', {
method: 'POST',
headers: {
'Authorization': 'Bearer aek_your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({ input: 'Review PR #42 in repo myorg/myapp' })
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = decoder.decode(value);
// Parse SSE events: thinking, tool_call, tool_result, done
for (const line of text.split('\n')) {
if (line.startsWith('data: ')) {
const event = JSON.parse(line.slice(6));
console.log(event.type, event);
}
}
}Step 4: Integrate with CI
Add to your GitHub Actions workflow:
- name: AI PR Review
run: |
REVIEW=$(curl -s -X POST https://api.aerostack.dev/api/run/pr-reviewer \
-H "Authorization: Bearer ${{ secrets.AEROSTACK_AGENT_KEY }}" \
-H "Content-Type: application/json" \
-d "{\"input\": \"Review PR #${{ github.event.pull_request.number }} in ${{ github.repository }}\"}")
echo "$REVIEW" | jq '.output.issues[] | "\(.severity): \(.file):\(.line) — \(.message)"'Next Steps
- Agent Endpoints overview
- SSE Streaming guide
- Smart Webhooks — trigger agents automatically on PR events