Files
letta-server/letta/services/per_agent_lock_manager.py
Shubham Naik 5a743d1dc4 Add 'apps/core/' from commit 'ea2a7395f4023f5b9fab03e6273db3b64a1181d5'
git-subtree-dir: apps/core
git-subtree-mainline: a8963e11e7a5a0059acbc849ce768e1eee80df61
git-subtree-split: ea2a7395f4023f5b9fab03e6273db3b64a1181d5
2024-12-22 20:31:22 -08:00

19 lines
546 B
Python

import threading
from collections import defaultdict
class PerAgentLockManager:
"""Manages per-agent locks."""
def __init__(self):
self.locks = defaultdict(threading.Lock)
def get_lock(self, agent_id: str) -> threading.Lock:
"""Retrieve the lock for a specific agent_id."""
return self.locks[agent_id]
def clear_lock(self, agent_id: str):
"""Optionally remove a lock if no longer needed (to prevent unbounded growth)."""
if agent_id in self.locks:
del self.locks[agent_id]