feat(multi-agent): create_custom_agent 支持同 role_id 覆盖更新
- 同 role_id 重复创建时由报错改为覆盖式保存,结果中返回 overwritten 标记 - 覆盖仅影响之后新创建的实例,运行中实例 prompt 已快照冻结不受影响 - 工具 description 与结果格式化文案同步说明该语义
This commit is contained in:
parent
d5b1e2c3af
commit
59a9f6ab62
@ -2180,12 +2180,10 @@ class MainTerminalToolsExecutionMixin:
|
|||||||
_is_web = '/web/users/' in _data_dir.replace("\\", "/")
|
_is_web = '/web/users/' in _data_dir.replace("\\", "/")
|
||||||
_runtime_dir = None if _is_web else _custom_dir
|
_runtime_dir = None if _is_web else _custom_dir
|
||||||
existing_ids = {r.role_id for r in list_roles(runtime_dir=_runtime_dir, custom_dir=_custom_dir)}
|
existing_ids = {r.role_id for r in list_roles(runtime_dir=_runtime_dir, custom_dir=_custom_dir)}
|
||||||
if role_id in existing_ids:
|
# 同 role_id 重复创建 = 覆盖式修改(仅影响之后创建的实例;运行中实例 prompt 已快照冻结)
|
||||||
result = {"success": False, "error": f"角色 {role_id} 已存在"}
|
role = RoleConfig(role_id=role_id, name=name, description=description, body_prompt=body_prompt, thinking_mode=thinking_mode_arg, model_key=model_key_arg, is_custom=True)
|
||||||
else:
|
f = save_custom_role(role, custom_dir=_custom_dir)
|
||||||
role = RoleConfig(role_id=role_id, name=name, description=description, body_prompt=body_prompt, thinking_mode=thinking_mode_arg, model_key=model_key_arg, is_custom=True)
|
result = {"success": True, "role_id": role_id, "name": name, "file": str(f), "overwritten": role_id in existing_ids}
|
||||||
f = save_custom_role(role, custom_dir=_custom_dir)
|
|
||||||
result = {"success": True, "role_id": role_id, "file": str(f)}
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
result = {"success": False, "error": str(exc)}
|
result = {"success": False, "error": str(exc)}
|
||||||
|
|
||||||
|
|||||||
@ -147,7 +147,11 @@ def _master_tool_create_custom_agent() -> Dict[str, Any]:
|
|||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
"name": "create_custom_agent",
|
"name": "create_custom_agent",
|
||||||
"description": "创建/保存一个自定义角色到后端(~/.astrion/astrion/host/mutiagents/agents/)。后续可用 create_sub_agent 指定该角色。",
|
"description": (
|
||||||
|
"创建/保存一个自定义角色到后端(~/.astrion/astrion/host/mutiagents/agents/)。"
|
||||||
|
"后续可用 create_sub_agent 指定该角色。role_id 已存在时覆盖更新该角色设定;"
|
||||||
|
"注意:覆盖只影响之后新创建的实例,已在运行的实例 prompt 已快照冻结,不受影响。"
|
||||||
|
),
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": _inject_intent({
|
"properties": _inject_intent({
|
||||||
|
|||||||
@ -291,6 +291,8 @@ def _format_create_custom_agent(result_data: Dict[str, Any]) -> str:
|
|||||||
return _format_failure("create_custom_agent", result_data)
|
return _format_failure("create_custom_agent", result_data)
|
||||||
role_id = result_data.get("role_id")
|
role_id = result_data.get("role_id")
|
||||||
name = result_data.get("name") or role_id
|
name = result_data.get("name") or role_id
|
||||||
|
if result_data.get("overwritten"):
|
||||||
|
return f"已覆盖更新角色 {role_id}({name})。新设定对之后创建的实例生效,运行中的实例不受影响。"
|
||||||
return f"已创建自定义角色 {role_id}({name})。"
|
return f"已创建自定义角色 {role_id}({name})。"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user