You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current InMemorySaver class does not have a delete_thread(thread_id) method, which deletes all data related to a particular thread_id and allows the same thread_id to be reused without restarting the server.
I have implemented this method as follows:
classCustomInMemorySaver(InMemorySaver):
""" Custom InMemorySaver that allows deleting all data associated with a thread_id. """defdelete_thread(self, thread_id: str) ->None:
""" Deletes all checkpoints, writes, and blobs associated with the given thread_id. Args: thread_id (str): The ID of the thread to delete. """# Delete from storageifthread_idinself.storage:
delself.storage[thread_id]
logger.info(f"Deleted checkpoints for thread_id: {thread_id}")
# Delete from writeswrites_keys_to_delete= [
keyforkeyinself.writesifkey[0] ==thread_id
]
forkeyinwrites_keys_to_delete:
delself.writes[key]
ifwrites_keys_to_delete:
logger.info(f"Deleted writes for thread_id: {thread_id}")
# Delete from blobsblobs_keys_to_delete= [keyforkeyinself.blobsifkey[0] ==thread_id]
forkeyinblobs_keys_to_delete:
delself.blobs[key]
ifblobs_keys_to_delete:
logger.info(f"Deleted blobs for thread_id: {thread_id}")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
delete_thread
Method forInMemorySaver
The current
InMemorySaver
class does not have adelete_thread(thread_id)
method, which deletes all data related to a particularthread_id
and allows the samethread_id
to be reused without restarting the server.I have implemented this method as follows:
I would like to contribute this to the main repo.
Beta Was this translation helpful? Give feedback.
All reactions