File size: 1,207 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
# agents/specialized/writer.py
from agents.specialized.base import build_result, call_llm
from core.file_builder import build_docx

ROLE = """
Eres redactor experto. Escribe SOLO contenido real y extenso (500+ palabras).
Sin placeholders. Usa ## para secciones y ### para subsecciones.
Secciones: ## Resumen Ejecutivo, ### Introducción, ### Desarrollo,
### Hallazgos, ### Conclusiones, ### Recomendaciones
"""


async def run(task: str, context: dict = None) -> dict:
    result = build_result("writer")
    try:
        response = await call_llm("writer", ROLE, task, context)
        result["response"] = response

        # Si la respuesta es suficientemente larga, generar un .docx
        if len(response.strip()) > 300:
            title = task[:60].strip('"') or "Informe generado"
            try:
                file_path = build_docx(title, response, images=None)
                if file_path:
                    result["file_path"] = file_path.name
                    result["file_type"] = "docx"
            except Exception as e:
                result["file_error"] = str(e)

    except Exception as e:
        result["success"] = False
        result["error"] = str(e)

    return result