From 7ecc0496f5ad5e0ba6f41c91901372c881972d8b Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 7 Dec 2025 12:57:39 +0100 Subject: [PATCH] feat: add GET endpoints for listing and retrieving agents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GET /api/v1/agents/ - list all agents (with optional tenant_id filter) - GET /api/v1/agents/{agent_id} - get specific agent 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/routes/agents.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) 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,