wip: 初步增加了worker_individual,修改了trace_id
This commit is contained in:
parent
f59ac27782
commit
446e208193
|
|
@ -12,7 +12,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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 pydantic import BaseModel
|
||||||
from pretor.utils.access import Accessor, TokenData
|
from pretor.utils.access import Accessor, TokenData
|
||||||
from pretor.api.platform.event import PretorEvent
|
from pretor.api.platform.event import PretorEvent
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from fastapi import APIRouter, Request, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
from pretor.utils.access import TokenData, Accessor
|
from pretor.utils.access import TokenData, Accessor
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,6 @@ import ray
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from fastapi import FastAPI,WebSocket
|
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.staticfiles import StaticFiles
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
import os
|
import os
|
||||||
|
|
@ -34,12 +29,7 @@ from pretor.api.agent import agent_router
|
||||||
@ray.remote
|
@ray.remote
|
||||||
class PretorGateway:
|
class PretorGateway:
|
||||||
gateway: Dict[str, WebSocket]
|
gateway: Dict[str, WebSocket]
|
||||||
def __init__(self,
|
def __init__(self):
|
||||||
postgres_database: PostgresDatabase,
|
|
||||||
global_state_machine: GlobalStateMachine,
|
|
||||||
supervisory_node: SupervisoryNode,
|
|
||||||
consciousness_node: ConsciousnessNode,
|
|
||||||
control_node: ControlNode,):
|
|
||||||
self.app = FastAPI()
|
self.app = FastAPI()
|
||||||
self.gateway = {}
|
self.gateway = {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -14,3 +14,4 @@
|
||||||
|
|
||||||
from pretor.core.database.table.user import User
|
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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -15,12 +15,18 @@
|
||||||
from sqlmodel import SQLModel, Field
|
from sqlmodel import SQLModel, Field
|
||||||
from typing import List
|
from typing import List
|
||||||
from sqlalchemy import Column, JSON
|
from sqlalchemy import Column, JSON
|
||||||
|
from typing import Optional, Literal
|
||||||
|
|
||||||
class Provider(SQLModel, table=True):
|
class Provider(SQLModel, table=True):
|
||||||
__tablename__ = "provider"
|
__tablename__ = "provider"
|
||||||
provider_title: str = Field(primary_key=True)
|
provider_id: str = Field(primary_key=True)
|
||||||
provider_url: str
|
provider_title: str = Field(index=True)
|
||||||
provider_apikey: str
|
provider_type: Literal["openai", "vllm"]
|
||||||
|
|
||||||
|
provider_url: Optional[str]
|
||||||
|
provider_apikey: Optional[str]
|
||||||
|
|
||||||
provider_models: List[str] = Field(sa_column=Column(JSON))
|
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="该服务商节点是否在线/启用")
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import ray
|
import ray
|
||||||
import pathlib
|
|
||||||
from pretor.core.global_state_machine.provider_manager import ProviderManager
|
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.tool_manager import GlobalToolManager
|
||||||
from pretor.core.global_state_machine.model_provider import Provider, ProviderArgs
|
from pretor.core.global_state_machine.model_provider import Provider, ProviderArgs
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class ControlNode:
|
||||||
try:
|
try:
|
||||||
result: ForWorkflow = await self._run(payload)
|
result: ForWorkflow = await self._run(payload)
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.exception("ControlNode在执行working时发生严重错误")
|
logger.exception("ControlNode在执行working时发生严重错误")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ class SupervisoryNode:
|
||||||
else:
|
else:
|
||||||
logger.error(f"SupervisoryNode: 未知响应类型: {type(result)}")
|
logger.error(f"SupervisoryNode: 未知响应类型: {type(result)}")
|
||||||
return "抱歉,系统内部遇到未知错误,无法正确处理您的请求。"
|
return "抱歉,系统内部遇到未知错误,无法正确处理您的请求。"
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.exception("SupervisoryNode在处理请求时发生未捕获的严重错误")
|
logger.exception("SupervisoryNode在处理请求时发生未捕获的严重错误")
|
||||||
return "抱歉,监控节点处理请求时发生严重错误,请联系管理员。"
|
return "抱歉,监控节点处理请求时发生严重错误,请联系管理员。"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -267,7 +267,7 @@ class WorkflowRunningEngine:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
event = await self.workflow_queue.get()
|
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:
|
if not self.consciousness_node:
|
||||||
raise WorkflowError("未配置 consciousness_node,无法生成工作流")
|
raise WorkflowError("未配置 consciousness_node,无法生成工作流")
|
||||||
|
|
@ -285,7 +285,7 @@ class WorkflowRunningEngine:
|
||||||
if isinstance(result_obj, ForWorkflowEngine):
|
if isinstance(result_obj, ForWorkflowEngine):
|
||||||
workflow = result_obj.workflow
|
workflow = result_obj.workflow
|
||||||
|
|
||||||
workflow.trace_id = event.event_id
|
workflow.trace_id = event.trace_id
|
||||||
workflow.command = event.message
|
workflow.command = event.message
|
||||||
workflow.event_info = EventInfo(platform=event.platform,
|
workflow.event_info = EventInfo(platform=event.platform,
|
||||||
user_name=event.user_name,)
|
user_name=event.user_name,)
|
||||||
|
|
@ -293,7 +293,7 @@ class WorkflowRunningEngine:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"WorkflowRunningEngine: runner_{i} 成功生成工作流 {workflow.trace_id}:{workflow.title}")
|
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,
|
workflow_engine = WorkflowEngine(workflow,
|
||||||
self.consciousness_node,
|
self.consciousness_node,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ from fastapi import HTTPException, status, Request
|
||||||
from pydantic import BaseModel, ValidationError
|
from pydantic import BaseModel, ValidationError
|
||||||
from pretor.core.database.table.user import User
|
from pretor.core.database.table.user import User
|
||||||
from pwdlib import PasswordHash
|
from pwdlib import PasswordHash
|
||||||
from pwdlib.hashers.bcrypt import BcryptHasher
|
|
||||||
|
|
||||||
|
|
||||||
class TokenData(BaseModel):
|
class TokenData(BaseModel):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue