OpenHands Dynamic Agent Factory
A powerful extension for OpenHands that provides dynamic agent generation capabilities based on technology keywords. This module automatically creates specialized micro-agents for analyzing different technologies like Python, React, Node.js, and SQL using LLM-powered code generation.
Features
- 🤖 Dynamic Agent Generation: Automatically create specialized micro-agents based on technology keywords
- 🔄 OpenHands Integration: Seamless integration with OpenHands' LLM configuration system
- 🛡️ Security First: Built-in code validation and security checks
- 🎯 Technology-Specific: Pre-configured for Python, React, Node.js, and SQL analysis
- 🔌 Extensible: Easy to add new technology triggers and customizations
- ⚡ Production Ready: Comprehensive error handling and validation
Installation
Prerequisites
- Python 3.7 or higher
- OpenHands framework
- Access to an LLM provider (e.g., OpenAI)
Basic Installation
pip install openhands-dynamic-agent-factory
Technology-Specific Dependencies
Choose the dependencies based on your needs:
# Python analysis support
pip install "openhands-dynamic-agent-factory[python]"
# React analysis support
pip install "openhands-dynamic-agent-factory[react]"
# Node.js analysis support
pip install "openhands-dynamic-agent-factory[node]"
# SQL analysis support
pip install "openhands-dynamic-agent-factory[sql]"
# All technologies
pip install "openhands-dynamic-agent-factory[all]"
Quick Start
Basic Usage
from openhands_dynamic_agent_factory import DynamicAgentFactoryLLM
# Initialize the factory
factory = DynamicAgentFactoryLLM()
# Generate a Python code analyzer
result = factory.run({
"technology_keyword": "python",
"options": {
"analysis_type": "security"
}
})
# Use the generated agent
if result["agent_class"]:
agent = result["agent_class"]()
analysis = agent.run({
"code_snippet": """
def process_data(user_input):
return eval(user_input) # Security risk!
""",
"analysis_type": "security"
})
print(analysis)
Configuration
Configure your OpenHands LLM settings in your project:
# config.py
from openhands.config import Config
config = Config({
"llm": {
"provider": "openai",
"model": "gpt-4",
"api_key": "your-api-key",
"temperature": 0.7
}
})
The factory will automatically use these settings from your OpenHands configuration.
Supported Technologies
Python Analysis
- Input: Python code snippets
- Analysis Types:
- Style (PEP 8 compliance)
- Security (vulnerability detection)
- Performance (optimization suggestions)
- Outputs: Detailed analysis report with:
- Code quality metrics
- Security vulnerabilities
- Performance recommendations
React Analysis
- Input: React/JSX components
- Features:
- Component structure analysis
- Hooks usage patterns
- Performance optimization
- Outputs:
- Best practices compliance
- Performance bottlenecks
- Accessibility issues
Node.js Analysis
- Input: Node.js/JavaScript code
- Focus Areas:
- Security vulnerabilities
- Async/await patterns
- Scalability issues
- Outputs:
- Security audit report
- Performance metrics
- Best practices suggestions
SQL Analysis
- Input: SQL queries
- Features:
- Query optimization
- Injection prevention
- Performance analysis
- Outputs:
- Optimization suggestions
- Security recommendations
- Execution plan analysis
Advanced Usage
Custom Technology Triggers
Add your own technology-specific analyzers:
from openhands_dynamic_agent_factory import TRIGGER_MAP, TriggerInfo
# Define a new Java analyzer
TRIGGER_MAP["java"] = TriggerInfo(
class_name="JavaAnalyzer",
description="Advanced Java code analyzer",
inputs=["code_snippet", "analysis_type"],
outputs=["analysis_report", "suggestions"],
required_imports=["javalang"],
validation_rules={
"max_code_length": 10000,
"required_fields": ["code_snippet"]
},
llm_prompt_template="""
Create a Java code analyzer that:
1. Parses the input using javalang
2. Analyzes for {analysis_type}
3. Returns detailed suggestions
"""
)
Error Handling
The factory provides comprehensive error handling:
try:
result = factory.run({
"technology_keyword": "python",
"options": {"analysis_type": "security"}
})
if result["agent_class"] is None:
error_info = result["generation_info"]
print(f"Agent generation failed: {error_info['error']}")
print(f"Details: {error_info.get('details', 'No additional details')}")
except Exception as e:
print(f"Unexpected error: {str(e)}")
Project Structure
openhands-dynamic-agent-factory/
├── openhands_dynamic_agent_factory/
│ ├── core/
│ │ ├── factory.py # Main factory implementation
│ │ ├── triggers.py # Technology trigger definitions
│ │ └── dynamic_agent_factory_llm.py
│ └── __init__.py
├── examples/
│ └── basic_usage.py # Usage examples
├── README.md
├── LICENSE
└── pyproject.toml
Contributing
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature
- Make your changes and commit:
git commit -m 'Add amazing feature'
- Push to your branch:
git push origin feature/amazing-feature
- Open a Pull Request
Development Setup
- Clone the repository
- Install development dependencies:
pip install -e ".[dev]"
- Run tests:
pytest tests/
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built on top of the OpenHands framework
- Powered by state-of-the-art LLM capabilities
- Inspired by the need for intelligent, technology-specific code analysis
Metadata
Release files for openhands-dynamic-agent-factory 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| openhands_dynamic_agent_factory-0.1.0.tar.gz | 12.7 kB | With provenance | Details for openhands_dynamic_agent_factory-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl |
Total release size: 29.0 kB
Release files / openhands_dynamic_agent_factory-0.1.0.tar.gz
| Download URL | openhands_dynamic_agent_factory-0.1.0.tar.gz |
|---|---|
| Size | 12.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6083b9548028d258d39ca00e380e497de1e587a7fae2dc7577b850636ba9d07
|
|
BLAKE2b-256 checksum How to use checksums |
6abfafc6b8912e01fe958f69cccce1a49ba46e9e73223ac57904a52660f6ab4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 29, 2024.
Transparency logRelease files / openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl
| Download URL | openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ff416af8472f74cfe7a4fcb08ff3236d572c1db6bdb39d496c93f62d212ca21
|
|
BLAKE2b-256 checksum How to use checksums |
7fe0dc675c6b2c2fccb8274ad89fafa7fa9088f0625b42f3309ecb5ebae763df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 29, 2024.
Transparency logSecurity for openhands-dynamic-agent-factory 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for openhands_dynamic_agent_factory-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 29, 2024.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.