feat(system):优化后端
1.新增后端测试 2.增加了后端的加密 3.增加了i18n(国际化)
This commit is contained in:
@@ -24,6 +24,7 @@ from kilostar.core.individual.regulatory_node.template import (
|
||||
MessageResponse
|
||||
)
|
||||
from pydantic_ai import RunContext, Agent
|
||||
from kilostar.utils.i18n import agent_prompt
|
||||
|
||||
|
||||
@ray.remote
|
||||
@@ -46,6 +47,8 @@ class RegulatoryNode:
|
||||
provider_title: str,
|
||||
model_id: str,
|
||||
tools_list: list[str] = None,
|
||||
toolsets=None,
|
||||
locale: str | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
create_agent方法,将agent对象装配到regulatoryNode的属性内
|
||||
@@ -56,24 +59,21 @@ class RegulatoryNode:
|
||||
provider_title: 供应商名
|
||||
model_id: 模型id
|
||||
tools_list: 工具列表
|
||||
locale: 语言代码(zh/en),控制system prompt语言
|
||||
Returns:
|
||||
无返回
|
||||
"""
|
||||
system_prompt: str = (
|
||||
"你叫kilostar,是一个多智能体AI助手系统中的【监控节点 (regulatory Node)】。\n"
|
||||
"你是系统的'前台接待'和'大脑皮层',负责接收用户的初始请求或工作流的最终报告。\n"
|
||||
"你的核心职责是进行【意图识别与路由】。请仔细阅读用户的请求:\n"
|
||||
"1. 如果用户只是进行简单的问候、闲聊或查询非常基础的信息,请直接生成友好的回复,使用 ForUser 格式。\n"
|
||||
"2. 如果用户提出的是复杂任务(如需要编写代码、多步骤规划、数据处理等),请务必将其判定为需要工作流处理的任务,"
|
||||
" 并使用 ForConsciousnessNode 格式将其移交意识节点处理。\n"
|
||||
"3. 如果你收到的是 TerminationMessage(代表工作流已完成并生成了报告),请将报告内容转化为友好的面向用户的回复,使用 ForUser 格式。\n"
|
||||
"请保持冷静、专业,并严格遵循上述路由规则。"
|
||||
)
|
||||
system_prompt: str = agent_prompt("regulatory_node", locale=locale)
|
||||
output_type = Union[MessageResponse]
|
||||
from kilostar.utils.get_tool import load_tools_from_list
|
||||
provider: Provider = await global_state_machine.get_provider.remote(
|
||||
provider_title
|
||||
)
|
||||
from kilostar.core.global_state_machine.gsm_snapshot import fetch_snapshot
|
||||
|
||||
# 走 Object Store 快照而不是 actor RPC:高频读路径不再受单 actor 串行限制
|
||||
snapshot = await fetch_snapshot(gsm_actor=global_state_machine)
|
||||
provider: Provider = snapshot.providers.get(provider_title)
|
||||
if provider is None:
|
||||
from kilostar.utils.i18n import t
|
||||
raise ValueError(t("provider_not_registered", locale=locale, provider_title=provider_title))
|
||||
agent_factory = AgentFactory()
|
||||
|
||||
callables = load_tools_from_list(tools_list)
|
||||
@@ -85,6 +85,7 @@ class RegulatoryNode:
|
||||
deps_type=RegulatoryNodeDeps,
|
||||
agent_name="regulatory_node",
|
||||
tools=callables,
|
||||
toolsets=toolsets,
|
||||
)
|
||||
|
||||
@self.agent.system_prompt
|
||||
@@ -112,16 +113,15 @@ class RegulatoryNode:
|
||||
)
|
||||
return prompt
|
||||
|
||||
async def working(self, payload: MessageRequest) -> str:
|
||||
"""working方法,是节点唯一的调用方法,对于_run函数的结果进行判断并实现最终回复
|
||||
async def working(self, payload: MessageRequest) -> Union[MessageResponse, None]:
|
||||
"""working方法,是节点唯一的调用方法,对_run函数的结果进行判断并返回最终回复
|
||||
Args:
|
||||
payload: 消息载荷,包含所有信息
|
||||
|
||||
Returns:
|
||||
str,监控节点对于用户的回复
|
||||
MessageResponse 或 None,监控节点对用户的结构化回复
|
||||
"""
|
||||
await self._run(payload)
|
||||
return ""
|
||||
return await self._run(payload)
|
||||
|
||||
async def _run(
|
||||
self, payload: MessageRequest
|
||||
@@ -140,7 +140,8 @@ class RegulatoryNode:
|
||||
deps=deps,)
|
||||
response: MessageResponse = agent_response.output
|
||||
response.platform = platform
|
||||
response.platform_id = MessageRequest.platform_id
|
||||
response.platform_id = payload.platform_id
|
||||
return response
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
self.logger.exception(f"RegulatoryNode._run failed: {e}")
|
||||
return None
|
||||
@@ -49,7 +49,7 @@ class MessageRequest(RequestModel):
|
||||
MessageRequest类
|
||||
任何消息渠道向regulatory_node发送消息请求的模型
|
||||
"""
|
||||
platform: Literal["client"]
|
||||
platform: Literal["client", "onebot"]
|
||||
user_name: str
|
||||
platform_id: Optional[str]
|
||||
message: str
|
||||
@@ -59,6 +59,6 @@ class MessageResponse(RegulatoryNodeResponse):
|
||||
MessageResponse类
|
||||
regulatory_node回复的模型
|
||||
"""
|
||||
platform: Optional[Literal["client"]] = Field(description="系统自动填入的platform")
|
||||
platform: Optional[Literal["client", "onebot"]] = Field(description="系统自动填入的platform")
|
||||
platform_id: Optional[str] = Field(description="系统自动填入的platform_id")
|
||||
reply_message: str = Field(...,description="模型回复的消息")
|
||||
|
||||
Reference in New Issue
Block a user