首次提交
This commit is contained in:
68
app/routers/agents.py
Normal file
68
app/routers/agents.py
Normal file
@@ -0,0 +1,68 @@
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
from typing import List
|
||||
|
||||
from app.models import AgentConfig, AgentDefinition
|
||||
from app.services.agent_service import get_agent_service, AgentService
|
||||
|
||||
# Initialize Router
|
||||
router = APIRouter(
|
||||
prefix="/agents",
|
||||
tags=["Agents"]
|
||||
)
|
||||
|
||||
# ==========================
|
||||
# 🤖 Agent Management API
|
||||
# ==========================
|
||||
|
||||
@router.post("", response_model=AgentDefinition)
|
||||
async def create_agent_def(
|
||||
config: AgentConfig,
|
||||
service: AgentService = Depends(get_agent_service)
|
||||
):
|
||||
"""Create a new Agent definition."""
|
||||
return service.create_agent(config)
|
||||
|
||||
|
||||
@router.get("", response_model=List[AgentDefinition])
|
||||
async def list_agents(
|
||||
service: AgentService = Depends(get_agent_service)
|
||||
):
|
||||
"""List all available Agents."""
|
||||
return service.list_agents()
|
||||
|
||||
|
||||
@router.get("/{agent_id}", response_model=AgentDefinition)
|
||||
async def get_agent_def(
|
||||
agent_id: str,
|
||||
service: AgentService = Depends(get_agent_service)
|
||||
):
|
||||
"""Get specific Agent definition."""
|
||||
agent = service.get_agent(agent_id)
|
||||
if not agent:
|
||||
raise HTTPException(status_code=404, detail="Agent not found")
|
||||
return agent
|
||||
|
||||
|
||||
@router.put("/{agent_id}", response_model=AgentDefinition)
|
||||
async def update_agent_def(
|
||||
agent_id: str,
|
||||
config: AgentConfig,
|
||||
service: AgentService = Depends(get_agent_service)
|
||||
):
|
||||
"""Update an Agent definition."""
|
||||
agent = service.update_agent(agent_id, config)
|
||||
if not agent:
|
||||
raise HTTPException(status_code=404, detail="Agent not found")
|
||||
return agent
|
||||
|
||||
|
||||
@router.delete("/{agent_id}")
|
||||
async def delete_agent_def(
|
||||
agent_id: str,
|
||||
service: AgentService = Depends(get_agent_service)
|
||||
):
|
||||
"""Delete an Agent definition."""
|
||||
success = service.delete_agent(agent_id)
|
||||
if not success:
|
||||
raise HTTPException(status_code=404, detail="Agent not found")
|
||||
return {"status": "deleted", "agent_id": agent_id}
|
||||
Reference in New Issue
Block a user