Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: fix patch approvals endpoint incorrectly using queyr params [LET-5792] (#5661)
cthomas2f30b789fd27
diff --git a/fern/openapi.json b/fern/openapi.jsonindex e1c31ec76..4e1158538 100644--- a/fern/openapi.json+++ b/fern/openapi.json@@ -4584,7 +4584,7 @@"patch": {"tags": ["agents"],"summary": "Modify Approval For Tool",- "description": "Attach a tool to an agent.",+ "description": "Modify the approval requirement for a tool attached to an agent.\n\nAccepts requires_approval via request body (preferred) or query parameter (deprecated).","operationId": "modify_approval_for_tool","parameters": [{@@ -4614,13 +4614,41 @@{"name": "requires_approval","in": "query",- "required": true,+ "required": false,"schema": {- "type": "boolean",+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ],+ "description": "Whether the tool requires approval before execution",+ "deprecated": true,"title": "Requires Approval"- }+ },+ "description": "Whether the tool requires approval before execution",+ "deprecated": true}],+ "requestBody": {+ "content": {+ "application/json": {+ "schema": {+ "anyOf": [+ {+ "$ref": "#/components/schemas/ModifyApprovalRequest"+ },+ {+ "type": "null"+ }+ ],+ "title": "Request"+ }+ }+ }+ },"responses": {"200": {"description": "Successful Response",@@ -26141,6 +26169,20 @@"type": "object","title": "ModalSandboxConfig"},+ "ModifyApprovalRequest": {+ "properties": {+ "requires_approval": {+ "type": "boolean",+ "title": "Requires Approval",+ "description": "Whether the tool requires approval before execution"+ }+ },+ "additionalProperties": false,+ "type": "object",+ "required": ["requires_approval"],+ "title": "ModifyApprovalRequest",+ "description": "Request body for modifying tool approval requirements."+ },"ModifyFeedbackRequest": {"properties": {"feedback": {diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.pyindex 7cf27a476..43f96c69d 100644--- a/letta/server/rest_api/routers/v1/agents.py+++ b/letta/server/rest_api/routers/v1/agents.py@@ -8,7 +8,7 @@ from fastapi import APIRouter, Body, Depends, File, Form, Header, HTTPException,from fastapi.responses import JSONResponsefrom marshmallow import ValidationErrorfrom orjson import orjson-from pydantic import BaseModel, Field+from pydantic import BaseModel, ConfigDict, Fieldfrom sqlalchemy.exc import IntegrityError, OperationalErrorfrom starlette.responses import Response, StreamingResponse@@ -456,21 +456,41 @@ async def detach_tool_from_agent(return await server.agent_manager.get_agent_by_id_async(agent_id=agent_id, actor=actor)+class ModifyApprovalRequest(BaseModel):+ """Request body for modifying tool approval requirements."""++ requires_approval: bool = Field(..., description="Whether the tool requires approval before execution")++ model_config = ConfigDict(extra="forbid")++@router.patch("/{agent_id}/tools/approval/{tool_name}", response_model=AgentState, operation_id="modify_approval_for_tool")async def modify_approval_for_tool(tool_name: str,- requires_approval: bool,agent_id: AgentId,+ requires_approval: bool | None = Query(None, description="Whether the tool requires approval before execution", deprecated=True),+ request: ModifyApprovalRequest | None = Body(None),server: "SyncServer" = Depends(get_letta_server),headers: HeaderParams = Depends(get_headers),):"""- Attach a tool to an agent.+ Modify the approval requirement for a tool attached to an agent.++ Accepts requires_approval via request body (preferred) or query parameter (deprecated)."""+ # Prefer body over query param for backwards compatibility+ if request is not None:+ approval_value = request.requires_approval+ elif requires_approval is not None:+ approval_value = requires_approval+ else:+ raise HTTPException(+ status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,+ detail="requires_approval must be provided either in request body or as query parameter",+ )+actor = await server.user_manager.get_actor_or_default_async(actor_id=headers.actor_id)- await server.agent_manager.modify_approvals_async(- agent_id=agent_id, tool_name=tool_name, requires_approval=requires_approval, actor=actor- )+ await server.agent_manager.modify_approvals_async(agent_id=agent_id, tool_name=tool_name, requires_approval=approval_value, actor=actor)# TODO: Unfortunately we need this to preserve our current API behaviorreturn await server.agent_manager.get_agent_by_id_async(agent_id=agent_id, actor=actor)