# 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
```bash
pip install openhands-dynamic-agent-factory
```
### Technology-Specific Dependencies
Choose the dependencies based on your needs:
```bash
# 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
```python
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:
```python
# 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:
```python
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:
```python
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
1. Fork the repository
2. Create your feature branch:
```bash
git checkout -b feature/amazing-feature
```
3. Make your changes and commit:
```bash
git commit -m 'Add amazing feature'
```
4. Push to your branch:
```bash
git push origin feature/amazing-feature
```
5. Open a Pull Request
### Development Setup
1. Clone the repository
2. Install development dependencies:
```bash
pip install -e ".[dev]"
```
3. Run tests:
```bash
pytest tests/
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- Built on top of the [OpenHands](https://github.com/All-Hands-AI/OpenHands) framework
- Powered by state-of-the-art LLM capabilities
- Inspired by the need for intelligent, technology-specific code analysis
Raw data
{
"_id": null,
"home_page": null,
"name": "openhands-dynamic-agent-factory",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "openhands, llm, agent, factory, code-analysis",
"author": null,
"author_email": "Makafeli <info@yasin.nu>",
"download_url": "https://files.pythonhosted.org/packages/6a/bf/afc6b8912e01fe958f69cccce1a49ba46e9e73223ac57904a52660f6ab4c/openhands_dynamic_agent_factory-0.1.0.tar.gz",
"platform": null,
"description": "# OpenHands Dynamic Agent Factory\n\nA 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.\n\n## Features\n\n- \ud83e\udd16 **Dynamic Agent Generation**: Automatically create specialized micro-agents based on technology keywords\n- \ud83d\udd04 **OpenHands Integration**: Seamless integration with OpenHands' LLM configuration system\n- \ud83d\udee1\ufe0f **Security First**: Built-in code validation and security checks\n- \ud83c\udfaf **Technology-Specific**: Pre-configured for Python, React, Node.js, and SQL analysis\n- \ud83d\udd0c **Extensible**: Easy to add new technology triggers and customizations\n- \u26a1 **Production Ready**: Comprehensive error handling and validation\n\n## Installation\n\n### Prerequisites\n\n- Python 3.7 or higher\n- OpenHands framework\n- Access to an LLM provider (e.g., OpenAI)\n\n### Basic Installation\n\n```bash\npip install openhands-dynamic-agent-factory\n```\n\n### Technology-Specific Dependencies\n\nChoose the dependencies based on your needs:\n\n```bash\n# Python analysis support\npip install \"openhands-dynamic-agent-factory[python]\"\n\n# React analysis support\npip install \"openhands-dynamic-agent-factory[react]\"\n\n# Node.js analysis support\npip install \"openhands-dynamic-agent-factory[node]\"\n\n# SQL analysis support\npip install \"openhands-dynamic-agent-factory[sql]\"\n\n# All technologies\npip install \"openhands-dynamic-agent-factory[all]\"\n```\n\n## Quick Start\n\n### Basic Usage\n\n```python\nfrom openhands_dynamic_agent_factory import DynamicAgentFactoryLLM\n\n# Initialize the factory\nfactory = DynamicAgentFactoryLLM()\n\n# Generate a Python code analyzer\nresult = factory.run({\n \"technology_keyword\": \"python\",\n \"options\": {\n \"analysis_type\": \"security\"\n }\n})\n\n# Use the generated agent\nif result[\"agent_class\"]:\n agent = result[\"agent_class\"]()\n analysis = agent.run({\n \"code_snippet\": \"\"\"\n def process_data(user_input):\n return eval(user_input) # Security risk!\n \"\"\",\n \"analysis_type\": \"security\"\n })\n print(analysis)\n```\n\n### Configuration\n\nConfigure your OpenHands LLM settings in your project:\n\n```python\n# config.py\nfrom openhands.config import Config\n\nconfig = Config({\n \"llm\": {\n \"provider\": \"openai\",\n \"model\": \"gpt-4\",\n \"api_key\": \"your-api-key\",\n \"temperature\": 0.7\n }\n})\n```\n\nThe factory will automatically use these settings from your OpenHands configuration.\n\n## Supported Technologies\n\n### Python Analysis\n- **Input**: Python code snippets\n- **Analysis Types**: \n - Style (PEP 8 compliance)\n - Security (vulnerability detection)\n - Performance (optimization suggestions)\n- **Outputs**: Detailed analysis report with:\n - Code quality metrics\n - Security vulnerabilities\n - Performance recommendations\n\n### React Analysis\n- **Input**: React/JSX components\n- **Features**: \n - Component structure analysis\n - Hooks usage patterns\n - Performance optimization\n- **Outputs**: \n - Best practices compliance\n - Performance bottlenecks\n - Accessibility issues\n\n### Node.js Analysis\n- **Input**: Node.js/JavaScript code\n- **Focus Areas**: \n - Security vulnerabilities\n - Async/await patterns\n - Scalability issues\n- **Outputs**: \n - Security audit report\n - Performance metrics\n - Best practices suggestions\n\n### SQL Analysis\n- **Input**: SQL queries\n- **Features**: \n - Query optimization\n - Injection prevention\n - Performance analysis\n- **Outputs**: \n - Optimization suggestions\n - Security recommendations\n - Execution plan analysis\n\n## Advanced Usage\n\n### Custom Technology Triggers\n\nAdd your own technology-specific analyzers:\n\n```python\nfrom openhands_dynamic_agent_factory import TRIGGER_MAP, TriggerInfo\n\n# Define a new Java analyzer\nTRIGGER_MAP[\"java\"] = TriggerInfo(\n class_name=\"JavaAnalyzer\",\n description=\"Advanced Java code analyzer\",\n inputs=[\"code_snippet\", \"analysis_type\"],\n outputs=[\"analysis_report\", \"suggestions\"],\n required_imports=[\"javalang\"],\n validation_rules={\n \"max_code_length\": 10000,\n \"required_fields\": [\"code_snippet\"]\n },\n llm_prompt_template=\"\"\"\n Create a Java code analyzer that:\n 1. Parses the input using javalang\n 2. Analyzes for {analysis_type}\n 3. Returns detailed suggestions\n \"\"\"\n)\n```\n\n### Error Handling\n\nThe factory provides comprehensive error handling:\n\n```python\ntry:\n result = factory.run({\n \"technology_keyword\": \"python\",\n \"options\": {\"analysis_type\": \"security\"}\n })\n if result[\"agent_class\"] is None:\n error_info = result[\"generation_info\"]\n print(f\"Agent generation failed: {error_info['error']}\")\n print(f\"Details: {error_info.get('details', 'No additional details')}\")\nexcept Exception as e:\n print(f\"Unexpected error: {str(e)}\")\n```\n\n## Project Structure\n\n```\nopenhands-dynamic-agent-factory/\n\u251c\u2500\u2500 openhands_dynamic_agent_factory/\n\u2502 \u251c\u2500\u2500 core/\n\u2502 \u2502 \u251c\u2500\u2500 factory.py # Main factory implementation\n\u2502 \u2502 \u251c\u2500\u2500 triggers.py # Technology trigger definitions\n\u2502 \u2502 \u2514\u2500\u2500 dynamic_agent_factory_llm.py\n\u2502 \u2514\u2500\u2500 __init__.py\n\u251c\u2500\u2500 examples/\n\u2502 \u2514\u2500\u2500 basic_usage.py # Usage examples\n\u251c\u2500\u2500 README.md\n\u251c\u2500\u2500 LICENSE\n\u2514\u2500\u2500 pyproject.toml\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch:\n ```bash\n git checkout -b feature/amazing-feature\n ```\n3. Make your changes and commit:\n ```bash\n git commit -m 'Add amazing feature'\n ```\n4. Push to your branch:\n ```bash\n git push origin feature/amazing-feature\n ```\n5. Open a Pull Request\n\n### Development Setup\n\n1. Clone the repository\n2. Install development dependencies:\n ```bash\n pip install -e \".[dev]\"\n ```\n3. Run tests:\n ```bash\n pytest tests/\n ```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n- Built on top of the [OpenHands](https://github.com/All-Hands-AI/OpenHands) framework\n- Powered by state-of-the-art LLM capabilities\n- Inspired by the need for intelligent, technology-specific code analysis\n",
"bugtrack_url": null,
"license": null,
"summary": "Dynamic agent factory for OpenHands that generates micro-agents based on technology keywords",
"version": "0.1.0",
"project_urls": {
"Bug Tracker": "https://github.com/makafeli/openhands-dynamic-agent-factor/issues",
"Homepage": "https://github.com/makafeli/openhands-dynamic-agent-factor"
},
"split_keywords": [
"openhands",
" llm",
" agent",
" factory",
" code-analysis"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7fe0dc675c6b2c2fccb8274ad89fafa7fa9088f0625b42f3309ecb5ebae763df",
"md5": "034efb03dc7a223813843c29bc12ef6c",
"sha256": "4ff416af8472f74cfe7a4fcb08ff3236d572c1db6bdb39d496c93f62d212ca21"
},
"downloads": -1,
"filename": "openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "034efb03dc7a223813843c29bc12ef6c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 16280,
"upload_time": "2024-12-29T22:36:04",
"upload_time_iso_8601": "2024-12-29T22:36:04.751901Z",
"url": "https://files.pythonhosted.org/packages/7f/e0/dc675c6b2c2fccb8274ad89fafa7fa9088f0625b42f3309ecb5ebae763df/openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6abfafc6b8912e01fe958f69cccce1a49ba46e9e73223ac57904a52660f6ab4c",
"md5": "4dffcf7f2a5dd9398ed12c81ec0d6058",
"sha256": "a6083b9548028d258d39ca00e380e497de1e587a7fae2dc7577b850636ba9d07"
},
"downloads": -1,
"filename": "openhands_dynamic_agent_factory-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "4dffcf7f2a5dd9398ed12c81ec0d6058",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 12720,
"upload_time": "2024-12-29T22:36:09",
"upload_time_iso_8601": "2024-12-29T22:36:09.465089Z",
"url": "https://files.pythonhosted.org/packages/6a/bf/afc6b8912e01fe958f69cccce1a49ba46e9e73223ac57904a52660f6ab4c/openhands_dynamic_agent_factory-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-29 22:36:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "makafeli",
"github_project": "openhands-dynamic-agent-factor",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "openhands-dynamic-agent-factory"
}