What the agent does
The agent checks out the pull request and finds the endpoints it changes. In fastapi/full-stack-fastapi-template those are in backend/app/api/routes/items.py and users.py, with shared logic in backend/app/crud.py. For each changed route or CRUD function it finds the request that would reach the new code, checks whether a test sends it, and lists the gaps with file and line.
New tests go in backend/tests/api/routes/test_items.py, test_users.py or backend/tests/crud/test_user.py, and take the fixtures backend/tests/conftest.py already provides: db, client around TestClient(app), superuser_token_headers and normal_user_token_headers. Postgres starts with the values in .env, scripts/prestart.sh runs the Alembic migrations and initial data, and pytest runs from backend/.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Check out this pull request and diff it against its base branch. List the new or changed behavior in backend/app/api/routes/users.py, items.py and backend/app/crud.py that no existing test covers, with file and line. Start Postgres with the values in .env, run scripts/prestart.sh from backend/, and write pytest tests for each item in backend/tests/api/routes/test_users.py, test_items.py or backend/tests/crud/, using the fixtures in conftest.py (client, db, superuser_token_headers, normal_user_token_headers) and the helpers in tests/utils. Change no application code. Run uv run coverage run -m pytest tests/ from backend/, then uv run coverage report for the changed files. If nothing under backend/ changed, say so in the review. Do not push commits or open a pull request. Post one review on the pull request listing each untested behavior with file and line, the tests you wrote, the pytest summary, any test that fails against the branch's code with its failing assertion, and the tests as a patch. If this run names no pull request, in resources or after this prompt, stop and say so.",
"resources": [
{
"url": "https://github.com/your-org/your-app/pull/123"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
One review lands on the pull request: each untested route or CRUD branch with its file and line, the test written for it, the pytest summary and coverage for the changed files, and a patch under backend/tests/ only. The branch gets no commit.
The reviewer decides whether to apply the patch, and, for a test the review marks as failing, whether the route really returns the wrong status or leaks a field, or the test expected the wrong one.
Run it on every pull request opened against master
An automation with this request as its prompt and a github trigger on pull_request.opened and pull_request.synchronize, branch_patterns master, the template's default branch, reviews each new pull request and each push to one. Only an owner, member or collaborator fires it; a fork's pull request never does. The event text gives the URL, title, author, labels, base branch and body but no SHAs, so the agent checks out the head from the URL. A pull request that only touches the frontend/ folder still fires, since no trigger filters on paths, and the review says no backend behavior changed.
The use case this job follows, with its automation and trigger: Review every pull request.
Why run it on Rush?
The template's backend workflow fails when coverage drops below 90 percent (coverage report --fail-under=90), so an untested route can turn a pull request red with nothing wrong in it. The agent's tests aim at exactly those new lines and come back with the coverage figure for the changed files, run against migrated Postgres, before CI reports the drop.
Frequently asked questions
Why does it post a patch instead of committing the tests?
The review recipe never pushes, so the author's branch stays theirs. Applying the patch from the review adds the tests, and the next push lets the coverage check run with them.
Does it need the first superuser?
The tests log in as it. scripts/prestart.sh runs app/initial_data.py, which creates it from FIRST_SUPERUSER in .env, and superuser_token_headers uses that account.