A sophisticated documentation system that uses specialized AI agents to automatically generate, review, and insert high-quality docstrings into Python codebases.
- Project Overview
- Key Features
- Project Structure
- System Architecture
- Installation
- Usage
- Demo
- Technologies Used
- Testing
- Contributing
- License
This project is a comprehensive Python documentation system developed in three progressive parts:
The foundation of the system, integrating documentation tools with LlamaIndex to create an agent that can help with Python code documentation tasks:
- Code parsing to extract function and class definitions
- Docstring generation using Google style format
- Docstring analysis to check completeness and identify issues
- Interactive agent for natural language documentation queries
Extends the documentation assistant with web browsing capabilities:
- Web browsing capabilities using Playwright
- Searching documentation standards (e.g., Google Python Style Guide)
- Looking up library documentation online
- Improving docstrings based on best practices found on the web
The complete system with a sophisticated multi-agent architecture:
- Coordinator Agent orchestrates the workflow between specialized agents
- Code Analyzer Agent analyzes code structure and detects undocumented elements
- Docstring Generator Agent creates appropriate docstrings for code elements
- Documentation Reviewer Agent reviews and improves generated docstrings
- File Tools for reading, writing, and manipulating Python files
- Configuration System for customizable documentation settings
- Automated Documentation: Automatically generate high-quality docstrings for Python code
- Multi-Agent Architecture: Specialized agents working together for optimal results
- Customizable Docstring Styles: Support for Google, NumPy, and Sphinx docstring formats
- Intelligent Code Analysis: Understands code structure and relationships
- Quality Assurance: Reviews and improves generated docstrings
- Web Integration: References documentation standards and library documentation online
- Configurable Workflow: Customize the documentation process to fit your needs
- Comprehensive Reporting: Detailed reports on the documentation process
project/
โโโ part1/ # Basic documentation agent
โ โโโ agent.py # LlamaIndex agent integration
โ โโโ code_parser.py # Code parsing functionality
โ โโโ docstring_analyzer.py # Docstring analysis tools
โ โโโ docstring_generator.py # Docstring generation tools
โ โโโ main.py # Simple demo without agent
โ โโโ README.md # Part 1 documentation
โ
โโโ part2/ # Web-enhanced documentation agent
โ โโโ playwright_agent.py # Agent with web browsing capabilities
โ โโโ workflow_example.py # Example workflows
โ โโโ README.md # Part 2 documentation
โ
โโโ part3/ # Multi-agent documentation system
โ โโโ code_analyzer_agent.py # Code analysis agent
โ โโโ coordinator_agent.py # Workflow coordination agent
โ โโโ docstring_generator_agent.py # Docstring generation agent
โ โโโ doc_reviewer_agent.py # Documentation review agent
โ โโโ file_tools.py # File manipulation utilities
โ โโโ main.py # Main entry point
โ โโโ multi_agent_manager.py # Agent management system
โ โโโ README.md # Part 3 documentation
โ
โโโ tests/ # Test suite
โ โโโ tests/ # Test files
โ โโโ test_code_analyzer.py
โ โโโ test_docstring_generator.py
โ โโโ test_docstring_inserter.py
โ โโโ test_end_to_end.py
โ โโโ test_file_tools.py
โ
โโโ servers/ # MCP server implementations
โโโ README.md # Servers documentation
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DocumentationAgentManager โ
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ Coordinator โ โ Code โ โ Docstring โ โ Documentationโ โ
โ โ Agent โ<->โ Analyzer โ<->โ Generator โ<->โ Reviewer โ โ
โ โ โ โ Agent โ โ Agent โ โ Agent โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Python โ โ Generated โ โ Documented โ
โ Codebase โ -> โ Docstrings โ -> โ Codebase โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
- Python 3.8 or higher
- OpenAI API key
-
Clone the repository:
git clone https://github.com/yourusername/python-documentation-system.git cd python-documentation-system -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the required dependencies:
# For basic documentation agent (Part 1) pip install -r part1/requirements.txt # For web-enhanced agent (Part 2) pip install -r part2/playwright_requirements.txt python -m playwright install # For multi-agent system (Part 3) pip install -r part3/requirements.txt
-
Set up your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here" # On Windows: set OPENAI_API_KEY=your-api-key-here
Run the interactive agent:
cd part1
python agent.pyExample commands:
Document this function: def calculate_area(length, width): return length * width
Run the agent with web browsing capabilities:
cd part2
python playwright_agent.pyExample commands:
Look up Python docstring standards and tell me the recommended format
Process a Python codebase:
cd part3
python main.py --directory path/to/your/python/codeOr use the Python API:
from multi_agent_manager import DocumentationAgentManager
# Initialize the documentation agent manager
manager = DocumentationAgentManager()
# Process a codebase
results = manager.process_codebase("path/to/your/python/code")
# Print a summary of the results
print(f"Files processed: {results['files_processed']}")
print(f"Files completed: {len(results['files_completed'])}")
print(f"Files with errors: {len(results['files_failed'])}")A quick demo of the Multi-Agent Documentation System is available:
cd part3
./run_demo.shThis will:
- Create a demo directory with a sample Python file
- Show the original undocumented code
- Run the documentation system on the file
- Show the newly documented code
- Explain the system architecture
- LlamaIndex: For agent framework and LLM integration
- OpenAI: For accessing language models
- Playwright: For web browsing capabilities
- astor & astunparse: For Python AST manipulation
- pytest: For testing
- pyyaml: For configuration file parsing
Run the test suite:
cd tests
pytestRun specific tests:
# Run unit tests only
pytest -m unit
# Run a specific test file
pytest tests/test_code_analyzer.py
# Generate test coverage report
pytest --cov=. tests/Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.