feat(agent): 移除control_node实例化,新增系统节点命名与人设管理前端

当前阶段只保留regulatory+consciousness两个系统节点,control_node代码保留但不再实例化。
系统节点新增display_name字段支持自定义显示名称,前端新增人设管理Tab支持模板CRUD。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 06:03:28 +00:00
parent 9a7a5edd6e
commit f3a92a793e
11 changed files with 567 additions and 47 deletions
@@ -13,10 +13,8 @@
# limitations under the License.
from typing import List, Optional
from sqlalchemy import String
from sqlalchemy.dialects.postgresql import (
JSONB,
) # 针对 Postgres 优化,支持索引和高性能解析
from sqlalchemy import String, Text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Mapped, mapped_column
from .base import BaseDataModel
@@ -29,8 +27,14 @@ class SystemNodeConfigModel(BaseDataModel):
__tablename__ = "system_node_config"
node_name: Mapped[str] = mapped_column(String(100), primary_key=True)
display_name: Mapped[Optional[str]] = mapped_column(
String(100), nullable=True, comment="管理员可自定义的显示名称,用于前端展示"
)
provider_title: Mapped[str] = mapped_column(String(50), nullable=False)
model_id: Mapped[str] = mapped_column(String(100), nullable=False)
tools: Mapped[Optional[List[str]]] = mapped_column(
JSONB, default=list, comment="节点可调用的工具标识列表"
)
custom_system_prompt: Mapped[Optional[str]] = mapped_column(
Text, nullable=True, comment="管理员自定义追加的提示词,拼接在默认 system prompt 之后"
)
@@ -19,7 +19,7 @@ from kilostar.core.postgres_database.database_exception import database_exceptio
class SystemNodeDatabase:
"""SystemNodeConfig 表的 DAO:管理 control/consciousness/regulatory 等系统节点的模型配置。"""
"""SystemNodeConfig 表的 DAO:管理 consciousness/regulatory 等系统节点的模型配置。"""
def __init__(self, async_session_maker):
self.async_session_maker = async_session_maker
@@ -31,8 +31,10 @@ class SystemNodeDatabase:
provider_title: str,
model_id: str,
tools: Optional[List[str]] = None,
custom_system_prompt: Optional[str] = None,
display_name: Optional[str] = None,
) -> SystemNodeConfigModel:
"""按 node_name 插入或更新一个系统节点的模型配置Provider + 模型 ID + 工具列表)"""
"""按 node_name 插入或更新一个系统节点的模型配置。"""
async with self.async_session_maker() as session:
statement = select(SystemNodeConfigModel).where(
SystemNodeConfigModel.node_name == node_name
@@ -44,12 +46,18 @@ class SystemNodeDatabase:
config.model_id = model_id
if tools is not None:
config.tools = tools
if custom_system_prompt is not None:
config.custom_system_prompt = custom_system_prompt
if display_name is not None:
config.display_name = display_name
else:
config = SystemNodeConfigModel(
node_name=node_name,
provider_title=provider_title,
model_id=model_id,
tools=tools,
custom_system_prompt=custom_system_prompt,
display_name=display_name,
)
session.add(config)
await session.commit()
+32 -8
View File
@@ -16,6 +16,7 @@ import os
import asyncio
from kilostar.utils.standalone_proxy import actor_class
from kilostar.utils.settings import get_settings
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
from kilostar.core.postgres_database.model.base import BaseDataModel
@@ -42,6 +43,7 @@ from kilostar.core.postgres_database.model.mcp_server import MCPServerModel
from kilostar.core.postgres_database.model.tool_config import ToolConfigModel
from kilostar.core.postgres_database.model.custom_toolset import CustomToolsetModel
from kilostar.core.postgres_database.model.system_event_log import SystemEventLog
from kilostar.core.postgres_database.model.persona_template import PersonaTemplate
from .module.individual import IndividualDatabase
from .module.user import AuthDatabase
@@ -53,6 +55,7 @@ from .module.mcp_server import MCPServerDatabase
from .module.tool_config import ToolConfigDatabase
from .module.custom_toolset import CustomToolsetDatabase
from .module.system_event_log import SystemEventLogDatabase
from .module.persona_template import PersonaTemplateDatabase
@actor_class
@@ -65,13 +68,10 @@ class PostgresDatabase:
"""
def __init__(self):
user = os.environ.get("POSTGRES_USER")
password = os.environ.get("POSTGRES_PASSWORD")
host = os.environ.get("POSTGRES_HOST")
port = os.environ.get("POSTGRES_PORT")
database = os.environ.get("POSTGRES_DB")
_s = get_settings().db
database_url = (
f"postgresql+asyncpg://{user}:{password}@{host}:{port}/{database}"
f"postgresql+asyncpg://{_s.postgres_user}:{_s.postgres_password}"
f"@{_s.postgres_host}:{_s.postgres_port}/{_s.postgres_db}"
)
self.async_engine = create_async_engine(database_url, echo=True)
self.async_session_maker = sessionmaker(
@@ -88,6 +88,7 @@ class PostgresDatabase:
self._tool_config_database = ToolConfigDatabase(self.async_session_maker)
self._custom_toolset_database = CustomToolsetDatabase(self.async_session_maker)
self._system_event_log_database = SystemEventLogDatabase(self.async_session_maker)
self._persona_template_database = PersonaTemplateDatabase(self.async_session_maker)
self.ready_event = asyncio.Event()
@@ -182,11 +183,13 @@ class PostgresDatabase:
provider_title: str,
model_id: str,
tools: list[str] = None,
custom_system_prompt: str = None,
display_name: str = None,
):
"""插入或更新某个系统节点(如 control/consciousness/regulatory)的模型配置。"""
"""插入或更新某个系统节点(如 consciousness/regulatory)的模型配置。"""
await self.ready_event.wait()
return await self._system_node_database.upsert_system_node_config(
node_name, provider_title, model_id, tools
node_name, provider_title, model_id, tools, custom_system_prompt, display_name
)
async def get_all_system_node_configs(self):
@@ -410,3 +413,24 @@ class PostgresDatabase:
limit=limit,
offset=offset,
)
# Persona Template Database Methods
async def add_template(self, **kwargs):
await self.ready_event.wait()
return await self._persona_template_database.add_template(**kwargs)
async def get_template(self, template_id: str):
await self.ready_event.wait()
return await self._persona_template_database.get_template(template_id)
async def list_templates(self, owner_id: str = None, include_builtin: bool = True):
await self.ready_event.wait()
return await self._persona_template_database.list_templates(owner_id, include_builtin)
async def update_template(self, template_id: str, **kwargs):
await self.ready_event.wait()
return await self._persona_template_database.update_template(template_id, **kwargs)
async def delete_template(self, template_id: str):
await self.ready_event.wait()
return await self._persona_template_database.delete_template(template_id)