AsyncMemory gives you a non-blocking interface to Mem0’s storage layer so Python applications can add, search, and manage memories directly from async code. Use it when you embed Mem0 inside FastAPI services, background workers, or any workflow that relies on asyncio.
You’ll use this when…
- Your agent already runs in an async framework and you need memory calls to await cleanly.
- You want to embed Mem0’s storage locally without sending requests through the synchronous client.
- You plan to mix memory operations with other async APIs (OpenAI, HTTP calls, databases).
Working in TypeScript? The OSS
Memory class in the Node SDK (mem0ai/oss) is also fully async: every method returns a Promise and must be awaited. Python’s AsyncMemory serves the same purpose within Python async frameworks like FastAPI. Both runtimes support awaited memory operations; choose the SDK that matches your language.Feature anatomy
- Direct storage access:
AsyncMemorytalks to the same backends as the synchronous client but keeps everything in-process for lower latency. - Method parity: Each memory operation (
add,search,get_all,delete, etc.) mirrors the synchronous API, letting you reuse payload shapes. - Concurrent execution: Non-blocking I/O lets you schedule multiple memory tasks with
asyncio.gather. - Scoped organization: Continue using
user_id,agent_id, andrun_idto separate memories across sessions and agents.
Async method parity
Async method parity
Configure it
Initialize the client
Run
await memory.search(...) once right after initialization. If it returns memories without errors, your configuration works.Manage lifecycle and concurrency
When concurrency works correctly, successful tasks return memory IDs while failures surface as exceptions in the
results list.Add resilience with retries
See it in action
Core operations
Confirm each call returns the same response fields as the synchronous client (IDs,
results, or confirmation objects). Missing keys usually mean the coroutine wasn’t awaited.delete_all requires at least one of user_id, agent_id, or run_id. Provide all three to narrow deletion to a single session.Scoped organization
Blend with other async APIs
When everything is wired correctly, the OpenAI response should incorporate recent memories and the follow-up
add call should persist the new assistant turn.Handle errors gracefully
Serve through FastAPI
Instrument logging
Logged durations give you the baseline needed to spot regressions once AsyncMemory is in production.
Verify the feature is working
- Run a quick add/search cycle and confirm the returned memory content matches your input.
- Inspect application logs to ensure async tasks complete without blocking the event loop.
- In FastAPI or other frameworks, hit health endpoints to verify the shared client handles concurrent requests.
- Monitor retry counters: unexpected spikes indicate configuration or connectivity issues.
Best practices
- Keep operations awaited: Forgetting
awaitis the fastest way to miss writes: lint for it or add helper wrappers. - Scope deletions carefully: Always supply
user_id,agent_id, orrun_idto avoid purging too much data. - Batch writes thoughtfully: Use
asyncio.gatherfor throughput but cap concurrency based on backend capacity. - Log errors with context: Capture user and agent scopes to triage failures quickly.
- Reuse clients: Instantiate
AsyncMemoryonce per worker to avoid repeated backend handshakes.
Troubleshooting
Master Memory Operations
Review how add, search, update, and delete behave across synchronous and async clients.
Connect Async Agents
Follow a full workflow that mixes AsyncMemory with OpenAI tool-call automation.