klg-asutk-app/backend/app/services/legal_agents/base.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

41 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Базовый класс для ИИ-агентов юридического анализа.
"""
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Any
@dataclass
class AgentResult:
"""Результат работы агента."""
success: bool
data: dict[str, Any] = field(default_factory=dict)
error: str | None = None
agent_name: str = ""
class BaseLegalAgent(ABC):
"""Базовый агент. Все агенты должны уметь вызывать LLM и возвращать структурированный результат."""
def __init__(self, name: str, llm_client: Any = None):
self.name = name
self.llm = llm_client
def _call_llm(self, system: str, user: str, json_mode: bool = False) -> str | None:
"""Вызов LLM. Поддерживает OpenAI-совместимый API. При отсутствии ключа — заглушка."""
if self.llm is None:
return None
try:
if hasattr(self.llm, "chat") and callable(self.llm.chat):
return self.llm.chat(system=system, user=user, json_mode=json_mode)
return None
except Exception:
return None
@abstractmethod
def run(self, context: dict[str, Any]) -> AgentResult:
"""Выполнить задачу агента. context: документ, юрисдикция, текст и т.д."""
pass