-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create new and update existing routes
- Loading branch information
1 parent
88e7131
commit fca04b8
Showing
8 changed files
with
334 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
agents-api/agents_api/routers/agents/create_agent_tools.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Annotated | ||
from uuid import UUID, uuid4 | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
from starlette.status import HTTP_201_CREATED | ||
|
||
from ...autogen.openapi_model import ( | ||
CreateAgentRequest, | ||
CreateOrUpdateAgentRequest, | ||
CreateToolRequest, | ||
ResourceCreatedResponse, | ||
) | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.tools.create_tools import create_tools as create_tools_query | ||
from .router import router | ||
|
||
|
||
@router.post("/agents/{agent_id}/tools", status_code=HTTP_201_CREATED, tags=["agents"]) | ||
async def create_agent_tools( | ||
agent_id: UUID, | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
data: list[CreateToolRequest], | ||
ignore_existing: bool = False, | ||
) -> ResourceCreatedResponse: | ||
_, resp = next( | ||
create_tools_query( | ||
developer_id=x_developer_id, | ||
agent_id=agent_id, | ||
data=data, | ||
ignore_existing=ignore_existing, | ||
).iterrows() | ||
) | ||
|
||
return ResourceCreatedResponse(id=resp["tool_id"], created_at=resp["created_at"]) |
33 changes: 33 additions & 0 deletions
33
agents-api/agents_api/routers/agents/create_or_update_agent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import Annotated | ||
from uuid import UUID | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
from starlette.status import HTTP_201_CREATED | ||
|
||
from ...autogen.openapi_model import ( | ||
CreateOrUpdateAgentRequest, | ||
ResourceCreatedResponse, | ||
) | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.agent.create_or_update_agent import ( | ||
create_or_update_agent as create_or_update_agent_query, | ||
) | ||
from .router import router | ||
|
||
|
||
@router.post("/agents/{agent_id}", status_code=HTTP_201_CREATED, tags=["agents"]) | ||
async def create_or_update_agent( | ||
agent_id: UUID, | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
data: CreateOrUpdateAgentRequest, | ||
) -> ResourceCreatedResponse: | ||
_, resp = next( | ||
create_or_update_agent_query( | ||
developer_id=x_developer_id, | ||
agent_id=agent_id, | ||
data=data, | ||
).iterrows() | ||
) | ||
|
||
return ResourceCreatedResponse(id=agent_id, created_at=resp["created_at"]) |
28 changes: 28 additions & 0 deletions
28
agents-api/agents_api/routers/agents/delete_agent_tools.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Annotated | ||
from uuid import UUID | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
|
||
from ...autogen.openapi_model import ResourceDeletedResponse | ||
from ...common.utils.datetime import utcnow | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.tools.delete_tools import delete_tool as delete_tool_query | ||
from .router import router | ||
|
||
|
||
@router.delete("/agents/{agent_id}/tools/{tool_id}", tags=["agents"]) | ||
async def delete_agent_tools( | ||
agent_id: UUID, | ||
tool_id: UUID, | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
) -> ResourceDeletedResponse: | ||
_, resp = next( | ||
delete_tool_query( | ||
developer_id=x_developer_id, | ||
agent_id=agent_id, | ||
tool_id=tool_id, | ||
).iterrows() | ||
) | ||
|
||
return ResourceDeletedResponse(id=resp["tool_id"], deleted_at=utcnow()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Annotated, Literal | ||
from uuid import UUID | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
|
||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.tools.list_tools import list_tools as list_tools_query | ||
from .router import router | ||
|
||
|
||
@router.get("/agents/{agent_id}/tools", tags=["agents"]) | ||
async def list_agent_tools( | ||
agent_id: UUID, | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
limit: int = 100, | ||
offset: int = 0, | ||
sort_by: Literal["created_at", "updated_at"] = "created_at", | ||
direction: Literal["asc", "desc"] = "desc", | ||
) -> list[tuple[str, dict]]: | ||
return [ | ||
row | ||
for _, row in list_tools_query( | ||
developer_id=x_developer_id, | ||
agent_id=agent_id, | ||
limit=limit, | ||
offset=offset, | ||
sort_by=sort_by, | ||
direction=direction, | ||
).iterrows() | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import Annotated | ||
from uuid import UUID | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
|
||
from ...autogen.openapi_model import ( | ||
PatchToolRequest, | ||
ResourceUpdatedResponse, | ||
) | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.tools.patch_tool import patch_tool as patch_tool_query | ||
from .router import router | ||
|
||
|
||
@router.patch("/agents/{agent_id}/tools/{tool_id}", tags=["agents"]) | ||
async def patch_agent_tools( | ||
agent_id: UUID, | ||
tool_id: UUID, | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
patch_tool: PatchToolRequest, | ||
) -> ResourceUpdatedResponse: | ||
_, resp = next( | ||
patch_tool_query( | ||
developer_id=x_developer_id, | ||
agent_id=agent_id, | ||
tool_id=tool_id, | ||
patch_tool=patch_tool, | ||
).iterrows() | ||
) | ||
|
||
return ResourceUpdatedResponse(id=resp["tool_id"], updated_at=resp["updated_at"]) |
32 changes: 32 additions & 0 deletions
32
agents-api/agents_api/routers/agents/update_agent_tools.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import Annotated | ||
from uuid import UUID | ||
|
||
from fastapi import Depends | ||
from pydantic import UUID4 | ||
|
||
from ...autogen.openapi_model import ( | ||
ResourceUpdatedResponse, | ||
UpdateToolRequest, | ||
) | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...models.tools.update_tool import update_tool as update_tool_query | ||
from .router import router | ||
|
||
|
||
@router.put("/agents/{agent_id}/tools/{tool_id}", tags=["agents"]) | ||
async def update_agent_tools( | ||
agent_id: UUID, | ||
tool_id: UUID, | ||
x_developer_id: Annotated[UUID4, Depends(get_developer_id)], | ||
data: UpdateToolRequest, | ||
) -> ResourceUpdatedResponse: | ||
_, resp = next( | ||
update_tool_query( | ||
developer_id=x_developer_id, | ||
agent_id=agent_id, | ||
tool_id=tool_id, | ||
data=data, | ||
).iterrows() | ||
) | ||
|
||
return ResourceUpdatedResponse(id=resp["tool_id"], updated_at=resp["updated_at"]) |
Oops, something went wrong.