docs/content/cookbooks/pr-review-agent.mdx
Build a PR review agent that runs on every pull request, reads your repo's CLAUDE.md or AGENTS.md, reviews the diff against those rules, and posts structured feedback as a comment. About 40 lines of Python and a 20-line GitHub Action.
CLAUDE.md or AGENTS.md from your repo to enforce project-specific rulesStack: Python, OpenAI Agents SDK, Composio, GitHub Actions
Create a new directory and install dependencies:
mkdir pr-review-agent && cd pr-review-agent
pip install composio composio-openai-agents openai-agents
Set your API keys:
COMPOSIO_API_KEY=your_composio_api_key
OPENAI_API_KEY=your_openai_api_key
Create agent.py:
<include meta='title="agent.py"'>../../examples/pr-review-agent/agent.py</include>
Here's what's happening:
Session creation: composio.create(user_id="user_123", toolkits=["github"]) creates a session with GitHub tools like GITHUB_GET_A_PULL_REQUEST, GITHUB_LIST_PULL_REQUESTS_FILES, and GITHUB_CREATE_A_REVIEW_FOR_A_PULL_REQUEST.
CLAUDE.md / AGENTS.md as review rules: The agent checks for either file in the repo root and uses it as its review checklist. Your existing project standards become the review guide with zero extra setup.
Focused review: The agent only flags new code that could break something or mislead someone. It skips style preferences, pre-existing issues, and anything CI already catches.
python agent.py
If you haven't connected GitHub yet, the agent will prompt you with an auth link. Authorize and rerun.
To review a specific PR:
GITHUB_REPO=owner/repo PR_NUMBER=42 python agent.py
Add agent.py to the root of your repo, then create .github/workflows/review.yml:
<include meta='title=".github/workflows/review.yml"'>../../examples/pr-review-agent/review.yml</include>
Your repo should look like this:
your-repo/
├── agent.py
├── .github/workflows/review.yml
└── CLAUDE.md (optional)
Then set up your repo:
COMPOSIO_API_KEY and OPENAI_API_KEY as repository secretsuser_123 in CI, so that user needs a GitHub connection before the workflow can post reviews:python -c "
from composio import Composio
composio = Composio()
session = composio.create(user_id='user_123', toolkits=['github'])
connection = session.authorize('github')
print('Visit this URL to connect GitHub:', connection.redirect_url)
connection.wait_for_connection()
print('Connected!')
"
After you authorize once, the connection persists. The GitHub Action will work for all future PRs.
When a PR is opened:
agent.pyGITHUB_GET_A_PULL_REQUEST and GITHUB_LIST_PULL_REQUESTS_FILESCLAUDE.md or AGENTS.md in the repo rootGITHUB_CREATE_A_REVIEW_FOR_A_PULL_REQUESTComposio handles OAuth, tool discovery, and API execution. You don't write any GitHub API code.