Spaces:
Sleeping
Sleeping
File size: 1,625 Bytes
d677097 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | # 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
|