Dynamic agent factory for OpenHands that generates micro-agents based on technology keywords
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openhands_dynamic_agent_factory-0.1.0.tar.gz.
File metadata
- Download URL: openhands_dynamic_agent_factory-0.1.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6083b9548028d258d39ca00e380e497de1e587a7fae2dc7577b850636ba9d07
|
|
| MD5 |
4dffcf7f2a5dd9398ed12c81ec0d6058
|
|
| BLAKE2b-256 |
6abfafc6b8912e01fe958f69cccce1a49ba46e9e73223ac57904a52660f6ab4c
|
Provenance
The following attestation bundles were made for openhands_dynamic_agent_factory-0.1.0.tar.gz:
Publisher:
publish.yml on makafeli/openhands-dynamic-agent-factor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openhands_dynamic_agent_factory-0.1.0.tar.gz -
Subject digest:
a6083b9548028d258d39ca00e380e497de1e587a7fae2dc7577b850636ba9d07 - Sigstore transparency entry: 158148204
- Sigstore integration time:
-
Permalink:
makafeli/openhands-dynamic-agent-factor@757eb8ca519e051fd4886a233b7bdbda60389fe8 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/makafeli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@757eb8ca519e051fd4886a233b7bdbda60389fe8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ff416af8472f74cfe7a4fcb08ff3236d572c1db6bdb39d496c93f62d212ca21
|
|
| MD5 |
034efb03dc7a223813843c29bc12ef6c
|
|
| BLAKE2b-256 |
7fe0dc675c6b2c2fccb8274ad89fafa7fa9088f0625b42f3309ecb5ebae763df
|
Provenance
The following attestation bundles were made for openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on makafeli/openhands-dynamic-agent-factor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl -
Subject digest:
4ff416af8472f74cfe7a4fcb08ff3236d572c1db6bdb39d496c93f62d212ca21 - Sigstore transparency entry: 158148205
- Sigstore integration time:
-
Permalink:
makafeli/openhands-dynamic-agent-factor@757eb8ca519e051fd4886a233b7bdbda60389fe8 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/makafeli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@757eb8ca519e051fd4886a233b7bdbda60389fe8 -
Trigger Event:
release
-
Statement type: