feat: v0.1.1 迭代——人设外键重构、Chat UI优化、意识节点防幻觉、日志双视图
1. 人设外键重构:persona_template 成为 system_prompt 唯一权威来源, agent/系统节点通过 persona_id FK 引用,含数据迁移脚本 2. Chat UI:去掉底部AI提示、加号改为弹出菜单、新建对话乐观跳转 3. 意识节点:无可用worker时禁止编造agent_id,只能自行完成或拒绝 4. 日志页面:双tab布局(系统日志 + 工作流日志列表选择) 5. 其他:SSE流式聊天、对话删除/重命名、standalone模式修复 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+19
-48
@@ -36,7 +36,7 @@ class AgentRegister(BaseModel):
|
||||
model_id: str
|
||||
individual_name: str
|
||||
tools: Optional[List[str]] = None
|
||||
custom_system_prompt: Optional[str] = None
|
||||
persona_id: Optional[str] = None
|
||||
display_name: Optional[str] = None
|
||||
|
||||
|
||||
@@ -79,13 +79,19 @@ async def load_agent(
|
||||
agent_register.provider_title,
|
||||
agent_register.model_id,
|
||||
agent_register.tools,
|
||||
agent_register.custom_system_prompt,
|
||||
agent_register.persona_id,
|
||||
agent_register.display_name,
|
||||
)
|
||||
|
||||
scope = agent_register.individual_name
|
||||
toolsets = await get_all_toolsets_for_scope(scope)
|
||||
custom_prompt = agent_register.custom_system_prompt
|
||||
|
||||
# Resolve persona system_prompt from DB
|
||||
persona_prompt = None
|
||||
if agent_register.persona_id:
|
||||
tpl = await postgres_database.get_template.remote(agent_register.persona_id)
|
||||
if tpl:
|
||||
persona_prompt = tpl.system_prompt
|
||||
|
||||
match scope:
|
||||
case "regulatory_node":
|
||||
@@ -97,7 +103,7 @@ async def load_agent(
|
||||
agent_register.tools,
|
||||
toolsets,
|
||||
accept_lang,
|
||||
custom_prompt,
|
||||
persona_prompt,
|
||||
)
|
||||
case "consciousness_node":
|
||||
node = ray_actor_hook("consciousness_node").consciousness_node
|
||||
@@ -108,7 +114,7 @@ async def load_agent(
|
||||
agent_register.tools,
|
||||
toolsets,
|
||||
accept_lang,
|
||||
custom_prompt,
|
||||
persona_prompt,
|
||||
)
|
||||
case _:
|
||||
pass
|
||||
@@ -130,7 +136,7 @@ class WorkerIndividualCreate(BaseModel):
|
||||
description: str
|
||||
provider_title: str
|
||||
model_id: str
|
||||
system_prompt: str
|
||||
persona_id: str
|
||||
output_template: dict
|
||||
bound_skill: Dict[str, List[str]]
|
||||
workspace: List[str]
|
||||
@@ -153,7 +159,7 @@ class WorkerIndividualUpdate(BaseModel):
|
||||
description: Optional[str] = None
|
||||
provider_title: Optional[str] = None
|
||||
model_id: Optional[str] = None
|
||||
system_prompt: Optional[str] = None
|
||||
persona_id: Optional[str] = None
|
||||
output_template: Optional[dict] = None
|
||||
bound_skill: Optional[Dict[str, List[str]]] = None
|
||||
workspace: Optional[List[str]] = None
|
||||
@@ -280,34 +286,21 @@ async def delete_worker_individual(
|
||||
|
||||
class PersonaTemplateCreate(BaseModel):
|
||||
name: str
|
||||
description: str = ""
|
||||
system_prompt: str = ""
|
||||
agent_type: AgentType = "ordinary"
|
||||
provider_title: Optional[str] = None
|
||||
model_id: Optional[str] = None
|
||||
tools: Optional[List[str]] = None
|
||||
tags: Optional[List[str]] = None
|
||||
|
||||
|
||||
class PersonaTemplateUpdate(BaseModel):
|
||||
name: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
system_prompt: Optional[str] = None
|
||||
agent_type: Optional[AgentType] = None
|
||||
provider_title: Optional[str] = None
|
||||
model_id: Optional[str] = None
|
||||
tools: Optional[List[str]] = None
|
||||
tags: Optional[List[str]] = None
|
||||
|
||||
|
||||
@agent_router.get("/template")
|
||||
async def list_templates(
|
||||
include_builtin: bool = True,
|
||||
token_data: TokenData = Depends(Accessor.get_current_user),
|
||||
):
|
||||
postgres_database = ray_actor_hook("postgres_database").postgres_database
|
||||
templates = await postgres_database.list_templates.remote(
|
||||
owner_id=token_data.user_id, include_builtin=include_builtin
|
||||
owner_id=token_data.user_id
|
||||
)
|
||||
return {"templates": templates}
|
||||
|
||||
@@ -319,7 +312,9 @@ async def create_template(
|
||||
):
|
||||
postgres_database = ray_actor_hook("postgres_database").postgres_database
|
||||
tpl = await postgres_database.add_template.remote(
|
||||
**data.model_dump(), owner_id=token_data.user_id, is_builtin=False
|
||||
name=data.name,
|
||||
system_prompt=data.system_prompt,
|
||||
owner_id=token_data.user_id,
|
||||
)
|
||||
return {"message": "success", "template_id": tpl.template_id}
|
||||
|
||||
@@ -334,7 +329,7 @@ async def update_template(
|
||||
tpl = await postgres_database.get_template.remote(template_id)
|
||||
if not tpl:
|
||||
raise HTTPException(status_code=404, detail="Template not found")
|
||||
if not tpl.is_builtin and tpl.owner_id != token_data.user_id:
|
||||
if tpl.owner_id != token_data.user_id:
|
||||
raise HTTPException(status_code=403, detail="Forbidden")
|
||||
updated = await postgres_database.update_template.remote(
|
||||
template_id, **data.model_dump(exclude_unset=True)
|
||||
@@ -351,31 +346,7 @@ async def delete_template(
|
||||
tpl = await postgres_database.get_template.remote(template_id)
|
||||
if not tpl:
|
||||
raise HTTPException(status_code=404, detail="Template not found")
|
||||
if tpl.is_builtin or tpl.owner_id != token_data.user_id:
|
||||
if tpl.owner_id != token_data.user_id:
|
||||
raise HTTPException(status_code=403, detail="Forbidden")
|
||||
await postgres_database.delete_template.remote(template_id)
|
||||
return {"message": "success"}
|
||||
|
||||
|
||||
@agent_router.post("/worker/from-template/{template_id}")
|
||||
async def create_worker_from_template(
|
||||
template_id: str,
|
||||
token_data: TokenData = Depends(RoleChecker(allowed_roles=UserAuthority.USER)),
|
||||
):
|
||||
"""从人设模板快速创建一个 Worker Agent,字段直接从模板复制。"""
|
||||
postgres_database = ray_actor_hook("postgres_database").postgres_database
|
||||
tpl = await postgres_database.get_template.remote(template_id)
|
||||
if not tpl:
|
||||
raise HTTPException(status_code=404, detail="Template not found")
|
||||
worker = await postgres_database.add_worker_individual.remote(
|
||||
agent_name=tpl.name,
|
||||
agent_type=tpl.agent_type,
|
||||
description=tpl.description,
|
||||
system_prompt=tpl.system_prompt,
|
||||
provider_title=tpl.provider_title or "",
|
||||
model_id=tpl.model_id or "",
|
||||
tools=tpl.tools or [],
|
||||
owner_id=token_data.user_id,
|
||||
template_origin_id=template_id,
|
||||
)
|
||||
return {"message": "success", "agent_id": worker.agent_id}
|
||||
|
||||
Reference in New Issue
Block a user