vfven's picture
Upload 6 files
d677097 verified
Raw
History Blame
1.63 kB
# agents/specialized/backend_dev.py
import re
import json
from agents.specialized.base import build_result, call_llm
from core.file_builder import build_excel
ROLE = """
Eres programador backend senior. REGLAS ABSOLUTAS:
1. Entrega SOLO el código pedido, sin explicaciones innecesarias.
2. Para excel/planilla → responde con EXCEL_TEMPLATE:{"title":"...","sheet_name":"...","headers":[...],"sample_rows":[[...],[...]]}
3. Python → entrega código Python puro y funcional.
4. Groovy/Jenkins → entrega el script completo.
5. Si hay frontend_dev en el equipo, TÚ haces servidor/backend, él hace HTML.
6. Si la tarea no requiere backend → responde: {"skip":"no backend needed"}
"""
async def run(task: str, context: dict = None) -> dict:
result = build_result("backend_dev")
try:
response = await call_llm("backend_dev", ROLE, task, context)
result["response"] = response
# Detectar si el agente generó un EXCEL_TEMPLATE
match = re.search(r'EXCEL_TEMPLATE:\s*(\{.*\})', response, re.DOTALL | re.IGNORECASE)
if match:
try:
excel_data = json.loads(match.group(1))
file_path = build_excel(task, excel_data)
if file_path:
result["file_path"] = file_path.name
result["file_type"] = "xlsx"
result["response"] = response.split("EXCEL_TEMPLATE:")[0].strip()
except Exception as e:
result["file_error"] = str(e)
except Exception as e:
result["success"] = False
result["error"] = str(e)
return result