Learning resourcesReviewed · Mistral AI

Build a private repository cleanup agent

This Mistral tutorial helps Python developers build an AI agent that opens cleanup pull requests in a private GitHub repository, but it requires a GitHub connection with permission to push code. It covers a managed sandbox, a separate client and optional scheduled execution.

Researched 25 Nov 2026

In short.

This Mistral tutorial guides Python developers through building a private GitHub repository cleanup agent, but its GitHub connection must permit branch pushes and pull request creation. The example uses mistral-large-4 in a managed sandbox, with GitHub credentials supplied through Sandbox Proxy rather than copied into the sandbox. Separate agent and client projects support local serving, managed deployment and optional scheduled jobs. The page explains session recovery and identity requirements, but provides no measured cleanup results, prices or explicit licence terms. No code was executed.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage is limited to the complete selected documentation page at [https://docs.mistral.ai/studio/agents/examples/private-repository-cleanup-agent.md], retained as selected-page.txt from [https://docs.mistral.ai/llms/studio/agents/examples/private-repository-cleanup-agent/llms.txt]. It includes the code excerpts, optional scheduler and troubleshooting sections. Linked documentation, console pages and complete example files are excluded. No explicit licence notice appears in the supplied page. No code was executed; runtime behavior, cleanup quality, deployment success, link availability and actual costs were not assessed.

The overview

identity

Build a private repository cleanup agent is a Mistral documentation tutorial about an agent that modifies code in one private GitHub repository and opens a pull request. The original source address is [https://docs.mistral.ai/studio/agents/examples/private-repository-cleanup-agent.md].

The example separates the agent definition, instructions and dependencies in agent/ from the session client and optional scheduler in client/. Its documented endpoint is an opened pull request; merging that request is outside the described flow.

assessment

The guide is useful for developers connecting a coding agent to private source code while keeping the GitHub credential in a connector service. It explains practical details such as repository permissions, workspace roles, session timeouts and the different identities used by interactive and scheduled execution.

It is an implementation guide that requires configuration and supporting example files. The captured page contains selected code excerpts rather than the entire project. Cleanup quality, reliability and deployment success are not demonstrated by measured results.

users

The clearest audience is Python developers and repository maintainers who want an agent to propose code cleanups through GitHub pull requests. Platform developers may also find the separation of agent deployment, client execution and scheduling useful.

Beginners need familiarity with terminal commands, environment files, Git branches and pull requests. Adoption also requires someone able to configure Mistral workspace access and connect a GitHub account with the necessary repository permissions.

capabilities

The documented agent clones the configured repository into a fresh managed sandbox, reads repository guidance, makes coherent code cleanups, runs focused checks, creates a timestamped branch and opens a pull request. The client extracts the returned pull request URL and validates that it refers to the configured repository.

The instructions exclude dependency updates, migrations, generated files, authentication changes, deployment changes and documentation-only pull requests. These are stated instructions, not independently verified enforcement guarantees.

The same cleanup function supports manual execution and an optional scheduled workflow. Each run creates a new branch, so an earlier open cleanup pull request does not block another run.

Using it

requirements

The page requires Python 3.12, uv and a MISTRAL_API_KEY. The Mistral identity needs the cloud_user workspace role to create a managed sandbox. Serving or deploying the agent also requires a workspace role with Workflows access, such as Developer.

A GitHub connector must be enabled in Mistral Studio at [https://console.mistral.ai/build/connectors]. Its connected GitHub account must be able to clone the chosen repository, push a branch and open a pull request. The repository allowlist does not grant these permissions.

The agent project pins mistralai-agents with the koyeb extra needed by the managed sandbox. The exact pinned SDK version is not shown. Scheduled execution additionally requires a separate Workflows deployment and a workspace secret containing a user API key associated with the GitHub connector.

mechanism

The client resolves the agent by name, opens a session and sends the cleanup task. The agent uses mistral-large-4 with max_iterations set to 60 and temperature set to 0.1. Its managed sandbox uses Network.all(), while GitHubBinding limits Sandbox Proxy access to the named repository.

Sandbox Proxy obtains a short-lived token from the session starter's GitHub connector and adds it to GitHub traffic. The GitHub credential remains in the connector service. For scheduled execution, a user API key stored as SCHEDULED_AGENT_API_KEY opens a session under the connector owner's identity, because the scheduling worker otherwise runs as its service account.

The session and each message use idempotency keys derived from a job identifier. A 45-minute timeout stops waiting rather than directly stopping a turn; the client treats a still-running turn as an error and cancels the session in its finally block. An abrupt process crash can leave a session available for continuation with the same job identifier, whereas an ordinary error or Ctrl-C ends it.

The optional scheduled activity describes up to four turns, a three-hour-ten-minute activity timeout and at most three attempts. A retry after a worker crash can continue the same session; a retry after an error that ended the session fails immediately.

setup

Replace your-org/your-private-repo in both agent/main.py and client/cleanup_task.py. Create the agent environment file, add MISTRAL_API_KEY, install dependencies with uv sync and inspect the configuration with uv run --frozen --env-file .env agents info. Start the agent from agent/ with uv run --frozen --env-file .env agents serve.

In client/, create the environment file, install dependencies and set MISTRAL_API_KEY and AGENT_NAME. The name must match the locally served or deployed agent. The client then runs the cleanup job against that agent.

For managed deployment, the page says to commit and push agent/ first because deployment builds the pushed commit. Deploy from agent/ with agents deploy . --name private-repository-cleanup-agent --hardened. The deployment grants its service account cloud_user, and the deploying user must already have that role. The session starter still needs the GitHub connector configured.

Scheduling is optional and separately deployed from client/. It requires binding a user API key secret to SCHEDULED_AGENT_API_KEY and scheduling private-repository-cleanup-schedule in Workflows. The documented example cron expression, 0 0 * * *, means midnight in the time zone selected in Mistral Studio.

example

After configuration and local serving, the documented manual invocation from client/ is uv run --frozen --env-file .env python run_agent.py. Its intended result is a branch named agent-cleanup/<UTC timestamp>-<short-name> and a printed pull request URL for the configured repository.

The client prints a job identifier. If the process stops abruptly before session cleanup, python run_agent.py --job <id>, using the same environment and identifier, is the documented recovery path. This example describes expected behavior from the page; no cleanup, check result or pull request was observed.

Assessment & evidence

limitations

The page does not include the complete instructions file, dependency files, Dockerfiles or helper implementations. Their full behavior cannot be assessed from the excerpts. No cleanup success rate, benchmark, representative output or repository-size limit is reported.

The agent is described as operating without an approval step; an unexpected approval callback causes the client to fail. Its sandbox configuration permits all networking through Network.all(). The repository binding limits GitHub access through Sandbox Proxy rather than providing a general network restriction.

A new run can proceed while an earlier cleanup pull request remains open, but the page does not describe coordination between overlapping cleanups or management of accumulated pull requests. It also does not specify repository-content retention, data residency or model-training treatment.

reasoning

Separating the agent from its client makes scheduling optional and lets the same cleanup function target a locally served or managed agent. This is useful when a team wants to begin with individual runs before maintaining a scheduled deployment.

The connector design avoids copying the GitHub credential into the sandbox, but access still depends on the identity opening the session. The scheduler therefore introduces a separately stored user API key to preserve the intended GitHub identity.

Idempotency keys support continuity after a crash by identifying existing sessions and turns. They should not be read as evidence that every repository operation is independently deduplicated or that an ended session can be resumed.

alternatives

The documented choices are to invoke the client manually or add scheduled execution, and to serve the agent locally or deploy it as a managed agent. The scheduler is unnecessary for building, trying or deploying the core agent.

The page does not compare other coding assistants, cleanup tools or hosting approaches in enough detail to judge relative quality, cost or maintenance effort. Its linked run-mode comparison is outside the selected page.

evidence

The evidence consists of the complete selected Mistral documentation page. Its original source address is [https://docs.mistral.ai/studio/agents/examples/private-repository-cleanup-agent.md], and the retained text was acquired from [https://docs.mistral.ai/llms/studio/agents/examples/private-repository-cleanup-agent/llms.txt].

The page provides configuration and Python excerpts, setup commands, an optional scheduling design and troubleshooting guidance. These support descriptions of intended behavior. No code was executed, and no deployment, GitHub permission, generated change or runtime outcome was verified. Linked pages and complete project files were not included.

Access & freshness

costs

Cost is unknown. The page gives no model prices, sandbox rates, hosting fees, Workflows charges, free allowances or example usage bills.

Model use, sandbox runtime, agent deployment and optional scheduling are components whose pricing needs confirmation. The stated iteration limits, timeouts and retry counts do not establish typical runtime, token consumption or cost per cleanup pull request.

rights

The captured page supplies no explicit licence or redistribution terms for its prose or code excerpts. Permission to redistribute the tutorial or a complete example project is therefore not established by this evidence.

The GitHub connection must authorize repository access, branch pushes and pull request creation. Those operational permissions do not establish the licence governing the repository's code or the example files.

freshness

The supplied capture is dated 25 November 2026 at 23:38:03.824 UTC. The page itself gives no publication or last-updated date.

It names mistral-large-4 and says the SDK is pinned, but does not show the pinned version. Current model availability, CLI compatibility and platform behavior beyond the captured documentation are unknown.

actions

Obtain the complete example project and confirm Python 3.12, uv, the required Mistral roles and a GitHub connector that can clone, push branches and open pull requests in the intended repository. Configure the repository in both projects and keep their agent names aligned.

Begin with a manual run using the documented configuration inspection and serving commands. Review the proposed changes and focused-check output before merging a resulting pull request. Confirm current pricing and applicable licence terms before budgeting for repeated use or redistributing example material.

If scheduling is needed, configure the separate Workflows deployment and connector owner's API key secret. Account for the documented distinction between recovery after an abrupt crash and failure after a session has already been ended.

Evidence for this report

selected-page.txtselected · checked 2026-11-25