from fastapi import FastAPI, HTTPException from pydantic import BaseModel from agents.clean_agent.agent import execute_agent_with_api import uvicorn app = FastAPI(title="Knowledge Agent API", description="API for executing knowledge agent") @app.post("/execute") async def execute_agent(input: str): """ 执行Agent处理用户指令 Args: user_input: 包含用户指令的对象 Returns: dict: 包含执行结果的字典 """ try: result = execute_agent_with_api(input) return {"status": "success", "result": result} except Exception as e: raise HTTPException(status_code=500, detail=f"执行Agent时出错: {str(e)}") @app.get("/") async def root(): return {"message": "Knowledge Agent API 服务已启动,请使用 /execute 端点执行Agent"} if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000)