feat: add GET endpoints for listing and retrieving agents
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
4527c85e3d
commit
7ecc0496f5
|
|
@ -21,6 +21,7 @@ from app.schemas.agent import (
|
||||||
AgentRegisterRequestLegacy,
|
AgentRegisterRequestLegacy,
|
||||||
AgentRegisterResponse,
|
AgentRegisterResponse,
|
||||||
AgentRegisterResponseLegacy,
|
AgentRegisterResponseLegacy,
|
||||||
|
AgentResponse,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -109,6 +110,46 @@ async def validate_agent_token(
|
||||||
# --- Route handlers (thin controllers) ---
|
# --- 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(
|
@router.post(
|
||||||
"/register",
|
"/register",
|
||||||
response_model=AgentRegisterResponse | AgentRegisterResponseLegacy,
|
response_model=AgentRegisterResponse | AgentRegisterResponseLegacy,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue