From 6a976915d0801d3b700ad4928e703fad59b4e90b Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Mon, 22 Sep 2025 19:19:02 +0800 Subject: [PATCH] =?UTF-8?q?perf(chat):=20=E5=B0=86=20planner=20=E7=9A=84?= =?UTF-8?q?=E9=9D=9E=E5=9B=9E=E5=A4=8D=E5=8A=A8=E4=BD=9C=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E4=BB=BB=E5=8A=A1=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原先的 PlanExecutor 会 `await` 等待所有动作执行完毕,包括非直接回复用户的动作,这可能导致在这些动作耗时较长时,用户的响应被延迟。 本次修改将非回复类的动作(other_actions)放入 `asyncio.create_task` 中执行,使其成为后台任务。这样可以确保核心的回复流程不被阻塞,从而显著提升机器人的响应速度。 注意:后台任务的执行结果和统计数据将不会在本次执行周期中立即返回。 --- src/chat/planner_actions/plan_executor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chat/planner_actions/plan_executor.py b/src/chat/planner_actions/plan_executor.py index acd9b376f..f6d70de60 100644 --- a/src/chat/planner_actions/plan_executor.py +++ b/src/chat/planner_actions/plan_executor.py @@ -83,11 +83,11 @@ class PlanExecutor: execution_results.extend(reply_result["results"]) self.execution_stats["reply_executions"] += len(reply_actions) - # 并行执行其他动作 + # 将其他动作放入后台任务执行,避免阻塞主流程 if other_actions: - other_result = await self._execute_other_actions(other_actions, plan) - execution_results.extend(other_result["results"]) - self.execution_stats["other_action_executions"] += len(other_actions) + asyncio.create_task(self._execute_other_actions(other_actions, plan)) + logger.info(f"已将 {len(other_actions)} 个其他动作放入后台任务执行。") + # 注意:后台任务的结果不会立即计入本次返回的统计数据 # 更新总体统计 self.execution_stats["total_executed"] += len(plan.decided_actions)