Metadata-Version: 2.1
Name: openhands_dynamic_agent_factory
Version: 0.1.0
Summary: Dynamic agent factory for OpenHands that generates micro-agents based on technology keywords
Author-email: Makafeli <info@yasin.nu>
Project-URL: Homepage, https://github.com/makafeli/openhands-dynamic-agent-factor
Project-URL: Bug Tracker, https://github.com/makafeli/openhands-dynamic-agent-factor/issues
Keywords: openhands,llm,agent,factory,code-analysis
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openhands>=0.17.0
Requires-Dist: dataclasses; python_version < "3.7"
Provides-Extra: python
Requires-Dist: ast; extra == "python"
Requires-Dist: pylint>=3.0.0; extra == "python"
Provides-Extra: react
Requires-Dist: esprima>=4.0.0; extra == "react"
Requires-Dist: eslint>=8.0.0; extra == "react"
Provides-Extra: node
Requires-Dist: acorn>=8.0.0; extra == "node"
Requires-Dist: eslint>=8.0.0; extra == "node"
Provides-Extra: sql
Requires-Dist: sqlparse>=0.4.0; extra == "sql"
Requires-Dist: sqlalchemy>=2.0.0; extra == "sql"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: isort>=5.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Provides-Extra: all
Requires-Dist: ast; extra == "all"
Requires-Dist: pylint>=3.0.0; extra == "all"
Requires-Dist: esprima>=4.0.0; extra == "all"
Requires-Dist: eslint>=8.0.0; extra == "all"
Requires-Dist: acorn>=8.0.0; extra == "all"
Requires-Dist: sqlparse>=0.4.0; extra == "all"
Requires-Dist: sqlalchemy>=2.0.0; extra == "all"

# 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
