Extending PR-Agent¶
Contributors extending a model, git provider, or tool start here. To only change the model, use Changing a Model.
Adding a model¶
Tool calls go through LiteLLM (pr_agent/algo/ai_handlers/litellm_ai_handler.py), the default handler. Most models need only configuration:
Set these under [config] in pr_agent/settings/configuration.toml.
Keep model names in configuration, not in tool code.
Models that behave differently are registered in pr_agent/algo/__init__.py:
NO_SUPPORT_TEMPERATURE_MODELS for models that reject a temperature
parameter; CLAUDE_EXTENDED_THINKING_MODELS for Claude models that
take extended thinking. Add the exact model name to the matching list.
Context windows are registered in MAX_TOKENS in pr_agent/algo/__init__.py:
add the model name and its context-window token count, or set
config.custom_model_max_tokens in configuration.toml. Without
either, get_max_tokens() raises.
Verify with PYTHONPATH=. uv run pytest tests/unittest.
Adding a git provider¶
Implement a GitProvider subclass and register it:
- Create
pr_agent/git_providers/<name>_provider.py, extending the interface inpr_agent/git_providers/git_provider.py(gitlab_provider.pyis the reference). - Register the class in
_GIT_PROVIDERSinpr_agent/git_providers/__init__.py. Keys already used:github,gitlab,bitbucket,bitbucket_server,azure,codecommit,local,gerrit,gitea,plain-diff. - Select it via
[config]→git_provider="<name>"inpr_agent/settings/configuration.toml. - Add
docs/docs/installation/<name>.md(seegitlab.md) and register it underInstallationindocs/mkdocs.yml. - Select provider-dependent behavior with capability checks like
provider.is_supported("feature")rather than provider-type checks. - Add unit tests under
tests/unittest/test_<name>_provider.py(seetest_bitbucket_provider.py) and list the required env vars inpr_agent/settings/.secrets_template.toml.
Adding a tool¶
- Implement the tool class in
pr_agent/tools/pr_<name>.pywith anasync def run(self)entry point (seepr_reviewer.py). - Add a
[pr_<tool>]section inpr_agent/settings/configuration.tomlfor the option keys the tool reads ([pr_reviewer]is the pattern to follow). - Add a prompt TOML under
pr_agent/settings/and register it in thesettings_files=[...]list inpr_agent/config_loader.py— it is not loaded otherwise. - Match the TOML section name to the settings key the tool reads:
[pr_review_prompt]inpr_reviewer_prompts.toml↔get_settings().pr_review_promptinpr_reviewer.py. - Register the tool in
command2classinpr_agent/agent/pr_agent.pyunder a command name, e.g."my_tool": PRMyTool. Then add it to the hardcoded help surfaces, or it will not show up in/help:pr_agent/tools/pr_help_message.py,pr_agent/servers/help.py, and the command list inpr_agent/cli.py. - Add a row to the tool list in
docs/docs/tools/index.md, a pagedocs/docs/tools/<name>.md(seereview.md), and register the page underToolsindocs/mkdocs.yml. - Add tests under
tests/unittest/and verify withPYTHONPATH=. uv run pytest tests/unittest.