PMFlow/backend/app/services/ai_pmo_kernel_runtime.py

58 lines
2.2 KiB
Python
Raw 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.

"""AI PMO kernel runtime composition."""
from __future__ import annotations
from . import ai_pmo_kernel_common as _common
for _name, _value in vars(_common).items():
if not _name.startswith("__"):
globals()[_name] = _value
from .ai_pmo_kernel_mixins_closure import KernelClosureMixin
from .ai_pmo_kernel_mixins_followup import KernelFollowupMixin
from .ai_pmo_kernel_mixins_ingress import KernelIngressMixin
from .ai_pmo_kernel_mixins_intent import KernelIntentMixin
from .ai_pmo_kernel_mixins_world_model import KernelWorldModelMixin
class AIPMOKernelService(
KernelIngressMixin,
KernelWorldModelMixin,
KernelIntentMixin,
KernelFollowupMixin,
KernelClosureMixin,
):
"""AI PMO kernel,作为新的统一事实链。"""
def __init__(self, db: AsyncSession, tenant_id: int = 1) -> None:
self.db = db
self.tenant_id = int(tenant_id)
self._background_session_factory = self._build_background_session_factory(db)
self.context_cache = ContextCacheService()
self.intent_resolver = IntentResolver()
self.route_resolver = RouteResolver()
self.decision_engine = DecisionEngine(policy_gate_rules=POLICY_GATE_RULES)
self.reply_renderer = ReplyRenderer(
state_waiting_manual=STATE_WAITING_MANUAL,
state_failed=STATE_FAILED,
receipt_phase_action=RECEIPT_PHASE_ACTION,
receipt_phase_pending=RECEIPT_PHASE_PENDING,
receipt_phase_error=RECEIPT_PHASE_ERROR,
)
self.executor = TypedExecutor(db, tenant_id=self.tenant_id)
self.context_assembler = ContextAssembler(self)
self.workflow_registry = WorkflowRegistry(self)
self.review_service = AIPMOReviewService(db, tenant_id=self.tenant_id)
self.cadence_service = AIPMOCadenceService(db, tenant_id=self.tenant_id)
@staticmethod
def _build_background_session_factory(db: AsyncSession) -> Optional[async_sessionmaker[AsyncSession]]:
bind = getattr(db, "bind", None)
if bind is None:
return None
try:
return async_sessionmaker(bind=bind, expire_on_commit=False, class_=AsyncSession)
except Exception:
return None