Skip to main content

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

  1. Fork the repository
  2. Create your feature branch:
    git checkout -b feature/amazing-feature
    
  3. Make your changes and commit:
    git commit -m 'Add amazing feature'
    
  4. Push to your branch:
    git push origin feature/amazing-feature
    
  5. Open a Pull Request

Development Setup

  1. Clone the repository
  2. Install development dependencies:
    pip install -e ".[dev]"
    
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openhands_dynamic_agent_factory-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file openhands_dynamic_agent_factory-0.1.0.tar.gz.

File metadata

File hashes

Hashes for openhands_dynamic_agent_factory-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a6083b9548028d258d39ca00e380e497de1e587a7fae2dc7577b850636ba9d07
MD5 4dffcf7f2a5dd9398ed12c81ec0d6058
BLAKE2b-256 6abfafc6b8912e01fe958f69cccce1a49ba46e9e73223ac57904a52660f6ab4c

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openhands_dynamic_agent_factory-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ff416af8472f74cfe7a4fcb08ff3236d572c1db6bdb39d496c93f62d212ca21
MD5 034efb03dc7a223813843c29bc12ef6c
BLAKE2b-256 7fe0dc675c6b2c2fccb8274ad89fafa7fa9088f0625b42f3309ecb5ebae763df

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page