wip: 初步增加了worker_individual,修改了trace_id

This commit is contained in:
朝夕 2026-04-21 15:06:50 +08:00
parent f59ac27782
commit 446e208193
12 changed files with 76 additions and 26 deletions

View File

@ -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

View File

@ -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

View File

@ -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 = {}

View File

@ -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

View File

@ -13,4 +13,5 @@
# limitations under the License.
from pretor.core.database.table.user import User
from pretor.core.database.table.provider import Provider
from pretor.core.database.table.provider import Provider
from pretor.core.database.table.individual import WorkerIndividual

View File

@ -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

View File

@ -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
provider_owner: int
is_active: bool = Field(default=True, description="该服务商节点是否在线/启用")

View File

@ -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

View File

@ -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

View File

@ -110,7 +110,7 @@ class SupervisoryNode:
else:
logger.error(f"SupervisoryNode: 未知响应类型: {type(result)}")
return "抱歉,系统内部遇到未知错误,无法正确处理您的请求。"
except Exception as e:
except Exception:
logger.exception("SupervisoryNode在处理请求时发生未捕获的严重错误")
return "抱歉,监控节点处理请求时发生严重错误,请联系管理员。"

View File

@ -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,

View File

@ -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):