ai_virtual_dev_pod / agents /developer.py
parthib07's picture
Upload 52 files
e5e882e verified
from core.base_agent import BaseAgent
from core.database import db
from typing import Dict, Any
class DeveloperAgent(BaseAgent):
def __init__(self):
super().__init__("Developer")
self.create_chain("""
You are an expert Software Developer. Your task is to generate production-ready, well-structured code based on the given design specifications.
Design Specifications:
{input}
Generate code that follows these strict guidelines:
1. Code Structure:
- Use proper project structure with separate modules
- Follow SOLID principles
- Implement proper error handling
- Use type hints
- Include comprehensive docstrings
- Follow PEP 8 style guide
2. Implementation Details:
- Use modern Python features (Python 3.9+)
- Implement proper logging
- Add input validation
- Include unit tests
- Use dependency injection where appropriate
- Implement proper configuration management
3. Security:
- Sanitize all inputs
- Implement proper authentication/authorization
- Use secure coding practices
- Handle sensitive data properly
4. Performance:
- Optimize database queries
- Implement caching where appropriate
- Use async/await for I/O operations
- Implement proper resource management
5. Documentation:
- Include detailed module docstrings
- Document all public methods
- Include usage examples
- Document configuration options
The code should be:
- Production-ready
- Well-tested
- Scalable
- Maintainable
- Secure
- Performant
Provide the complete implementation with all necessary files and dependencies.
""")
async def generate_code(self, design: str) -> Dict[str, Any]:
"""Generate code from design specifications"""
result = await self.process({"input": design})
# Store the code in the database
db.store_artifact(
"code",
result,
{
"type": "code",
"source": "developer",
"status": "created",
"version": "1.0.0"
}
)
return {
"status": "success",
"code": result,
"message": "Code generated successfully",
"metadata": {
"language": "Python",
"framework": "Standard Library",
"dependencies": self._extract_dependencies(result)
}
}
def _extract_dependencies(self, code: str) -> list:
"""Extract dependencies from the generated code"""
dependencies = set()
# Add common dependencies
dependencies.update([
"python-dotenv",
"pydantic",
"fastapi",
"uvicorn",
"pytest",
"pytest-asyncio"
])
# Add dependencies based on code content
if "import sqlalchemy" in code:
dependencies.add("sqlalchemy")
if "import aiohttp" in code:
dependencies.add("aiohttp")
if "import redis" in code:
dependencies.add("redis")
if "import jwt" in code:
dependencies.add("PyJWT")
return sorted(list(dependencies))