Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: patch bug in pydantic request model for `/v1/tools/run` (#2152)
Charles Packera7e2c8cff780
diff --git a/letta/schemas/tool.py b/letta/schemas/tool.pyindex ff39ed7c1..ba8445518 100644--- a/letta/schemas/tool.py+++ b/letta/schemas/tool.py@@ -209,7 +209,7 @@ class ToolRun(LettaBase):class ToolRunFromSource(LettaBase):+ source_code: str = Field(..., description="The source code of the function.")args: str = Field(..., description="The arguments to pass to the tool (as stringified JSON).")- name: Optional[str] = Field(..., description="The name of the tool to run.")- source_code: str = Field(None, description="The source code of the function.")+ name: Optional[str] = Field(None, description="The name of the tool to run.")source_type: Optional[str] = Field(None, description="The type of the source code.")diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.pyindex d9e24473a..c9b60f785 100644--- a/letta/server/rest_api/routers/v1/tools.py+++ b/letta/server/rest_api/routers/v1/tools.py@@ -186,13 +186,27 @@ def run_tool_from_source("""actor = server.get_user_or_default(user_id=user_id)- return server.run_tool_from_source(- tool_source=request.source_code,- tool_source_type=request.source_type,- tool_args=request.args,- tool_name=request.name,- user_id=actor.id,- )+ try:+ return server.run_tool_from_source(+ tool_source=request.source_code,+ tool_source_type=request.source_type,+ tool_args=request.args,+ tool_name=request.name,+ user_id=actor.id,+ )+ except LettaToolCreateError as e:+ # HTTP 400 == Bad Request+ print(f"Error occurred during tool creation: {e}")+ # print the full stack trace+ import traceback++ print(traceback.format_exc())+ raise HTTPException(status_code=400, detail=str(e))++ except Exception as e:+ # Catch other unexpected errors and raise an internal server error+ print(f"Unexpected error occurred: {e}")+ raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")# Specific routes for Composio