Spaces:
Sleeping
Sleeping
| """ | |
| Agent routes - manage agent configurations. | |
| """ | |
| from fastapi import APIRouter, HTTPException | |
| from typing import Optional, List | |
| from ..agent import ( | |
| AgentInfo, | |
| get, | |
| list_agents, | |
| default_agent, | |
| register, | |
| unregister, | |
| ) | |
| router = APIRouter(prefix="/agent", tags=["agent"]) | |
| async def get_agents( | |
| mode: Optional[str] = None, | |
| include_hidden: bool = False | |
| ): | |
| """List all available agents.""" | |
| return list_agents(mode=mode, include_hidden=include_hidden) | |
| async def get_default_agent(): | |
| """Get the default agent configuration.""" | |
| return default_agent() | |
| async def get_agent(agent_id: str): | |
| """Get a specific agent by ID.""" | |
| agent = get(agent_id) | |
| if not agent: | |
| raise HTTPException(status_code=404, detail=f"Agent not found: {agent_id}") | |
| return agent | |
| async def create_agent(agent: AgentInfo): | |
| """Register a custom agent.""" | |
| existing = get(agent.id) | |
| if existing and existing.native: | |
| raise HTTPException(status_code=400, detail=f"Cannot override native agent: {agent.id}") | |
| register(agent) | |
| return agent | |
| async def delete_agent(agent_id: str): | |
| """Unregister a custom agent.""" | |
| agent = get(agent_id) | |
| if not agent: | |
| raise HTTPException(status_code=404, detail=f"Agent not found: {agent_id}") | |
| if agent.native: | |
| raise HTTPException(status_code=400, detail=f"Cannot delete native agent: {agent_id}") | |
| unregister(agent_id) | |
| return {"deleted": agent_id} | |