Files
letta-server/letta/services/per_agent_lock_manager.py
Kian Jones b8e9a80d93 merge this (#4759)
* wait I forgot to comit locally

* cp the entire core directory and then rm the .git subdir
2025-09-17 15:47:40 -07:00

23 lines
627 B
Python

import threading
from collections import defaultdict
from letta.otel.tracing import trace_method
class PerAgentLockManager:
"""Manages per-agent locks."""
def __init__(self):
self.locks = defaultdict(threading.Lock)
@trace_method
def get_lock(self, agent_id: str) -> threading.Lock:
"""Retrieve the lock for a specific agent_id."""
return self.locks[agent_id]
@trace_method
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]