diff --git a/pretor/api/platform/frontend.py b/pretor/api/platform/frontend.py index 32323f0..8f414fa 100644 --- a/pretor/api/platform/frontend.py +++ b/pretor/api/platform/frontend.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from fastapi import APIRouter, Depends, HTTPException, status, WebSocket, WebSocketDisconnect +from fastapi import APIRouter, Depends, HTTPException, status from pydantic import BaseModel from pretor.utils.access import Accessor, TokenData from pretor.api.platform.event import PretorEvent diff --git a/pretor/api/provider.py b/pretor/api/provider.py index 11e28c5..84d899b 100644 --- a/pretor/api/provider.py +++ b/pretor/api/provider.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from fastapi import APIRouter, Request, Depends +from fastapi import APIRouter, Depends from pydantic import BaseModel from typing import Literal from pretor.utils.access import TokenData, Accessor diff --git a/pretor/core/api/__init__.py b/pretor/core/api/__init__.py index a0ceac8..9864b58 100644 --- a/pretor/core/api/__init__.py +++ b/pretor/core/api/__init__.py @@ -16,11 +16,6 @@ import ray import uvicorn from typing import Dict from fastapi import FastAPI,WebSocket -from pretor.core.database.postgres import PostgresDatabase -from pretor.core.global_state_machine.global_state_machine import GlobalStateMachine -from pretor.core.individual.supervisory_node.supervisory_node import SupervisoryNode -from pretor.core.individual.consciousness_node.consciousness_node import ConsciousnessNode -from pretor.core.individual.control_node.control_node import ControlNode from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse import os @@ -34,12 +29,7 @@ from pretor.api.agent import agent_router @ray.remote class PretorGateway: gateway: Dict[str, WebSocket] - def __init__(self, - postgres_database: PostgresDatabase, - global_state_machine: GlobalStateMachine, - supervisory_node: SupervisoryNode, - consciousness_node: ConsciousnessNode, - control_node: ControlNode,): + def __init__(self): self.app = FastAPI() self.gateway = {} diff --git a/pretor/core/database/module/individual.py b/pretor/core/database/module/individual.py new file mode 100644 index 0000000..87f3d56 --- /dev/null +++ b/pretor/core/database/module/individual.py @@ -0,0 +1,18 @@ +# Copyright 2026 zhaoxi826 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from pretor.core.database.table import WorkerIndividual +from sqlmodel import select +from pretor.utils.error import UserNotExistError, UserPasswordError +from pretor.core.database.database_exception import database_exception \ No newline at end of file diff --git a/pretor/core/database/table/__init__.py b/pretor/core/database/table/__init__.py index 17db41d..e1af3aa 100644 --- a/pretor/core/database/table/__init__.py +++ b/pretor/core/database/table/__init__.py @@ -13,4 +13,5 @@ # limitations under the License. from pretor.core.database.table.user import User -from pretor.core.database.table.provider import Provider \ No newline at end of file +from pretor.core.database.table.provider import Provider +from pretor.core.database.table.individual import WorkerIndividual \ No newline at end of file diff --git a/pretor/core/database/table/individual.py b/pretor/core/database/table/individual.py new file mode 100644 index 0000000..dcc7dd2 --- /dev/null +++ b/pretor/core/database/table/individual.py @@ -0,0 +1,37 @@ +# Copyright 2026 zhaoxi826 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from sqlmodel import SQLModel, Field +from typing import List, Dict +from sqlalchemy import Column, JSON +from enum import Enum + +class AgentType(str, Enum): + SKILL_INDIVIDUAL = "skill_individual" + ORDINARY_INDIVIDUAL = "ordinary_individual" + SPECIAL_INDIVIDUAL = "special_individual" + +class WorkerIndividual(SQLModel, table=True): + __tablename__ = "worker_individual" + agent_id: str = Field(primary_key=True) + agent_name: str = Field(index=True) + agent_type: AgentType + description: str = Field(nullable=False) + provider_title: str + model_id: str + system_prompt: str + output_template: dict = Field(sa_column=Column(JSON),description="输出模板标识") + bound_skill: Dict[str, List[str]] = Field(sa_column=Column(JSON)) + workspace: List[str] = Field(sa_column=Column(JSON)) + owner_id: str \ No newline at end of file diff --git a/pretor/core/database/table/provider.py b/pretor/core/database/table/provider.py index 7820fe9..9c166d9 100644 --- a/pretor/core/database/table/provider.py +++ b/pretor/core/database/table/provider.py @@ -15,12 +15,18 @@ from sqlmodel import SQLModel, Field from typing import List from sqlalchemy import Column, JSON +from typing import Optional, Literal class Provider(SQLModel, table=True): __tablename__ = "provider" - provider_title: str = Field(primary_key=True) - provider_url: str - provider_apikey: str + provider_id: str = Field(primary_key=True) + provider_title: str = Field(index=True) + provider_type: Literal["openai", "vllm"] + + provider_url: Optional[str] + provider_apikey: Optional[str] + provider_models: List[str] = Field(sa_column=Column(JSON)) - provider_type: str - provider_owner: int \ No newline at end of file + + provider_owner: int + is_active: bool = Field(default=True, description="该服务商节点是否在线/启用") \ No newline at end of file diff --git a/pretor/core/global_state_machine/global_state_machine.py b/pretor/core/global_state_machine/global_state_machine.py index 61053b8..22a2ae5 100644 --- a/pretor/core/global_state_machine/global_state_machine.py +++ b/pretor/core/global_state_machine/global_state_machine.py @@ -13,7 +13,6 @@ # limitations under the License. import ray -import pathlib from pretor.core.global_state_machine.provider_manager import ProviderManager from pretor.core.global_state_machine.tool_manager import GlobalToolManager from pretor.core.global_state_machine.model_provider import Provider, ProviderArgs diff --git a/pretor/core/individual/control_node/control_node.py b/pretor/core/individual/control_node/control_node.py index 176ea1c..cb28404 100644 --- a/pretor/core/individual/control_node/control_node.py +++ b/pretor/core/individual/control_node/control_node.py @@ -75,7 +75,7 @@ class ControlNode: try: result: ForWorkflow = await self._run(payload) return result - except Exception as e: + except Exception: logger.exception("ControlNode在执行working时发生严重错误") return None diff --git a/pretor/core/individual/supervisory_node/supervisory_node.py b/pretor/core/individual/supervisory_node/supervisory_node.py index b214d47..95265fd 100644 --- a/pretor/core/individual/supervisory_node/supervisory_node.py +++ b/pretor/core/individual/supervisory_node/supervisory_node.py @@ -110,7 +110,7 @@ class SupervisoryNode: else: logger.error(f"SupervisoryNode: 未知响应类型: {type(result)}") return "抱歉,系统内部遇到未知错误,无法正确处理您的请求。" - except Exception as e: + except Exception: logger.exception("SupervisoryNode在处理请求时发生未捕获的严重错误") return "抱歉,监控节点处理请求时发生严重错误,请联系管理员。" diff --git a/pretor/core/workflow/workflow_runner.py b/pretor/core/workflow/workflow_runner.py index 165ab42..1d65bea 100644 --- a/pretor/core/workflow/workflow_runner.py +++ b/pretor/core/workflow/workflow_runner.py @@ -267,7 +267,7 @@ class WorkflowRunningEngine: while True: try: event = await self.workflow_queue.get() - logger.info(f"WorkflowRunningEngine: runner_{i} 接收到事件 {event.event_id} 准备生成工作流。") + logger.info(f"WorkflowRunningEngine: runner_{i} 接收到事件 {event.trace_id} 准备生成工作流。") if not self.consciousness_node: raise WorkflowError("未配置 consciousness_node,无法生成工作流") @@ -285,7 +285,7 @@ class WorkflowRunningEngine: if isinstance(result_obj, ForWorkflowEngine): workflow = result_obj.workflow - workflow.trace_id = event.event_id + workflow.trace_id = event.trace_id workflow.command = event.message workflow.event_info = EventInfo(platform=event.platform, user_name=event.user_name,) @@ -293,7 +293,7 @@ class WorkflowRunningEngine: logger.info( f"WorkflowRunningEngine: runner_{i} 成功生成工作流 {workflow.trace_id}:{workflow.title}") - await self.global_state_machine.update_workflow.remote(event.event_id, workflow) + await self.global_state_machine.update_workflow.remote(event.trace_id, workflow) workflow_engine = WorkflowEngine(workflow, self.consciousness_node, diff --git a/pretor/utils/access.py b/pretor/utils/access.py index 28e3690..0b9eab3 100644 --- a/pretor/utils/access.py +++ b/pretor/utils/access.py @@ -20,7 +20,6 @@ from fastapi import HTTPException, status, Request from pydantic import BaseModel, ValidationError from pretor.core.database.table.user import User from pwdlib import PasswordHash -from pwdlib.hashers.bcrypt import BcryptHasher class TokenData(BaseModel):