feat:添加timing gate平滑

This commit is contained in:
SengokuCola
2026-05-07 16:16:31 +08:00
parent fd51632da8
commit f41051f836
5 changed files with 332 additions and 1 deletions

View File

@@ -57,7 +57,7 @@ MODEL_CONFIG_PATH: Path = (CONFIG_DIR / "model_config.toml").resolve().absolute(
LEGACY_ENV_PATH: Path = (PROJECT_ROOT / ".env").resolve().absolute()
A_MEMORIX_LEGACY_CONFIG_PATH: Path = (CONFIG_DIR / "a_memorix.toml").resolve().absolute()
MMC_VERSION: str = "1.0.0-pre.14"
CONFIG_VERSION: str = "8.10.11"
CONFIG_VERSION: str = "8.10.12"
MODEL_CONFIG_VERSION: str = "1.16.0"
logger = get_logger("config")

View File

@@ -421,6 +421,22 @@ class ChatConfig(ConfigBase):
)
"""Planner 连续被新消息打断的最大次数0 表示不启用打断"""
timing_gate_non_continue_cooldown_seconds: float = Field(
default=0,
ge=0,
json_schema_extra={
"label": {
"zh_CN": "Timing Gate 非 continue 冷却",
"en_US": "Timing Gate non-continue cooldown",
"ja_JP": "Timing Gate 非 continue クールダウン",
},
"x-widget": "input",
"x-icon": "timer",
"advanced": True,
},
)
"""Timing Gate 返回 wait/no_reply 时的最小窗口秒数0 表示不启用冷却"""
group_chat_prompt: str = Field(
default=(
"你正在qq群里聊天下面是群里正在聊的内容其中包含聊天记录和聊天中的图片和表情包。\n"

View File

@@ -511,6 +511,11 @@ class MaisakaReasoningEngine:
timing_tool_results,
timing_tool_monitor_results,
) = await self._run_timing_gate(anchor_message)
timing_elapsed_seconds = time.time() - timing_started_at
if timing_action != "continue":
await self._runtime._wait_for_timing_gate_non_continue_cooldown(
timing_elapsed_seconds
)
timing_duration_ms = (time.time() - timing_started_at) * 1000
cycle_detail.time_records["timing_gate"] = timing_duration_ms / 1000
await emit_timing_gate_result(

View File

@@ -116,6 +116,10 @@ class MaisakaHeartFlowChatting:
self._force_next_timing_continue = False
self._force_next_timing_message_id = ""
self._force_next_timing_reason = ""
self._timing_gate_non_continue_cooldown_seconds = max(
0.0,
float(global_config.chat.timing_gate_non_continue_cooldown_seconds),
)
self._planner_interrupt_flag: Optional[asyncio.Event] = None
self._planner_interrupt_requested = False
self._planner_interrupt_consecutive_count = 0
@@ -567,6 +571,20 @@ class MaisakaHeartFlowChatting:
return self._force_next_timing_continue
async def _wait_for_timing_gate_non_continue_cooldown(self, elapsed_seconds: float) -> None:
"""仅对 Timing Gate 的 wait/no_reply 动作应用冷却窗口。"""
cooldown_seconds = self._timing_gate_non_continue_cooldown_seconds
if cooldown_seconds <= 0:
return
remaining_seconds = cooldown_seconds - max(0.0, elapsed_seconds)
if remaining_seconds <= 0:
return
logger.info(f"{self.log_prefix} Timing Gate 非 continue 冷却中,等待 {remaining_seconds:.2f} 秒后结束")
await asyncio.sleep(remaining_seconds)
def _bind_planner_interrupt_flag(self, interrupt_flag: asyncio.Event) -> None:
"""绑定当前可打断请求使用的中断标记。"""
self._planner_interrupt_flag = interrupt_flag