AsyncMemory
TheAsyncMemory class is a direct asynchronous interface to Zentry’s in-process memory operations. Unlike the memory, which interacts with an API, AsyncMemory works directly with the underlying storage systems. This makes it ideal for applications where you want to embed Zentry directly into your codebase.
Initialization
To useAsyncMemory, import it from the zentry.memory module:
Python
Key Features
- Non-blocking Operations - All memory operations use
asyncioto avoid blocking the event loop - Concurrent Processing - Parallel execution of vector store and graph operations
- Efficient Resource Utilization - Better handling of I/O bound operations
- Compatible with Async Frameworks - Seamless integration with FastAPI, aiohttp, and other async frameworks
Methods
All methods inAsyncMemory have the same parameters as the synchronous Memory class but are designed to be used with async/await.
Create memories
Add a new memory asynchronously:Python
Retrieve memories
Retrieve memories related to a query:Python
List memories
List all memories for auser_id, agent_id, or run_id:
Python
Get specific memory
Retrieve a specific memory by its ID:Python
Update memory
Update an existing memory by ID:Python
Delete memory
Delete a specific memory by ID:Python
Delete all memories
Delete all memories for a specific user, agent, or run:Python
Memory History
Get the history of changes for a specific memory:Python
Example: Concurrent Usage with Other APIs
AsyncMemory can be effectively combined with other async operations. Here’s an example showing how to use it alongside OpenAI API calls in separate threads:
Python