Observed since 20 Oct, 21:49 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
A command-line tool to auto-generate and update file-level docstrings summarizing classes and functions. Useful for maintaining a high-level overview of your files, especially in projects with code generated or modified by AI assistants.
Agent Docstrings is a command-line tool that automatically generates and maintains a "Table of Contents" at the top of your source files. It scans for classes, functions, and methods, creating a summary that provides a high-level overview of the file's structure.
This is especially useful for AI-Agents, helping them solve the "cold start" problem of quickly understanding and navigating large, unfamiliar codebases.
| Language | File Extensions | Features |
|---|---|---|
| Python | .py | Classes, functions, methods |
| Java | .java | Classes, methods |
| Kotlin | .kt | Classes, functions |
| Go | .go | Functions, methods |
| PowerShell | .ps1, .psm1 | Functions |
| Delphi | .pas | Classes, procedures, functions |
| C | .c, .h | Functions |
| C++ | .cpp, .hpp, .cc, .cxx, .h | Functions, classes |
| C# | .cs | Classes, methods |
| JavaScript | .js, .jsx | Functions, classes |
| TypeScript | .ts, .tsx | Functions, classes |
Imagine an AI agent tasked with modifying a large, unfamiliar codebase. Its first step is to read a file to get its bearings. What if the first thing it saw was a perfect summary?
An AI agent opens a file and has no initial context. To understand the file's structure, it must:
grep_tool or other search methods to find function and class definitions.The agent opens the same file. The very first thing it reads is a "Table of Contents" generated by this tool. This provides immediate, critical advantages:
read_tool operation. This is far more efficient than performing multiple searches and analyses to build the same context from scratch.integrate_user_data exists allows for a much more focused approach than a broad search for "user data".In short, Agent Docstrings gives an AI a crucial head start, turning a slow, investigative process into a quick, informed action.
.gitignore files and allows for custom ignore (.agent-docstrings-ignore) and include (.agent-docstrings-include) files for fine-grained control.Before:
def calculate_fibonacci(n):
if n <= 1:
return n
return calculate_fibonacci(n-1) + calculate_fibonacci(n-2)
class MathUtils:
def add(self, a, b):
return a + b
After:
"""
--- AUTO-GENERATED DOCSTRING ---
Table of content is automatically generated by Agent Docstrings v1.3.0
Classes/Functions:
- MathUtils (line 18):
- add(a, b) (line 19)
- Functions:
- calculate_fibonacci(n) (line 13)
--- END AUTO-GENERATED DOCSTRING ---
"""
def calculate_fibonacci(n):
if n <= 1:
return n
return calculate_fibonacci(n-1) + calculate_fibonacci(n-2)
class MathUtils:
def add(self, a, b):
return a + b
This tool is compatible with:
Python: 3.10, 3.11, 3.12, and 3.13
Go: >=1.22 (required only for building the Go parser during package development)
No dependency on external Python libraries at runtime
pip install agent-docstrings
git clone https://github.com/Artemonim/agent-docstrings.git
cd agent-docstrings
pip install -e .
You can process one or more directories, files, or a mix of both.
Process a directory:
agent-docstrings src/
Process a single file:
agent-docstrings src/main.py
Process multiple paths:
agent-docstrings src/ tests/ lib/utils.py
agent-docstrings src/ --verbose
from agent_docstrings.core import discover_and_process_files
# Process a mix of files and directories
discover_and_process_files(["src/", "lib/utils.py"], verbose=True)
The tool automatically reads and respects .gitignore files in your project directory and its parents. Files and directories ignored by git will also be ignored by the docstring generator.
You can create a gitignore-like .agent-docstrings-ignore file in your project root to specify files and directories to ignore:
You can create a gitignore-like .agent-docstrings-include file to only process specific files:
# Only process main source code
src/*.py
lib/*.py
agent_docstrings/*.py
Note: If a whitelist file exists and is not empty, ONLY files matching the whitelist patterns will be processed.
It is important to understand the nuances of this tool to use it effectively. The quality and method of code parsing vary significantly by language.
Table of Contents, Not Full Documentation: The generator does not create detailed, explanatory docstrings. Instead, it generates a file-level comment block that acts as a "Table of Contents" listing the functions and classes found in the file. This provides a quick overview of the file's structure.
Language-Dependent Parsing Quality: The reliability of the parser is highly dependent on the target language.
Robust AST-Based Parsing (Python, Go): For Python and Go, the tool uses native Abstract Syntax Tree (AST) parsers. This approach is highly accurate and robustly handles complex syntax, multiline definitions, and unconventional formatting.
Regex-Based Parsing (Other Languages): For other languages (C++, C#, Java, JavaScript, TypeScript, Kotlin, PowerShell, Delphi), the generator relies on regular expressions and simplified scope analysis (brace counting). This method is inherently more fragile and may fail or produce incorrect results with:
{ or } characters, leading to incorrect structure detection.In-Place File Modification: The tool modifies files directly. It is designed to correctly remove its own previously generated headers, but it might struggle with files that have very complex, pre-existing header comments, potentially leading to incorrect placement of the new header.
Add to your .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: agent-docstrings
name: Generate docstrings
entry: agent-docstrings
language: system
files: \.(py|java|kt|go|ps1|psm1|pas|js|jsx|ts|tsx|cs|cpp|cxx|cc|hpp|h|c)$
pass_filenames: false
args: [src/]
# GitHub Actions example
- name: Generate docstrings
run: |
pip install agent-docstrings
agent-docstrings src/
# Check if any files were modified
git diff --exit-code || (echo "Docstrings need updating" && exit 1)
git clone https://github.com/Artemonim/agent-docstrings.git
cd agent-docstrings
pip install -e .[dev]
pytest tests/ -v
black agent_docstrings/
mypy agent_docstrings/
This project uses bump-my-version for version management. To create a new version, use the following commands after installing the development dependencies (pip install -e .[dev]):
bump-my-version patch
bump-my-version minor
bump-my-version major
The tool is configured in pyproject.toml to automatically update the version string in agent_docstrings/__init__.py, pyproject.toml, and CHANGELOG.md.
Note: Running bump-my-version, you need to create a release branch and a pull request to master. The process of tagging, creating a GitHub Release, and publishing to PyPI is automated. For full details, see the Contribution Guide.
Agent Docstrings is an independent open-source project. If you find this tool useful and want to support its ongoing development, your help would be greatly appreciated.
Here are a few ways you can contribute:
Thank you for your support!
We welcome contributions! Please see our Contribution Guide for detailed instructions on how to get started, our development workflow, and coding standards.
In short:
dev.CHANGELOG.md.dev.This project is licensed under the MIT License - see the LICENSE file for details.
See CHANGELOG.md for a list of changes and version history.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 1.3.5 | 9 Jul 2025 | 6 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 21:49 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:dbcac31c1c263cfae037d65cfc09d1c2e6fe6e94328c0f858d42dfbbcb2ce292