创建新角色 Args: role_name: 角色名(如 roleA, roleB) description: 角色描述 natural_language: 研究方向描述(用于冷启动) feishu_chat_id: 飞书群 ID(可选,用于绑定对话框) Returns: 创建结果
(role_name: str, description: str = "", natural_language: str = "", feishu_chat_id: str = None)
| 70 | |
| 71 | |
| 72 | def create_role(role_name: str, description: str = "", natural_language: str = "", feishu_chat_id: str = None) -> Dict[str, Any]: |
| 73 | """ |
| 74 | 创建新角色 |
| 75 | |
| 76 | Args: |
| 77 | role_name: 角色名(如 roleA, roleB) |
| 78 | description: 角色描述 |
| 79 | natural_language: 研究方向描述(用于冷启动) |
| 80 | feishu_chat_id: 飞书群 ID(可选,用于绑定对话框) |
| 81 | |
| 82 | Returns: |
| 83 | 创建结果 |
| 84 | """ |
| 85 | meta = load_roles_meta() |
| 86 | |
| 87 | if role_name in meta["roles"]: |
| 88 | return {"success": False, "message": f"角色 {role_name} 已存在"} |
| 89 | |
| 90 | # 生成 user_id |
| 91 | user_id = f"user_{role_name}" |
| 92 | |
| 93 | bootstrap_text = (natural_language or description or "").strip() |
| 94 | |
| 95 | # 创建角色元数据 |
| 96 | meta["roles"][role_name] = { |
| 97 | "user_id": user_id, |
| 98 | "description": description or bootstrap_text, |
| 99 | "created_at": datetime.now().isoformat(), |
| 100 | "natural_language": bootstrap_text, |
| 101 | "feishu_chat_id": feishu_chat_id, # 飞书群 ID |
| 102 | } |
| 103 | |
| 104 | # 如果是第一个角色,设为当前角色 |
| 105 | if meta["current_role"] is None: |
| 106 | meta["current_role"] = role_name |
| 107 | |
| 108 | save_roles_meta(meta) |
| 109 | |
| 110 | # 创建用户画像 |
| 111 | profile = { |
| 112 | "user_id": user_id, |
| 113 | "version": "0.1", |
| 114 | "created_at": datetime.now().isoformat(), |
| 115 | "updated_at": datetime.now().isoformat(), |
| 116 | "core_directions": {}, |
| 117 | "methodology_preferences": {}, |
| 118 | "must_read": {"authors": [], "institutions": [], "keywords": []}, |
| 119 | "topic_weights": {}, |
| 120 | "author_heat": {}, |
| 121 | "institution_heat": {}, |
| 122 | "interest_vector": [], |
| 123 | "taste_profile": {}, |
| 124 | "reading_history": [], |
| 125 | "behavior_logs": [], |
| 126 | "drift_state": build_default_drift_state(), |
| 127 | "feishu_chat_id": feishu_chat_id, # 画像中也存储飞书群 ID |
| 128 | } |
| 129 |
no test coverage detected