diff --git a/app/routes/agents.py b/app/routes/agents.py index 411c8d3..4a329e2 100644 --- a/app/routes/agents.py +++ b/app/routes/agents.py @@ -21,6 +21,7 @@ from app.schemas.agent import ( AgentRegisterRequestLegacy, AgentRegisterResponse, AgentRegisterResponseLegacy, + AgentResponse, ) logger = logging.getLogger(__name__) @@ -109,6 +110,46 @@ async def validate_agent_token( # --- Route handlers (thin controllers) --- +@router.get( + "/", + response_model=list[AgentResponse], + summary="List all agents", + description="Retrieve all registered agents, optionally filtered by tenant.", +) +async def list_agents( + db: AsyncSessionDep, + tenant_id: uuid.UUID | None = None, +) -> list[Agent]: + """List all agents, optionally filtered by tenant.""" + query = select(Agent) + if tenant_id: + query = query.where(Agent.tenant_id == tenant_id) + query = query.order_by(Agent.created_at.desc()) + + result = await db.execute(query) + return list(result.scalars().all()) + + +@router.get( + "/{agent_id}", + response_model=AgentResponse, + summary="Get agent by ID", + description="Retrieve a specific agent by its UUID.", +) +async def get_agent( + agent_id: uuid.UUID, + db: AsyncSessionDep, +) -> Agent: + """Get a specific agent by ID.""" + agent = await get_agent_by_id(db, agent_id) + if agent is None: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail=f"Agent {agent_id} not found", + ) + return agent + + @router.post( "/register", response_model=AgentRegisterResponse | AgentRegisterResponseLegacy,