perf(chat): 将 planner 的非回复动作改为后台任务执行
原先的 PlanExecutor 会 `await` 等待所有动作执行完毕,包括非直接回复用户的动作,这可能导致在这些动作耗时较长时,用户的响应被延迟。 本次修改将非回复类的动作(other_actions)放入 `asyncio.create_task` 中执行,使其成为后台任务。这样可以确保核心的回复流程不被阻塞,从而显著提升机器人的响应速度。 注意:后台任务的执行结果和统计数据将不会在本次执行周期中立即返回。
This commit is contained in:
@@ -83,11 +83,11 @@ class PlanExecutor:
|
|||||||
execution_results.extend(reply_result["results"])
|
execution_results.extend(reply_result["results"])
|
||||||
self.execution_stats["reply_executions"] += len(reply_actions)
|
self.execution_stats["reply_executions"] += len(reply_actions)
|
||||||
|
|
||||||
# 并行执行其他动作
|
# 将其他动作放入后台任务执行,避免阻塞主流程
|
||||||
if other_actions:
|
if other_actions:
|
||||||
other_result = await self._execute_other_actions(other_actions, plan)
|
asyncio.create_task(self._execute_other_actions(other_actions, plan))
|
||||||
execution_results.extend(other_result["results"])
|
logger.info(f"已将 {len(other_actions)} 个其他动作放入后台任务执行。")
|
||||||
self.execution_stats["other_action_executions"] += len(other_actions)
|
# 注意:后台任务的结果不会立即计入本次返回的统计数据
|
||||||
|
|
||||||
# 更新总体统计
|
# 更新总体统计
|
||||||
self.execution_stats["total_executed"] += len(plan.decided_actions)
|
self.execution_stats["total_executed"] += len(plan.decided_actions)
|
||||||
|
|||||||
Reference in New Issue
Block a user