Reinforcement Loop: Code access & draft PRs
The Reinforcement Loop diagnoses issues in your AI agents. With access to an agent's source code, it can point to the code behind an issue and recommend fixes. Requires the GitHub integration.
Prerequisites
The Reinforcement Loop requires the Monte Carlo GitHub App. Set up the GitHub integration first.
Connecting your agent's code
The Reinforcement Loop doesn't read any code until you add a repository to an agent.
Read-only access. The Reinforcement Loop only reads the repos you give it access to. It never pushes code, opens pull requests, or changes your repo on its own. The only write action is creating PRs from fixes, which is optional and must be initiated by a user.
- Open your connected AI agent and go to the Reinforcement Loop tab.
- Click Settings.
- Add one or more code locations:
| Field | Value |
|---|---|
| Repository | A repo the GitHub App can access |
| Branch | Optional. Defaults to the repo's default branch. |
| Path prefix | Optional. Limits reads to one folder (e.g. agents/support_bot) |
Creating PRs from fixes (optional)
Configure the steps below if you'd like to open recommended fixes as draft pull requests. A user on your team can then draft any proposed fix as a pull request.
This uses a second app, Monte Carlo Action Trigger, which can start a workflow in your repo but cannot read your code.
Permissions required:
- Read and write access to actions
- Read access to metadata
Setup:
- Add a workflow to your repo that accepts the inputs below, makes the change, and opens a draft pull request.
- In Monte Carlo, go to Settings → Integrations, click Add, and select GitHub Action Trigger. Install the app on your GitHub organization.
- On the GitHub Action Trigger integration page, under Draft PR workflows, click Add and enter:
| Field | Value |
|---|---|
| Agent | The agent whose fixes open draft PRs |
| Repository | The repo containing the workflow |
| Workflow file | The workflow's file name (e.g. mc-draft-pr.yml) |
| Ref | Branch or tag whose copy of the workflow runs |
Your workflow receives these inputs:
| Workflow input | Value |
|---|---|
title | Issue title |
context | Recommended fix and supporting details |
monte_carlo_id | Links the run and pull request to the issue |
monte_carlo_url | Link to the issue in Monte Carlo |
source | reinforcement_loop |
Your workflow opens the pull request with your repository's GITHUB_TOKEN, so your branch protection rules and review requirements apply. Inputs appear in the Actions run log and never contain secrets. Creating a PR from a Reinforcement Loop requires permission to edit alerts.
Verifying
- Code access: on the next diagnosis, issues for the agent reference files in the repo and include a proposed fix.
- Pull requests from fixes: trigger a fix from an issue. The issue shows the run status, then links the draft PR.
Troubleshooting
| Symptom | Fix |
|---|---|
| "The GitHub installation for … can't read the repo …" | Give the GitHub App access to that repo |
| "The branch … isn't on …" or "The path … isn't on …" | Fix the branch or path prefix |
| "Draft-PR workflow dispatch is not enabled for this account." | Contact Monte Carlo |
Updated 1 day ago
