MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / parse_role_command

Function parse_role_command

agents/role-manager/main.py:310–372  ·  view source on GitHub ↗

解析角色命令 支持格式: - "创建角色 roleB,研究方向:GUI Agent" - "切换到 roleB" - "查看角色列表" - "删除角色 roleA" - "绑定飞书群 roleA chat_xxx" Args: text: 用户输入 Returns: 命令字典

(text: str)

Source from the content-addressed store, hash-verified

308
309
310def parse_role_command(text: str) -> Optional[Dict[str, Any]]:
311 """
312 解析角色命令
313
314 支持格式:
315 - "创建角色 roleB,研究方向:GUI Agent"
316 - "切换到 roleB"
317 - "查看角色列表"
318 - "删除角色 roleA"
319 - "绑定飞书群 roleA chat_xxx"
320
321 Args:
322 text: 用户输入
323
324 Returns:
325 命令字典
326 """
327 text_lower = text.lower().strip()
328
329 # 绑定飞书群
330 if any(kw in text_lower for kw in ["绑定", "bind", "关联"]):
331 match = re.search(r'(?:绑定 |bind| 关联)\s*(?:飞书)?(?:群 |chat)?\s*(\w+)\s*(\w+)', text_lower)
332 if match:
333 return {
334 "action": "bind",
335 "role_name": match.group(1),
336 "feishu_chat_id": match.group(2),
337 }
338
339 # 创建角色
340 if any(kw in text_lower for kw in ["创建角色", "create role", "新建角色"]):
341 # 提取角色名和描述
342 match = re.search(r'(?:创建角色 | 新建角色|create role)\s*(\w+)[, ,]*(.*)', text_lower)
343 if match:
344 return {
345 "action": "create",
346 "role_name": match.group(1),
347 "natural_language": match.group(2).strip() if match.group(2) else "",
348 }
349
350 # 切换角色
351 if any(kw in text_lower for kw in ["切换", "switch", "转到", "转到"]):
352 match = re.search(r'(?:切换到 | 转到|switch to)\s*(\w+)', text_lower)
353 if match:
354 return {
355 "action": "switch",
356 "role_name": match.group(1),
357 }
358
359 # 查看列表
360 if any(kw in text_lower for kw in ["查看角色", "list roles", "角色列表", "我的角色"]):
361 return {"action": "list"}
362
363 # 删除角色
364 if any(kw in text_lower for kw in ["删除角色", "delete role", "移除角色"]):
365 match = re.search(r'(?:删除 | 移除|delete)\s*(?:角色)?\s*(\w+)', text_lower)
366 if match:
367 return {

Callers 1

process_role_commandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected