Add Docs
Overview
The add_docs command scans the PR code changes and suggests documentation for any code components that are missing documentation, such as functions, classes, and methods.
It can be invoked manually by commenting on any PR:
/add_docs
Example usage
Invoke the command manually by commenting /add_docs on any PR:
The command will generate documentation suggestions as inline code suggestions.
Language-specific documentation styles
The command automatically detects the programming language and generates documentation in the appropriate format:
| Language | Documentation Format |
|---|---|
| Python | Docstrings (Sphinx, Google, Numpy styles) |
| Java | Javadocs |
| JavaScript/TypeScript | JSdocs |
| C++ | Doxygen |
| Other | Generic documentation |
Configuration options
Under the section [pr_add_docs], the following options are available:
| Option | Type | Default | Description |
|---|---|---|---|
extra_instructions | string | "" | Additional instructions for the AI model |
docs_style | string | "Sphinx" | Documentation style for Python. Options: "Sphinx", "Google Style with Args, Returns, Attributes...etc", "Numpy Style", "PEP257", "reStructuredText" |
Example configuration
To customize the documentation style, add the following to your configuration file:
[pr_add_docs]
docs_style = "Google Style with Args, Returns, Attributes...etc"
extra_instructions = "Focus on documenting public methods and include usage examples"
Command line options
You can pass configuration options directly in the command:
/add_docs --pr_add_docs.docs_style="Numpy Style"
How it works
- The command analyzes the PR diff to identify code components (functions, classes, methods) that lack documentation
- It uses AI to generate appropriate documentation based on the code context and language
- Documentation suggestions are published as inline code suggestions that can be applied with a single click
Model response failures
Each model response is validated before it is accepted. Missing content or an
invalid documentation structure triggers the next model in CONFIG.FALLBACK_MODELS,
if configured. An explicit empty list or Code Documentation: null is a valid
empty result and does not trigger another model call.
If all model attempts fail, PR-Agent records the command as failed and removes
the temporary progress comment. With CONFIG.PUBLISH_OUTPUT enabled, it also
attempts to post Failed to generate code documentation for this PR.
Publication failures
Suggestions are skipped if their original source line cannot be reliably retained, including when file content is unavailable or incomplete. Valid suggestions in the same response can still be published.
With CONFIG.PUBLISH_OUTPUT enabled, PR-Agent retries unsuccessful batch
publication one suggestion at a time. If the batch and every individual retry
explicitly report failure, it attempts to post Failed to publish code
documentation for this PR. and records the command as failed. Partial success
or an unconfirmed provider result does not trigger this all-failed outcome.