klg-asutk-app/backend/app/services/legal_agents/formatting.py
Yuriy 0150aba4f5 Consolidation: KLG ASUTK + PAPA integration
- Unify API: lib/api.ts uses /api/v1, inbox uses /api/inbox (rewrites)
- Remove localhost refs: openapi, inbox page
- Add rewrites: /api/inbox|tmc -> inbox-server, /api/v1 -> FastAPI
- Add stub routes: knowledge/insights, recommendations, search, log-error
- Transfer from PAPA: prompts (inspection, tmc), scripts, supabase, data/tmc-requests
- Fix inbox-server: ORDER BY created_at, package.json
- Remove redundant app/api/inbox/files route (rewrites handle it)
- knowledge/ in gitignore (large PDFs)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 17:18:31 +03:00

51 lines
2.2 KiB
Python

"""
Агент форматирования документа по требованиям юрисдикции (структура, оформление, стиль).
"""
import json
from .base import BaseLegalAgent, AgentResult
class FormattingAgent(BaseLegalAgent):
def __init__(self, llm_client=None):
super().__init__("FormattingAgent", llm_client)
def run(self, context: dict) -> AgentResult:
content = (context.get("content") or "")[:6000]
jurisdiction = context.get("jurisdiction_code", "RU")
doc_type = context.get("document_type", "other")
system = (
"Ты — эксперт по оформлению юридических документов. Дай рекомендации по структуре и стилю. "
"Верни JSON: {\"structure_ok\": true|false, \"suggestions\": [\"...\"], \"required_sections\": [\"...\"], \"style_notes\": \"...\"}"
)
user = f"Юрисдикция: {jurisdiction}, тип: {doc_type}\n\nТекст:\n{content[:3500]}"
out = self._call_llm(system, user, json_mode=True)
if out:
try:
data = json.loads(out)
return AgentResult(
True,
{
"structure_ok": bool(data.get("structure_ok", True)),
"suggestions": data.get("suggestions") or [],
"required_sections": data.get("required_sections") or [],
"style_notes": data.get("style_notes") or "",
},
agent_name=self.name,
)
except (json.JSONDecodeError, TypeError):
pass
return AgentResult(
True,
{
"structure_ok": True,
"suggestions": ["Провести ручную выверку оформления по ГОСТ/локальным правилам."],
"required_sections": ["преамбула", "основная часть", "заключительные положения"],
"style_notes": "Рекомендации недоступны (LLM отключён).",
},
agent_name=self.name,
)