diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.py index be1b9c8c..50c4d262 100644 --- a/letta/server/rest_api/routers/v1/tools.py +++ b/letta/server/rest_api/routers/v1/tools.py @@ -59,7 +59,7 @@ def count_tools( @router.get("/{tool_id}", response_model=Tool, operation_id="retrieve_tool") -def retrieve_tool( +async def retrieve_tool( tool_id: str, server: SyncServer = Depends(get_letta_server), actor_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present @@ -67,8 +67,8 @@ def retrieve_tool( """ Get a tool by ID """ - actor = server.user_manager.get_user_or_default(user_id=actor_id) - tool = server.tool_manager.get_tool_by_id(tool_id=tool_id, actor=actor) + actor = await server.user_manager.get_actor_or_default_async(actor_id=actor_id) + tool = await server.tool_manager.get_tool_by_id_async(tool_id=tool_id, actor=actor) if tool is None: # return 404 error raise HTTPException(status_code=404, detail=f"Tool with id {tool_id} not found.") diff --git a/letta/services/tool_manager.py b/letta/services/tool_manager.py index eebff5ea..ad7a61e6 100644 --- a/letta/services/tool_manager.py +++ b/letta/services/tool_manager.py @@ -105,6 +105,15 @@ class ToolManager: # Convert the SQLAlchemy Tool object to PydanticTool return tool.to_pydantic() + @enforce_types + async def get_tool_by_id_async(self, tool_id: str, actor: PydanticUser) -> PydanticTool: + """Fetch a tool by its ID.""" + async with db_registry.async_session() as session: + # Retrieve tool by id using the Tool model's read method + tool = await ToolModel.read_async(db_session=session, identifier=tool_id, actor=actor) + # Convert the SQLAlchemy Tool object to PydanticTool + return tool.to_pydantic() + @enforce_types def get_tool_by_name(self, tool_name: str, actor: PydanticUser) -> Optional[PydanticTool]: """Retrieve a tool by its name and a user. We derive the organization from the user, and retrieve that tool."""