feat(backend): add ontology and orchestrator API endpoints

New endpoints:
- server/src/app/api/v1/endpoints/ontology.py: ontology API
- server/src/app/api/v1/endpoints/orchestrator.py: orchestrator API

New schemas:
- server/src/app/schemas/ontology.py: ontology data schemas
- server/src/app/schemas/orchestrator.py: orchestrator data schemas
- server/src/app/schemas/user_agent.py: user agent data schemas

New services:
- server/src/app/services/ontology.py: ontology business logic
- server/src/app/services/orchestrator.py: orchestrator business logic
- server/src/app/services/runtime_chat.py: runtime chat service
- server/src/app/services/user_agent.py: user agent service

New tests:
- server/tests/test_ontology_service.py
- server/tests/test_orchestrator_service.py
- server/tests/test_user_agent_service.py
This commit is contained in:
caoxiaozhu
2026-05-12 01:24:39 +00:00
parent 19da459bb3
commit 22d47cbf2b
12 changed files with 4262 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
from __future__ import annotations
from typing import Annotated
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.api.deps import get_db
from app.schemas.common import ErrorResponse
from app.schemas.ontology import OntologyParseRequest, OntologyParseResult
from app.services.ontology import SemanticOntologyService
router = APIRouter(prefix="/ontology")
DbSession = Annotated[Session, Depends(get_db)]
@router.post(
"/parse",
response_model=OntologyParseResult,
summary="解析自然语言为语义本体",
description=(
"把自然语言问题解析成 Day 3 约定的 8 个核心字段,"
"并写入 AgentRun 与 SemanticParseLog。"
),
responses={
status.HTTP_400_BAD_REQUEST: {
"model": ErrorResponse,
"description": "请求缺少有效 query 或解析请求格式不合法。",
}
},
)
def parse_ontology(payload: OntologyParseRequest, db: DbSession) -> OntologyParseResult:
try:
return SemanticOntologyService(db).parse(payload)
except ValueError as exc:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc

View File

@@ -0,0 +1,33 @@
from __future__ import annotations
from typing import Annotated
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.api.deps import get_db
from app.schemas.common import ErrorResponse
from app.schemas.orchestrator import OrchestratorRequest, OrchestratorResponse
from app.services.orchestrator import OrchestratorService
router = APIRouter(prefix="/orchestrator")
DbSession = Annotated[Session, Depends(get_db)]
@router.post(
"/run",
response_model=OrchestratorResponse,
summary="运行 Orchestrator 统一调度",
description="统一接收用户消息、定时任务和系统事件,完成语义解析、权限判断、路由和占位执行。",
responses={
status.HTTP_400_BAD_REQUEST: {
"model": ErrorResponse,
"description": "请求缺少 message 或 task_id无法启动调度。",
}
},
)
def run_orchestrator(payload: OrchestratorRequest, db: DbSession) -> OrchestratorResponse:
try:
return OrchestratorService(db).run(payload)
except ValueError as exc:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc