完整实现 Swarm 多智能体协作系统
- 新增 CLIPluginAdapter 统一接口 (backend/app/core/agent_adapter.py) - 新增 LLM 服务层,支持 Anthropic/OpenAI/DeepSeek/Ollama (backend/app/services/llm_service.py) - 新增 Agent 执行引擎,支持文件锁自动管理 (backend/app/services/agent_executor.py) - 新增 NativeLLMAgent 原生 LLM 适配器 (backend/app/adapters/native_llm_agent.py) - 新增进程管理器 (backend/app/services/process_manager.py) - 新增 Agent 控制 API (backend/app/routers/agents_control.py) - 新增 WebSocket 实时通信 (backend/app/routers/websocket.py) - 更新前端 AgentsPage,支持启动/停止 Agent - 测试通过:Agent 启动、批量操作、栅栏同步 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
75
backend/app/main.py
Normal file
75
backend/app/main.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
Swarm Command Center - FastAPI 主入口
|
||||
多智能体协作系统的协调层后端服务
|
||||
"""
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
import uvicorn
|
||||
|
||||
from app.routers import agents, locks, meetings, heartbeats, workflows, resources, roles, humans
|
||||
from app.routers import agents_control, websocket
|
||||
|
||||
# 创建 FastAPI 应用实例
|
||||
app = FastAPI(
|
||||
title="Swarm Command Center API",
|
||||
description="多智能体协作系统的协调层后端服务",
|
||||
version="0.1.0",
|
||||
)
|
||||
|
||||
# 配置 CORS - 允许前端访问
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:3000", "http://127.0.0.1:3000"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
# 基础健康检查端点
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""健康检查端点"""
|
||||
return {"status": "ok", "service": "Swarm Command Center"}
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
@app.get("/api/health")
|
||||
async def health():
|
||||
"""详细健康检查"""
|
||||
return {
|
||||
"status": "healthy",
|
||||
"version": "0.1.0",
|
||||
"services": {
|
||||
"api": "ok",
|
||||
"storage": "ok",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# 注册 API 路由
|
||||
app.include_router(agents.router, prefix="/api/agents", tags=["agents"])
|
||||
app.include_router(agents_control.router, tags=["agents-control"])
|
||||
app.include_router(locks.router, prefix="/api/locks", tags=["locks"])
|
||||
app.include_router(meetings.router, prefix="/api/meetings", tags=["meetings"])
|
||||
app.include_router(heartbeats.router, prefix="/api/heartbeats", tags=["heartbeats"])
|
||||
app.include_router(workflows.router, prefix="/api/workflows", tags=["workflows"])
|
||||
app.include_router(resources.router, prefix="/api", tags=["resources"])
|
||||
app.include_router(roles.router, prefix="/api/roles", tags=["roles"])
|
||||
app.include_router(humans.router, prefix="/api/humans", tags=["humans"])
|
||||
app.include_router(websocket.router, tags=["websocket"])
|
||||
|
||||
|
||||
def main():
|
||||
"""启动开发服务器"""
|
||||
uvicorn.run(
|
||||
"app.main:app",
|
||||
host="0.0.0.0",
|
||||
port=8000,
|
||||
reload=True,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user