Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: add validator for block id (#5514)
Kian Jonesad0f6b2be033
diff --git a/fern/openapi.json b/fern/openapi.jsonindex 2f11ed224..22bd3d953 100644--- a/fern/openapi.json+++ b/fern/openapi.json@@ -5567,8 +5567,14 @@"required": true,"schema": {"type": "string",+ "minLength": 42,+ "maxLength": 42,+ "pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",+ "description": "The ID of the block in the format 'block-<uuid4>'",+ "examples": ["block-123e4567-e89b-42d3-8456-426614174000"],"title": "Block Id"- }+ },+ "description": "The ID of the block in the format 'block-<uuid4>'"},{"name": "agent_id",@@ -5623,8 +5629,14 @@"required": true,"schema": {"type": "string",+ "minLength": 42,+ "maxLength": 42,+ "pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",+ "description": "The ID of the block in the format 'block-<uuid4>'",+ "examples": ["block-123e4567-e89b-42d3-8456-426614174000"],"title": "Block Id"- }+ },+ "description": "The ID of the block in the format 'block-<uuid4>'"},{"name": "agent_id",@@ -9448,8 +9460,14 @@"required": true,"schema": {"type": "string",+ "minLength": 42,+ "maxLength": 42,+ "pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",+ "description": "The ID of the block in the format 'block-<uuid4>'",+ "examples": ["block-123e4567-e89b-42d3-8456-426614174000"],"title": "Block Id"- }+ },+ "description": "The ID of the block in the format 'block-<uuid4>'"}],"requestBody": {@@ -9496,8 +9514,14 @@"required": true,"schema": {"type": "string",+ "minLength": 42,+ "maxLength": 42,+ "pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",+ "description": "The ID of the block in the format 'block-<uuid4>'",+ "examples": ["block-123e4567-e89b-42d3-8456-426614174000"],"title": "Block Id"- }+ },+ "description": "The ID of the block in the format 'block-<uuid4>'"}],"responses": {@@ -9532,8 +9556,14 @@"required": true,"schema": {"type": "string",+ "minLength": 42,+ "maxLength": 42,+ "pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",+ "description": "The ID of the block in the format 'block-<uuid4>'",+ "examples": ["block-123e4567-e89b-42d3-8456-426614174000"],"title": "Block Id"- }+ },+ "description": "The ID of the block in the format 'block-<uuid4>'"}],"responses": {@@ -9573,8 +9603,14 @@"required": true,"schema": {"type": "string",+ "minLength": 42,+ "maxLength": 42,+ "pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",+ "description": "The ID of the block in the format 'block-<uuid4>'",+ "examples": ["block-123e4567-e89b-42d3-8456-426614174000"],"title": "Block Id"- }+ },+ "description": "The ID of the block in the format 'block-<uuid4>'"},{"name": "before",diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.pyindex 87f92a9b9..f64172907 100644--- a/letta/server/rest_api/routers/v1/agents.py+++ b/letta/server/rest_api/routers/v1/agents.py@@ -4,7 +4,7 @@ import tracebackfrom datetime import datetime, timezonefrom typing import Annotated, Any, Dict, List, Literal, Optional, Union-from fastapi import APIRouter, Body, Depends, File, Form, Header, HTTPException, Path, Query, Request, UploadFile, status+from fastapi import APIRouter, Body, Depends, File, Form, Header, HTTPException, Query, Request, UploadFile, statusfrom fastapi.responses import JSONResponsefrom marshmallow import ValidationErrorfrom orjson import orjson@@ -939,7 +939,7 @@ async def modify_block(@router.patch("/{agent_id}/core-memory/blocks/attach/{block_id}", response_model=AgentState, operation_id="attach_core_memory_block")async def attach_block(- block_id: str,+ block_id: str = PATH_VALIDATORS["block"],agent_id: str = PATH_VALIDATORS["agent"],server: "SyncServer" = Depends(get_letta_server),headers: HeaderParams = Depends(get_headers),@@ -953,7 +953,7 @@ async def attach_block(@router.patch("/{agent_id}/core-memory/blocks/detach/{block_id}", response_model=AgentState, operation_id="detach_core_memory_block")async def detach_block(- block_id: str,+ block_id: str = PATH_VALIDATORS["block"],agent_id: str = PATH_VALIDATORS["agent"],server: "SyncServer" = Depends(get_letta_server),headers: HeaderParams = Depends(get_headers),diff --git a/letta/server/rest_api/routers/v1/blocks.py b/letta/server/rest_api/routers/v1/blocks.pyindex 6c8ac280d..3c75600a2 100644--- a/letta/server/rest_api/routers/v1/blocks.py+++ b/letta/server/rest_api/routers/v1/blocks.py@@ -7,6 +7,7 @@ from letta.schemas.agent import AgentStatefrom letta.schemas.block import Block, BlockUpdate, CreateBlockfrom letta.server.rest_api.dependencies import HeaderParams, get_headers, get_letta_serverfrom letta.server.server import SyncServer+from letta.validators import PATH_VALIDATORSif TYPE_CHECKING:pass@@ -128,7 +129,7 @@ async def create_block(@router.patch("/{block_id}", response_model=Block, operation_id="modify_block")async def modify_block(- block_id: str,+ block_id: str = PATH_VALIDATORS["block"],block_update: BlockUpdate = Body(...),server: SyncServer = Depends(get_letta_server),headers: HeaderParams = Depends(get_headers),@@ -139,7 +140,7 @@ async def modify_block(@router.delete("/{block_id}", operation_id="delete_block")async def delete_block(- block_id: str,+ block_id: str = PATH_VALIDATORS["block"],server: SyncServer = Depends(get_letta_server),headers: HeaderParams = Depends(get_headers),):@@ -149,7 +150,7 @@ async def delete_block(@router.get("/{block_id}", response_model=Block, operation_id="retrieve_block")async def retrieve_block(- block_id: str,+ block_id: str = PATH_VALIDATORS["block"],server: SyncServer = Depends(get_letta_server),headers: HeaderParams = Depends(get_headers),):@@ -162,7 +163,7 @@ async def retrieve_block(@router.get("/{block_id}/agents", response_model=List[AgentState], operation_id="list_agents_for_block")async def list_agents_for_block(- block_id: str,+ block_id: str = PATH_VALIDATORS["block"],before: Optional[str] = Query(None,description="Agent ID cursor for pagination. Returns agents that come before this agent ID in the specified sort order",