Files
voidea/app/api/v1/agents.py
T

55 lines
1.6 KiB
Python

"""Agents API routes for VoIdea."""
from typing import Annotated
from fastapi import APIRouter, Depends, HTTPException, status
from app.agents.registry import registry
from app.core.dependencies import get_current_user
from app.models.user import User
from app.schemas.agent import AgentRunRequest, AgentStatusResponse
from app.services.agent_service import AgentService
router = APIRouter()
def get_agent_service() -> AgentService:
return AgentService(registry)
@router.get("/", response_model=list[AgentStatusResponse])
async def list_agents(
user: Annotated[User, Depends(get_current_user)],
):
service = get_agent_service()
agents = service.list_agents()
return [AgentStatusResponse(**a) for a in agents]
@router.get("/{agent_name}", response_model=AgentStatusResponse)
async def get_agent(
agent_name: str,
user: Annotated[User, Depends(get_current_user)],
):
service = get_agent_service()
agent = service.get_agent(agent_name)
if not agent:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Agent not found")
return AgentStatusResponse(**agent)
@router.post("/{agent_name}/run")
async def run_agent(
agent_name: str,
body: AgentRunRequest,
user: Annotated[User, Depends(get_current_user)],
):
service = get_agent_service()
result = await service.run_agent(agent_name, body.context)
if not result["success"] and "not found" in result.get("message", ""):
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=result["message"],
)
return result