如何配置资源池中的资源处理多个agent,实现呼叫中心坐席同时服务多客户聊天场景
呼叫中心多会话客服Agent实现方案
核心基础配置:Employee Agent容量属性设计
首先给Employee agent新增2个可配置的核心属性,作为容量判定的基础依据:
max_concurrent_chats:数值类型,代表该客服最大可同时接待的会话数量,可根据不同客服的能力等级差异化配置active_chats:数组类型,存储当前正在处理的所有chat agent实例/唯一会话ID,数组的实时长度即为当前已占用的服务容量
会话抢占/延迟占用逻辑实现
1. 即时抢占判定逻辑
新的chat agent发起接入请求时,直接对目标Employee agent做容量校验:
- 若
len(active_chats) < max_concurrent_chats条件成立:直接将该chat agent加入active_chats数组,触发客服会话接入流程 - 若条件不成立:将chat agent转入全局等待队列,可按FIFO规则或者用户优先级规则排序等待
2. 延迟占用(队列调度)逻辑
单独实现全局调度功能块,定期轮询等待队列和所有在线Employee agent的剩余容量:
- 剩余容量计算公式:
max_concurrent_chats-len(active_chats) - 当检测到某Employee agent剩余容量>0时,按队列优先级将等待的chat agent依次分配给该Employee agent,直到容量占满
会话释放遍历功能块实现
给Employee agent添加会话巡检逻辑,可根据业务需要选择触发规则:每N秒定时触发、新会话接入请求时触发、单会话发送结束信号时触发
巡检逻辑执行时遍历
active_chats数组中的每个chat agent,可自定义会话结束判定条件,满足任意一条即可释放对应容量
会话结束判定条件参考:
- chat agent已主动发送
chat_end结束标识信号 - 会话超过
max_idle_time阈值无任何消息交互 - 用户侧主动触发会话关闭操作
校验完成后将满足结束条件的chat agent从active_chats数组中移除,同步释放对应容量,触发等待队列的调度逻辑。
核心逻辑参考伪代码
import time class EmployeeAgent: def __init__(self, max_concurrent_chats=3, max_idle_time=300): # 最大同时接待会话数,默认3 self.max_concurrent_chats = max_concurrent_chats # 会话最大空闲时长,默认300秒 self.max_idle_time = max_idle_time # 存储当前活跃会话 self.active_chats = [] # 尝试接入新会话 def try_accept_chat(self, chat_agent) -> bool: if len(self.active_chats) < self.max_concurrent_chats: self.active_chats.append({ "chat_id": chat_agent.chat_id, "last_active_time": time.time(), "instance": chat_agent }) return True return False # 遍历释放已结束的会话 def release_finished_chats(self) -> int: current_time = time.time() new_active_chats = [] for chat in self.active_chats: # 仅保留未关闭且未超时的会话 if not chat["instance"].is_closed and (current_time - chat["last_active_time"]) < self.max_idle_time: new_active_chats.append(chat) released_count = len(self.active_chats) - len(new_active_chats) self.active_chats = new_active_chats return released_count
内容的提问来源于stack exchange,提问作者Владимир Подпрятов
相关产品推荐
相关产品推荐

