feat: 完善企业场景多线路由与执行稳定性
补齐平台模板与场景 DSL、预算控制、执行看板和企业场景脚本,增强 Windows 启动/迁移与前端代理和聊天会话记忆,修复执行创建阶段 500 与异步链路排障体验。 Made-with: Cursor
This commit is contained in:
@@ -3,7 +3,7 @@ Agent管理API
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List, Optional, Dict, Any
|
||||
from datetime import datetime
|
||||
import logging
|
||||
@@ -35,6 +35,7 @@ class AgentCreate(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
workflow_config: Dict[str, Any] # 包含nodes和edges
|
||||
budget_config: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
class AgentUpdate(BaseModel):
|
||||
@@ -43,6 +44,28 @@ class AgentUpdate(BaseModel):
|
||||
description: Optional[str] = None
|
||||
workflow_config: Optional[Dict[str, Any]] = None
|
||||
status: Optional[str] = None
|
||||
budget_config: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
class SceneTemplateItem(BaseModel):
|
||||
"""场景模板列表项(元数据)"""
|
||||
|
||||
id: str
|
||||
title: str
|
||||
description: str
|
||||
category: Optional[str] = None
|
||||
default_temperature: Optional[float] = None
|
||||
parameter_hints: List[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
class AgentFromSceneTemplateCreate(BaseModel):
|
||||
"""从场景模板创建 Agent"""
|
||||
|
||||
template_id: str
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
parameters: Dict[str, Any] = Field(default_factory=dict)
|
||||
budget_config: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
class AgentResponse(BaseModel):
|
||||
@@ -51,6 +74,7 @@ class AgentResponse(BaseModel):
|
||||
name: str
|
||||
description: Optional[str]
|
||||
workflow_config: Dict[str, Any]
|
||||
budget_config: Optional[Dict[str, Any]] = None
|
||||
version: int
|
||||
status: str
|
||||
user_id: Optional[str] # 允许为None
|
||||
@@ -125,6 +149,7 @@ async def get_agents(
|
||||
"name": agent.name,
|
||||
"description": agent.description,
|
||||
"workflow_config": agent.workflow_config,
|
||||
"budget_config": agent.budget_config,
|
||||
"version": agent.version,
|
||||
"status": agent.status,
|
||||
"user_id": agent.user_id if agent.user_id else None,
|
||||
@@ -171,6 +196,7 @@ async def create_agent(
|
||||
name=agent_data.name,
|
||||
description=agent_data.description,
|
||||
workflow_config=agent_data.workflow_config,
|
||||
budget_config=agent_data.budget_config,
|
||||
user_id=current_user.id,
|
||||
status="draft"
|
||||
)
|
||||
@@ -259,6 +285,9 @@ async def update_agent(
|
||||
if agent_data.status not in valid_statuses:
|
||||
raise ValidationError(f"无效的状态: {agent_data.status}")
|
||||
agent.status = agent_data.status
|
||||
|
||||
if agent_data.budget_config is not None:
|
||||
agent.budget_config = agent_data.budget_config
|
||||
|
||||
db.commit()
|
||||
db.refresh(agent)
|
||||
@@ -403,6 +432,9 @@ async def duplicate_agent(
|
||||
name=new_name,
|
||||
description=original_agent.description,
|
||||
workflow_config=new_workflow_config,
|
||||
budget_config=copy.deepcopy(original_agent.budget_config)
|
||||
if original_agent.budget_config is not None
|
||||
else None,
|
||||
user_id=current_user.id,
|
||||
status="draft", # 复制的Agent状态为草稿
|
||||
version=1 # 版本号从1开始
|
||||
@@ -442,6 +474,7 @@ async def export_agent(
|
||||
"name": agent.name,
|
||||
"description": agent.description,
|
||||
"workflow_config": workflow_config,
|
||||
"budget_config": agent.budget_config,
|
||||
"version": agent.version,
|
||||
"status": agent.status,
|
||||
"exported_at": datetime.utcnow().isoformat()
|
||||
@@ -507,6 +540,7 @@ async def import_agent(
|
||||
counter += 1
|
||||
|
||||
# 创建Agent
|
||||
bc = agent_data.get("budget_config")
|
||||
agent = Agent(
|
||||
name=name,
|
||||
description=description,
|
||||
@@ -514,6 +548,7 @@ async def import_agent(
|
||||
"nodes": nodes,
|
||||
"edges": edges
|
||||
},
|
||||
budget_config=bc if isinstance(bc, dict) else None,
|
||||
user_id=current_user.id,
|
||||
status="draft", # 导入的Agent默认为草稿状态
|
||||
version=1
|
||||
|
||||
Reference in New Issue
Block a user