@@ -188,7 +188,7 @@ async def list_sessions(
188188 Get a list of session IDs, with optional pagination.
189189
190190 Args:
191- options: Query parameters (page, size , namespace)
191+ options: Query parameters (limit, offset , namespace, user_id )
192192
193193 Returns:
194194 List of session IDs
@@ -200,6 +200,7 @@ async def list_sessions(
200200 limit = options .limit ,
201201 offset = options .offset ,
202202 namespace = options .namespace ,
203+ user_id = options .user_id ,
203204 )
204205
205206 return SessionListResponse (
@@ -211,8 +212,8 @@ async def list_sessions(
211212@router .get ("/v1/working-memory/{session_id}" , response_model = WorkingMemoryResponse )
212213async def get_working_memory (
213214 session_id : str ,
215+ user_id : str | None = None ,
214216 namespace : str | None = None ,
215- window_size : int = settings .window_size , # Deprecated: kept for backward compatibility
216217 model_name : ModelNameLiteral | None = None ,
217218 context_window_max : int | None = None ,
218219 current_user : UserInfo = Depends (get_current_user ),
@@ -225,8 +226,8 @@ async def get_working_memory(
225226
226227 Args:
227228 session_id: The session ID
229+ user_id: The user ID to retrieve working memory for
228230 namespace: The namespace to use for the session
229- window_size: DEPRECATED - The number of messages to include (kept for backward compatibility)
230231 model_name: The client's LLM model name (will determine context window size if provided)
231232 context_window_max: Direct specification of the context window max tokens (overrides model_name)
232233
@@ -240,6 +241,7 @@ async def get_working_memory(
240241 session_id = session_id ,
241242 namespace = namespace ,
242243 redis_client = redis ,
244+ user_id = user_id ,
243245 )
244246
245247 if not working_mem :
@@ -249,6 +251,7 @@ async def get_working_memory(
249251 memories = [],
250252 session_id = session_id ,
251253 namespace = namespace ,
254+ user_id = user_id ,
252255 )
253256
254257 # Apply token-based truncation if we have messages and model info
@@ -266,17 +269,14 @@ async def get_working_memory(
266269 break
267270 working_mem .messages = truncated_messages
268271
269- # Fallback to message-count truncation for backward compatibility
270- elif len (working_mem .messages ) > window_size :
271- working_mem .messages = working_mem .messages [- window_size :]
272-
273272 return working_mem
274273
275274
276275@router .put ("/v1/working-memory/{session_id}" , response_model = WorkingMemoryResponse )
277276async def put_working_memory (
278277 session_id : str ,
279278 memory : WorkingMemory ,
279+ user_id : str | None = None ,
280280 model_name : ModelNameLiteral | None = None ,
281281 context_window_max : int | None = None ,
282282 background_tasks = Depends (get_background_tasks ),
@@ -291,6 +291,7 @@ async def put_working_memory(
291291 Args:
292292 session_id: The session ID
293293 memory: Working memory to save
294+ user_id: Optional user ID for the session (overrides user_id in memory object)
294295 model_name: The client's LLM model name for context window determination
295296 context_window_max: Direct specification of context window max tokens
296297 background_tasks: DocketBackgroundTasks instance (injected automatically)
@@ -303,6 +304,10 @@ async def put_working_memory(
303304 # Ensure session_id matches
304305 memory .session_id = session_id
305306
307+ # Override user_id if provided as query parameter
308+ if user_id is not None :
309+ memory .user_id = user_id
310+
306311 # Validate that all structured memories have id (if any)
307312 for mem in memory .memories :
308313 if not mem .id :
@@ -359,6 +364,7 @@ async def put_working_memory(
359364@router .delete ("/v1/working-memory/{session_id}" , response_model = AckResponse )
360365async def delete_working_memory (
361366 session_id : str ,
367+ user_id : str | None = None ,
362368 namespace : str | None = None ,
363369 current_user : UserInfo = Depends (get_current_user ),
364370):
@@ -369,6 +375,7 @@ async def delete_working_memory(
369375
370376 Args:
371377 session_id: The session ID
378+ user_id: Optional user ID for the session
372379 namespace: Optional namespace for the session
373380
374381 Returns:
@@ -379,6 +386,7 @@ async def delete_working_memory(
379386 # Delete unified working memory
380387 await working_memory .delete_working_memory (
381388 session_id = session_id ,
389+ user_id = user_id ,
382390 namespace = namespace ,
383391 redis_client = redis ,
384392 )
@@ -558,6 +566,7 @@ async def memory_prompt(
558566 working_mem = await working_memory .get_working_memory (
559567 session_id = params .session .session_id ,
560568 namespace = params .session .namespace ,
569+ user_id = params .session .user_id ,
561570 redis_client = redis ,
562571 )
563572
0 commit comments