Skip to content

Commit

Permalink
feat(backend): refactored agent params into params directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ezawadski committed Jan 9, 2025
1 parent 28e0fcb commit b7af340
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 43 deletions.
54 changes: 23 additions & 31 deletions src/backend/routers/agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
from typing import Annotated, Optional

from fastapi import APIRouter, Depends, HTTPException, Query
from fastapi import APIRouter, Depends, HTTPException
from fastapi import File as RequestFile
from fastapi import UploadFile as FastAPIUploadFile

Expand Down Expand Up @@ -42,10 +41,12 @@
UploadAgentFileResponse,
)
from backend.schemas.params.agent import (
agent_id_path,
agent_tool_metadata_id_path,
file_id_path,
AgentIdPathParam,
AgentToolMetadataIdPathParam,
VisibilityQueryParam,
)
from backend.schemas.params.file import FileIdPathParam
from backend.schemas.params.organization import OrganizationIdQueryParam
from backend.schemas.params.shared import PaginationQueryParams
from backend.services.agent import (
raise_db_error,
Expand Down Expand Up @@ -129,23 +130,14 @@ async def create_agent(
@router.get("", response_model=list[AgentPublic])
async def list_agents(
*,
page_params: Annotated[PaginationQueryParams, Depends()],
visibility: Annotated[AgentVisibility, Query(
title="Visibility",
description="Agent visibility",
)] = AgentVisibility.ALL,
organization_id: Annotated[Optional[str], Query(
title="Organization ID",
description="Organization ID of the agent",
)] = None,
page_params: PaginationQueryParams,
visibility: VisibilityQueryParam = AgentVisibility.ALL,
organization_id: OrganizationIdQueryParam = None,
session: DBSessionDep,
ctx: Context = Depends(get_context),
) -> list[AgentPublic]:
"""
List all agents.
Returns:
list[AgentPublic]: List of agents with no user ID or organization ID.
"""
# TODO: get organization_id from user
user_id = ctx.get_user_id()
Expand Down Expand Up @@ -173,7 +165,7 @@ async def list_agents(

@router.get("/{agent_id}", response_model=AgentPublic)
async def get_agent_by_id(
agent_id: Annotated[str, agent_id_path],
agent_id: AgentIdPathParam,
session: DBSessionDep,
ctx: Context = Depends(get_context)
) -> AgentPublic:
Expand Down Expand Up @@ -208,7 +200,7 @@ async def get_agent_by_id(

@router.get("/{agent_id}/deployments", response_model=list[DeploymentSchema])
async def get_agent_deployment(
agent_id: Annotated[str, agent_id_path],
agent_id: AgentIdPathParam,
session: DBSessionDep,
ctx: Context = Depends(get_context)
) -> DeploymentSchema:
Expand Down Expand Up @@ -236,7 +228,7 @@ async def get_agent_deployment(
],
)
async def update_agent(
agent_id: Annotated[str, agent_id_path],
agent_id: AgentIdPathParam,
new_agent: UpdateAgentRequest,
session: DBSessionDep,
ctx: Context = Depends(get_context),
Expand Down Expand Up @@ -284,7 +276,7 @@ async def update_agent(

@router.delete("/{agent_id}", response_model=DeleteAgent)
async def delete_agent(
agent_id: Annotated[str, agent_id_path],
agent_id: AgentIdPathParam,
session: DBSessionDep,
ctx: Context = Depends(get_context),
) -> DeleteAgent:
Expand Down Expand Up @@ -380,7 +372,7 @@ async def update_or_create_tool_metadata(

@router.get("/{agent_id}/tool-metadata", response_model=list[AgentToolMetadataPublic])
async def list_agent_tool_metadata(
agent_id: Annotated[str, agent_id_path],
agent_id: AgentIdPathParam,
session: DBSessionDep,
ctx: Context = Depends(get_context)
) -> list[AgentToolMetadataPublic]:
Expand All @@ -406,7 +398,7 @@ async def list_agent_tool_metadata(
response_model=AgentToolMetadataPublic,
)
def create_agent_tool_metadata(
agent_id: Annotated[str, agent_id_path],
agent_id: AgentIdPathParam,
agent_tool_metadata: CreateAgentToolMetadataRequest,
session: DBSessionDep,
ctx: Context = Depends(get_context),
Expand Down Expand Up @@ -446,8 +438,8 @@ def create_agent_tool_metadata(

@router.put("/{agent_id}/tool-metadata/{agent_tool_metadata_id}")
async def update_agent_tool_metadata(
agent_id: Annotated[str, agent_id_path],
agent_tool_metadata_id: Annotated[str, agent_tool_metadata_id_path],
agent_id: AgentIdPathParam,
agent_tool_metadata_id: AgentToolMetadataIdPathParam,
new_agent_tool_metadata: UpdateAgentToolMetadataRequest,
session: DBSessionDep,
ctx: Context = Depends(get_context),
Expand Down Expand Up @@ -480,8 +472,8 @@ async def update_agent_tool_metadata(

@router.delete("/{agent_id}/tool-metadata/{agent_tool_metadata_id}")
async def delete_agent_tool_metadata(
agent_id: Annotated[str, agent_id_path],
agent_tool_metadata_id: Annotated[str, agent_tool_metadata_id_path],
agent_id: AgentIdPathParam,
agent_tool_metadata_id: AgentToolMetadataIdPathParam,
session: DBSessionDep,
ctx: Context = Depends(get_context),
) -> DeleteAgentToolMetadata:
Expand Down Expand Up @@ -541,8 +533,8 @@ async def batch_upload_file(

@router.get("/{agent_id}/files/{file_id}", response_model=FileMetadata)
async def get_agent_file(
agent_id: Annotated[str, agent_id_path],
file_id: Annotated[str, file_id_path],
agent_id: AgentIdPathParam,
file_id: FileIdPathParam,
session: DBSessionDep,
ctx: Context = Depends(get_context),
) -> FileMetadata:
Expand Down Expand Up @@ -580,8 +572,8 @@ async def get_agent_file(

@router.delete("/{agent_id}/files/{file_id}")
async def delete_agent_file(
agent_id: Annotated[str, agent_id_path],
file_id: Annotated[str, file_id_path],
agent_id: AgentIdPathParam,
file_id: FileIdPathParam,
session: DBSessionDep,
ctx: Context = Depends(get_context),
) -> DeleteAgentFileResponse:
Expand Down
24 changes: 14 additions & 10 deletions src/backend/schemas/params/agent.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
"""
Query and Path Parameters for Agents
"""
from fastapi import Path
from typing import Annotated

agent_id_path = Path(
from fastapi import Path, Query

from backend.schemas.agent import AgentVisibility

VisibilityQueryParam = Annotated[AgentVisibility, Query(
title="Visibility",
description="Agent visibility",
)]

AgentIdPathParam = Annotated[str, Path(
title="Agent ID",
description="Agent ID for agent in question",
)
)]

agent_tool_metadata_id_path = Path(
AgentToolMetadataIdPathParam = Annotated[str, Path(
title="Agent Tool Metadata ID",
description="Agent Tool Metadata ID for tool metadata in question",
)

file_id_path = Path(
title="File ID",
description="File ID for file in question",
)
)]
11 changes: 11 additions & 0 deletions src/backend/schemas/params/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Query and Path Parameters for Files
"""
from typing import Annotated

from fastapi import Path

FileIdPathParam = Annotated[str, Path(
title="File ID",
description="File ID for file in question",
)]
11 changes: 11 additions & 0 deletions src/backend/schemas/params/organization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Query and Path Parameters for Organizations
"""
from typing import Annotated, Optional

from fastapi import Query

OrganizationIdQueryParam = Annotated[Optional[str], Query(
title="Organization ID",
description="Organization ID of the agent",
)]
6 changes: 4 additions & 2 deletions src/backend/schemas/params/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""
from typing import Annotated

from fastapi import Query
from fastapi import Depends, Query


class PaginationQueryParams:
class PaginationParams:
"""
Common pagination query parameters
"""
Expand All @@ -23,3 +23,5 @@ def __init__(
) -> None:
self.offset = offset
self.limit = limit

PaginationQueryParams = Annotated[PaginationParams, Depends()]

0 comments on commit b7af340

Please sign in to comment.