feat(memory): Refactor memory API to support async task-based and sync operations
- Rename endpoints from write_api_service/read_api_service to write/read for clarity - Add async task-based endpoints (/write, /read) that dispatch to Celery with fair locking - Add task status polling endpoints (/write/status, /read/status) to check async operation results - Add synchronous endpoints (/write/sync, /read/sync) for blocking operations with direct results - Introduce TaskStatusResponse schema for task status polling responses - Add MemoryWriteSyncResponse and MemoryReadSyncResponse schemas for sync operations - Implement write_memory_sync and read_memory_sync methods in MemoryAPIService - Remove await from async service calls in task-based endpoints (now handled by Celery) - Add Query parameter import for task_id in status endpoints - Update docstrings to clarify async vs sync behavior and task polling workflow - Integrate task_service for retrieving Celery task results
This commit is contained in:
@@ -110,6 +110,30 @@ class MemoryReadRequest(BaseModel):
|
||||
class MemoryWriteResponse(BaseModel):
|
||||
"""Response schema for memory write operation.
|
||||
|
||||
Attributes:
|
||||
task_id: Celery task ID for status polling
|
||||
status: Initial task status (PENDING)
|
||||
end_user_id: End user ID the write was submitted for
|
||||
"""
|
||||
task_id: str = Field(..., description="Celery task ID for polling")
|
||||
status: str = Field(..., description="Task status: PENDING")
|
||||
end_user_id: str = Field(..., description="End user ID")
|
||||
|
||||
|
||||
class TaskStatusResponse(BaseModel):
|
||||
"""Response schema for task status check.
|
||||
|
||||
Attributes:
|
||||
status: Task status (PENDING, STARTED, SUCCESS, FAILURE, SKIPPED)
|
||||
result: Task result data (available when status is SUCCESS or FAILURE)
|
||||
"""
|
||||
status: str = Field(..., description="Task status")
|
||||
result: Optional[Dict[str, Any]] = Field(None, description="Task result when completed")
|
||||
|
||||
|
||||
class MemoryWriteSyncResponse(BaseModel):
|
||||
"""Response schema for synchronous memory write.
|
||||
|
||||
Attributes:
|
||||
status: Operation status (success or failed)
|
||||
end_user_id: End user ID that was written to
|
||||
@@ -118,8 +142,8 @@ class MemoryWriteResponse(BaseModel):
|
||||
end_user_id: str = Field(..., description="End user ID")
|
||||
|
||||
|
||||
class MemoryReadResponse(BaseModel):
|
||||
"""Response schema for memory read operation.
|
||||
class MemoryReadSyncResponse(BaseModel):
|
||||
"""Response schema for synchronous memory read.
|
||||
|
||||
Attributes:
|
||||
answer: Generated answer from memory retrieval
|
||||
@@ -128,12 +152,25 @@ class MemoryReadResponse(BaseModel):
|
||||
"""
|
||||
answer: str = Field(..., description="Generated answer")
|
||||
intermediate_outputs: List[Dict[str, Any]] = Field(
|
||||
default_factory=list,
|
||||
default_factory=list,
|
||||
description="Intermediate retrieval outputs"
|
||||
)
|
||||
end_user_id: str = Field(..., description="End user ID")
|
||||
|
||||
|
||||
class MemoryReadResponse(BaseModel):
|
||||
"""Response schema for memory read operation.
|
||||
|
||||
Attributes:
|
||||
task_id: Celery task ID for status polling
|
||||
status: Initial task status (PENDING)
|
||||
end_user_id: End user ID the read was submitted for
|
||||
"""
|
||||
task_id: str = Field(..., description="Celery task ID for polling")
|
||||
status: str = Field(..., description="Task status: PENDING")
|
||||
end_user_id: str = Field(..., description="End user ID")
|
||||
|
||||
|
||||
class CreateEndUserRequest(BaseModel):
|
||||
"""Request schema for creating an end user.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user