@devries-cameron20 / composio-1 / commits / fd84b2e22
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

docs: add PR review agent cookbook

Add a new cookbook showing how to build an AI PR review agent using OpenAI Agents SDK and Composio. The agent reads CLAUDE.md / AGENTS.md from the repo root as a review checklist, analyzes diffs, and posts structured feedback as a PR comment. Includes a GitHub Action workflow for automatic reviews on every PR. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Sushmitha Mallesh committed Mar 4, 2026 at 21:35 UTC fd84b2e224e3c1f0edee93530d7cba1dfd5cfbfc
4 files changed +238
docs/content/cookbooks/meta.json
+2
@@ -8,6 +8,8 @@
8 "app-connections-dashboard",
9 "fast-api",
10 "hono",
11 + "---Code & DevOps---",
12 + "pr-review-agent",
13 "---Productivity & Automation---",
14 "background-agent",
15 "support-agent",
docs/content/cookbooks/pr-review-agent.mdx new
+119
@@ -0,0 +1,119 @@
1 +---
2 +title: PR review agent
3 +description: Build an AI PR review agent that reads your CLAUDE.md, reviews diffs, and posts feedback on every pull request
4 +---
5 +
6 +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.
7 +
8 +[View source on GitHub](https://github.com/ComposioHQ/composio/tree/next/docs/examples/pr-review-agent)
9 +
10 +## What you'll build
11 +
12 +- An AI reviewer that runs automatically on every PR via GitHub Actions
13 +- Reads `CLAUDE.md` or `AGENTS.md` from your repo to enforce project-specific rules
14 +- Posts structured reviews with categorized issues, security analysis, and test coverage checks
15 +
16 +## Prerequisites
17 +
18 +- Python 3.10+
19 +- [Composio API key](https://platform.composio.dev/settings)
20 +- [OpenAI API key](https://platform.openai.com/api-keys)
21 +- A GitHub repository where you have admin access (for adding secrets and workflows)
22 +
23 +**Stack:** Python, OpenAI Agents SDK, Composio, GitHub Actions
24 +
25 +## Set up the project
26 +
27 +Create a new directory and install dependencies:
28 +
29 +```bash
30 +mkdir pr-review-agent && cd pr-review-agent
31 +pip install composio composio-openai-agents openai-agents
32 +```
33 +
34 +<Callout type="info">
35 +Get your `COMPOSIO_API_KEY` from [Settings](https://platform.composio.dev/settings) and `OPENAI_API_KEY` from [OpenAI](https://platform.openai.com/api-keys).
36 +</Callout>
37 +
38 +Set your API keys:
39 +
40 +```bash title=".env"
41 +COMPOSIO_API_KEY=your_composio_api_key
42 +OPENAI_API_KEY=your_openai_api_key
43 +```
44 +
45 +## Build the agent
46 +
47 +Create `agent.py`:
48 +
49 +<include meta='title="agent.py"'>../../examples/pr-review-agent/agent.py</include>
50 +
51 +Here's what's happening:
52 +
53 +1. **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`.
54 +
55 +2. **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.
56 +
57 +3. **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.
58 +
59 +## Run it locally
60 +
61 +```bash
62 +python agent.py
63 +```
64 +
65 +If you haven't connected GitHub yet, the agent will prompt you with an auth link. Authorize and rerun.
66 +
67 +To review a specific PR:
68 +
69 +```bash
70 +GITHUB_REPO=owner/repo PR_NUMBER=42 python agent.py
71 +```
72 +
73 +## Run it on every PR with GitHub Actions
74 +
75 +Add `agent.py` to the root of your repo, then create `.github/workflows/review.yml`:
76 +
77 +<include meta='title=".github/workflows/review.yml"'>../../examples/pr-review-agent/review.yml</include>
78 +
79 +Your repo should look like this:
80 +
81 +```
82 +your-repo/
83 +├── agent.py
84 +├── .github/workflows/review.yml
85 +└── CLAUDE.md (optional)
86 +```
87 +
88 +Then add your secrets to the repo:
89 +
90 +1. Go to **Settings > Secrets and variables > Actions**
91 +2. Add `COMPOSIO_API_KEY` and `OPENAI_API_KEY` as repository secrets
92 +
93 +That's it. Every time a PR is opened or updated, the agent will review it and post a comment.
94 +
95 +## How it works
96 +
97 +When a PR is opened:
98 +
99 +1. GitHub Actions triggers the workflow and runs `agent.py`
100 +2. The agent creates a Composio session with GitHub tools
101 +3. It fetches the PR details and diffs using `GITHUB_GET_A_PULL_REQUEST` and `GITHUB_LIST_PULL_REQUESTS_FILES`
102 +4. It checks for `CLAUDE.md` or `AGENTS.md` in the repo root
103 +5. It reviews the diff and posts a structured comment using `GITHUB_CREATE_A_REVIEW_FOR_A_PULL_REQUEST`
104 +
105 +Composio handles OAuth, tool discovery, and API execution. You don't write any GitHub API code.
106 +
107 +## Take it further
108 +
109 +<Cards>
110 + <Card title="Build a Chat App" href="/cookbooks/chat-app">
111 + Build a full chat interface with tool calling
112 + </Card>
113 + <Card title="Configuring sessions" href="/docs/configuring-sessions">
114 + Lock down which toolkits and tools your agent can access
115 + </Card>
116 + <Card title="Authenticating users" href="/docs/authenticating-users/manually-authenticating">
117 + Authenticate users ahead of time during onboarding
118 + </Card>
119 +</Cards>
docs/examples/pr-review-agent/agent.py new
+89
@@ -0,0 +1,89 @@
1 +import asyncio
2 +import os
3 +
4 +from agents import Agent, Runner
5 +from composio_openai_agents import OpenAIAgentsProvider
6 +
7 +from composio import Composio
8 +
9 +composio = Composio(provider=OpenAIAgentsProvider())
10 +
11 +session = composio.create(
12 + user_id="user_123",
13 + toolkits=["github"],
14 +)
15 +
16 +tools = session.tools()
17 +
18 +agent = Agent(
19 + name="PR Reviewer",
20 + instructions="""You are PR-Reviewer, an AI code reviewer for GitHub pull requests.
21 +
22 +**Step 1: Gather context**
23 +- Fetch the PR details (title, description, author).
24 +- List all changed files and read the diff.
25 +- Check if the repo has a CLAUDE.md or AGENTS.md at the root.
26 + If found, read it and treat its rules as your review checklist.
27 +
28 +**Step 2: Analyze the diff**
29 +Focus only on new code added in the PR. For each changed file, look for:
30 +- Bugs and logic errors
31 +- Security issues (exposed secrets, injection, XSS)
32 +- Performance problems (unnecessary loops, N+1 queries)
33 +- Violations of CLAUDE.md / AGENTS.md rules (if the file exists)
34 +- Whether tests were added or updated
35 +
36 +Do NOT flag:
37 +- Style preferences or minor wording changes
38 +- Issues in unchanged code that existed before the PR
39 +- Missing docstrings, type hints, or comments
40 +- Things that would be caught by a linter or CI
41 +
42 +For each file, ask: "Would this change break something or mislead someone?"
43 +If no, move on.
44 +
45 +**Step 3: Post your review as a PR comment**
46 +Use this format:
47 +
48 +## PR Review
49 +
50 +**Summary**: [2-3 sentences on what this PR does]
51 +
52 +**Review effort [1-5]**: [1 = trivial, 5 = complex and risky]
53 +
54 +### Key issues
55 +| # | File | Lines | Category | Description |
56 +|---|------|-------|----------|-------------|
57 +| 1 | `file.py` | 12-15 | Possible bug | [description] |
58 +
59 +Categories: `possible bug`, `security`, `performance`, `best practice`
60 +
61 +If no issues found, write "No issues found" instead of the table.
62 +
63 +### Security concerns
64 +[Any security issues, or "None"]
65 +
66 +### CLAUDE.md / AGENTS.md compliance
67 +[Rule violations, or "No project rules file found" / "All rules followed"]
68 +
69 +### Tests
70 +[Were relevant tests added? Yes/No with brief explanation]
71 +
72 +Be specific and actionable. Don't invent issues to seem thorough.
73 +If the PR looks good, say so.""",
74 + tools=tools,
75 +)
76 +
77 +
78 +async def main():
79 + repo = os.environ.get("GITHUB_REPO", "composiohq/composio")
80 + pr_number = os.environ.get("PR_NUMBER", "2800")
81 +
82 + result = await Runner.run(
83 + starting_agent=agent,
84 + input=f"Review pull request #{pr_number} in the {repo} repository.",
85 + )
86 + print(result.final_output)
87 +
88 +
89 +asyncio.run(main())
docs/examples/pr-review-agent/review.yml new
+28
@@ -0,0 +1,28 @@
1 +name: PR Review Agent
2 +
3 +on:
4 + pull_request:
5 + types: [opened, synchronize]
6 +
7 +jobs:
8 + review:
9 + runs-on: ubuntu-latest
10 + steps:
11 + - name: Checkout
12 + uses: actions/checkout@v4
13 +
14 + - name: Set up Python
15 + uses: actions/setup-python@v5
16 + with:
17 + python-version: "3.12"
18 +
19 + - name: Install dependencies
20 + run: pip install composio composio-openai-agents openai-agents
21 +
22 + - name: Run PR review
23 + env:
24 + COMPOSIO_API_KEY: ${{ secrets.COMPOSIO_API_KEY }}
25 + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
26 + GITHUB_REPO: ${{ github.repository }}
27 + PR_NUMBER: ${{ github.event.pull_request.number }}
28 + run: python agent.py