Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: filter messages search endpoint by agent id [LET-6229] (#6246)
Christina Tong04611b981cce
diff --git a/fern/openapi.json b/fern/openapi.jsonindex 99cf0c3e8..55c2267e0 100644--- a/fern/openapi.json+++ b/fern/openapi.json@@ -30385,6 +30385,18 @@"title": "Roles","description": "Filter messages by role"},+ "agent_id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Agent Id",+ "description": "Filter messages by agent ID"+ },"project_id": {"anyOf": [{diff --git a/letta/helpers/tpuf_client.py b/letta/helpers/tpuf_client.pyindex 9a9cc31a8..f19a3aeb3 100644--- a/letta/helpers/tpuf_client.py+++ b/letta/helpers/tpuf_client.py@@ -758,6 +758,7 @@ class TurbopufferClient:search_mode: str = "hybrid", # "vector", "fts", "hybrid"top_k: int = 10,roles: Optional[List[MessageRole]] = None,+ agent_id: Optional[str] = None,project_id: Optional[str] = None,template_id: Optional[str] = None,vector_weight: float = 0.5,@@ -774,6 +775,7 @@ class TurbopufferClient:search_mode: Search mode - "vector", "fts", or "hybrid" (default: "hybrid")top_k: Number of results to returnroles: Optional list of message roles to filter by+ agent_id: Optional agent ID to filter messages byproject_id: Optional project ID to filter messages bytemplate_id: Optional template ID to filter messages byvector_weight: Weight for vector search results in hybrid mode (default: 0.5)@@ -806,6 +808,10 @@ class TurbopufferClient:else:all_filters.append(("role", "In", role_values))+ # agent filter+ if agent_id:+ all_filters.append(("agent_id", "Eq", agent_id))+# project filterif project_id:all_filters.append(("project_id", "Eq", project_id))diff --git a/letta/schemas/message.py b/letta/schemas/message.pyindex 200bff70f..75f423d8a 100644--- a/letta/schemas/message.py+++ b/letta/schemas/message.py@@ -2158,6 +2158,7 @@ class MessageSearchRequest(BaseModel):query: Optional[str] = Field(None, description="Text query for full-text search")search_mode: Literal["vector", "fts", "hybrid"] = Field("hybrid", description="Search mode to use")roles: Optional[List[MessageRole]] = Field(None, description="Filter messages by role")+ agent_id: Optional[str] = Field(None, description="Filter messages by agent ID")project_id: Optional[str] = Field(None, description="Filter messages by project ID")template_id: Optional[str] = Field(None, description="Filter messages by template ID")limit: int = Field(50, description="Maximum number of results to return", ge=1, le=100)diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.pyindex 5ad22afd3..1edb34519 100644--- a/letta/server/rest_api/routers/v1/agents.py+++ b/letta/server/rest_api/routers/v1/agents.py@@ -1643,6 +1643,7 @@ async def search_messages(query_text=request.query,search_mode=request.search_mode,roles=request.roles,+ agent_id=request.agent_id,project_id=request.project_id,template_id=request.template_id,limit=request.limit,diff --git a/letta/services/message_manager.py b/letta/services/message_manager.pyindex 113fb7a68..3da3f249a 100644--- a/letta/services/message_manager.py+++ b/letta/services/message_manager.py@@ -1190,6 +1190,7 @@ class MessageManager:query_text: Optional[str] = None,search_mode: str = "hybrid",roles: Optional[List[MessageRole]] = None,+ agent_id: Optional[str] = None,project_id: Optional[str] = None,template_id: Optional[str] = None,limit: int = 50,@@ -1204,6 +1205,7 @@ class MessageManager:query_text: Text query for full-text searchsearch_mode: "vector", "fts", or "hybrid" (default: "hybrid")roles: Optional list of message roles to filter by+ agent_id: Optional agent ID to filter messages byproject_id: Optional project ID to filter messages bytemplate_id: Optional template ID to filter messages bylimit: Maximum number of results to return@@ -1232,6 +1234,7 @@ class MessageManager:search_mode=search_mode,top_k=limit,roles=roles,+ agent_id=agent_id,project_id=project_id,template_id=template_id,start_date=start_date,