From 08955873876b6653d3620c50e0e4ee6a1802cffa Mon Sep 17 00:00:00 2001 From: cpacker Date: Mon, 2 Dec 2024 18:48:40 -0800 Subject: [PATCH] chore: comment out unused route for now --- letta/server/rest_api/routers/v1/tools.py | 25 ++++--- letta/server/server.py | 90 +++++++++++------------ 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.py index ad19c18a1f..d9e24473a1 100644 --- a/letta/server/rest_api/routers/v1/tools.py +++ b/letta/server/rest_api/routers/v1/tools.py @@ -6,7 +6,7 @@ from letta.errors import LettaToolCreateError from letta.orm.errors import UniqueConstraintViolationError from letta.schemas.letta_message import FunctionReturn -from letta.schemas.tool import Tool, ToolCreate, ToolRun, ToolRunFromSource, ToolUpdate +from letta.schemas.tool import Tool, ToolCreate, ToolRunFromSource, ToolUpdate from letta.server.rest_api.utils import get_letta_server from letta.server.server import SyncServer @@ -160,18 +160,19 @@ def add_base_tools( return server.tool_manager.add_base_tools(actor=actor) -@router.post("/{tool_id}/run", response_model=FunctionReturn, operation_id="run_tool") -def run_tool( - server: SyncServer = Depends(get_letta_server), - request: ToolRun = Body(...), - user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present -): - """ - Run an existing tool on provided arguments - """ - actor = server.get_user_or_default(user_id=user_id) +# NOTE: can re-enable if needed +# @router.post("/{tool_id}/run", response_model=FunctionReturn, operation_id="run_tool") +# def run_tool( +# server: SyncServer = Depends(get_letta_server), +# request: ToolRun = Body(...), +# user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present +# ): +# """ +# Run an existing tool on provided arguments +# """ +# actor = server.get_user_or_default(user_id=user_id) - return server.run_tool(tool_id=request.tool_id, tool_args=request.tool_args, user_id=actor.id) +# return server.run_tool(tool_id=request.tool_id, tool_args=request.tool_args, user_id=actor.id) @router.post("/run", response_model=FunctionReturn, operation_id="run_tool_from_source") diff --git a/letta/server/server.py b/letta/server/server.py index a5c45aa4ba..c7d5cadd1c 100644 --- a/letta/server/server.py +++ b/letta/server/server.py @@ -1760,51 +1760,51 @@ def get_agent_block_by_label(self, user_id: str, agent_id: str, label: str) -> B return block return None - def run_tool(self, tool_id: str, tool_args: str, user_id: str) -> FunctionReturn: - """Run a tool using the sandbox and return the result""" - - try: - tool_args_dict = json.loads(tool_args) - except json.JSONDecodeError: - raise ValueError("Invalid JSON string for tool_args") - - # Get the tool by ID - user = self.user_manager.get_user_by_id(user_id=user_id) - tool = self.tool_manager.get_tool_by_id(tool_id=tool_id, actor=user) - if tool.name is None: - raise ValueError(f"Tool with id {tool_id} does not have a name") - - # TODO eventually allow using agent state in tools - agent_state = None - - try: - sandbox_run_result = ToolExecutionSandbox(tool.name, tool_args_dict, user_id).run(agent_state=agent_state) - if sandbox_run_result is None: - raise ValueError(f"Tool with id {tool_id} returned execution with None") - function_response = str(sandbox_run_result.func_return) - - return FunctionReturn( - id="null", - function_call_id="null", - date=get_utc_time(), - status="success", - function_return=function_response, - ) - except Exception as e: - # same as agent.py - from letta.constants import MAX_ERROR_MESSAGE_CHAR_LIMIT - - error_msg = f"Error executing tool {tool.name}: {e}" - if len(error_msg) > MAX_ERROR_MESSAGE_CHAR_LIMIT: - error_msg = error_msg[:MAX_ERROR_MESSAGE_CHAR_LIMIT] - - return FunctionReturn( - id="null", - function_call_id="null", - date=get_utc_time(), - status="error", - function_return=error_msg, - ) + # def run_tool(self, tool_id: str, tool_args: str, user_id: str) -> FunctionReturn: + # """Run a tool using the sandbox and return the result""" + + # try: + # tool_args_dict = json.loads(tool_args) + # except json.JSONDecodeError: + # raise ValueError("Invalid JSON string for tool_args") + + # # Get the tool by ID + # user = self.user_manager.get_user_by_id(user_id=user_id) + # tool = self.tool_manager.get_tool_by_id(tool_id=tool_id, actor=user) + # if tool.name is None: + # raise ValueError(f"Tool with id {tool_id} does not have a name") + + # # TODO eventually allow using agent state in tools + # agent_state = None + + # try: + # sandbox_run_result = ToolExecutionSandbox(tool.name, tool_args_dict, user_id).run(agent_state=agent_state) + # if sandbox_run_result is None: + # raise ValueError(f"Tool with id {tool_id} returned execution with None") + # function_response = str(sandbox_run_result.func_return) + + # return FunctionReturn( + # id="null", + # function_call_id="null", + # date=get_utc_time(), + # status="success", + # function_return=function_response, + # ) + # except Exception as e: + # # same as agent.py + # from letta.constants import MAX_ERROR_MESSAGE_CHAR_LIMIT + + # error_msg = f"Error executing tool {tool.name}: {e}" + # if len(error_msg) > MAX_ERROR_MESSAGE_CHAR_LIMIT: + # error_msg = error_msg[:MAX_ERROR_MESSAGE_CHAR_LIMIT] + + # return FunctionReturn( + # id="null", + # function_call_id="null", + # date=get_utc_time(), + # status="error", + # function_return=error_msg, + # ) def run_tool_from_source( self,