代码提交

This commit is contained in:
董宏凯 committed 2026-08-03 19:27:54 +08:00
1 parent d93cc62806
commit ddf83f7728
25 files changed
+4086 -424

No files matched your search

@@ -20,7 +20,7 @@ from __future__ import annotations
import re
from typing import Literal
from pydantic import BaseModel, Field, field_validator
from pydantic import BaseModel, Field, field_validator, model_validator
# ── shared enums (config + API schemas) ───────────────────────────────────
@@ -108,10 +108,25 @@ class MafBusinessRoute(BaseModel):
value = str(agent_id).strip()
if not value or len(value) > 64:
raise ValueError("seat_agent_ids must contain non-empty agent ids")
if value not in normalized:
normalized.append(value)
if value in normalized:
raise ValueError("seat_agent_ids must not contain duplicates")
normalized.append(value)
return normalized
@field_validator("manager_agent_id", mode="before")
@classmethod
def _normalize_manager_agent_id(cls, value: object) -> str:
normalized = str(value or "").strip()
if not normalized:
raise ValueError("manager_agent_id must be non-empty")
return normalized
@model_validator(mode="after")
def _validate_manager_not_seat(self) -> MafBusinessRoute:
if self.manager_agent_id in self.seat_agent_ids:
raise ValueError("manager_agent_id must not appear in seat_agent_ids")
return self
class MafRoundtableConfig(BaseModel):
"""Microsoft Agent Framework 多智能体会商实验功能开关。
@@ -191,6 +206,73 @@ class MafRoundtableConfig(BaseModel):
le=7200,
description="外部业务目标写入租约有效期(秒);过期运行中的动作转 unknown。",
)
conversation_event_backend: Literal["memory"] = Field(
default="memory",
description="会商 SSE 事件广播后端;当前仅支持 memory(单 worker)。",
)
require_single_worker_for_conversation_sse: bool = Field(
default=True,
description="当 backend=memory 且检测到多 worker 时,禁止会商 SSE 写入入口。",
)
background_reconcile_interval_seconds: int = Field(
default=10,
ge=5,
le=60,
description="后台自动 reconcile 扫描间隔(秒);补偿投影失败的审计事件。",
)
@field_validator("default_manager_agent_id", mode="before")
@classmethod
def _normalize_default_manager_agent_id(cls, value: object) -> str | None:
if value is None:
return None
normalized = str(value).strip()
if not normalized:
raise ValueError("default_manager_agent_id must be non-empty when provided")
return normalized
@field_validator("default_seat_agent_ids")
@classmethod
def _validate_default_seat_agent_ids(cls, ids: list[str]) -> list[str]:
normalized: list[str] = []
for agent_id in ids:
value = str(agent_id).strip()
if not value or len(value) > 64:
raise ValueError("default_seat_agent_ids must contain non-empty agent ids")
if value in normalized:
raise ValueError("default_seat_agent_ids must not contain duplicates")
normalized.append(value)
return normalized
@field_validator("business_routes")
@classmethod
def _validate_business_route_codes(
cls, routes: dict[str, MafBusinessRoute]
) -> dict[str, MafBusinessRoute]:
code_pattern = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$")
normalized_routes: dict[str, MafBusinessRoute] = {}
for code, route in routes.items():
normalized_code = str(code).strip()
if not code_pattern.fullmatch(normalized_code):
raise ValueError(
"business route code must match ^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$"
)
if normalized_code in normalized_routes:
raise ValueError("business route codes must be unique after trimming")
normalized_routes[normalized_code] = route
return normalized_routes
@model_validator(mode="after")
def _validate_routes(self) -> MafRoundtableConfig:
if self.default_manager_agent_id and self.default_manager_agent_id in self.default_seat_agent_ids:
raise ValueError("default manager_agent_id must not appear in default_seat_agent_ids")
if len(self.default_seat_agent_ids) > self.max_seats_per_run:
raise ValueError("default_seat_agent_ids exceeds max_seats_per_run")
for code, route in self.business_routes.items():
if len(route.seat_agent_ids) > self.max_seats_per_run:
raise ValueError(f"business route {code!r} exceeds max_seats_per_run")
return self
__all__ = [