{"record":{"id":"3289d2f363f8a2d2","repo":"agentscope-ai/agentscope","slug":"mem0middleware-requires-an-async-mem0-client-me","errorCode":null,"errorMessage":"\"Mem0Middleware requires an async mem0 client (`mem0.AsyncMemory` or `mem0.AsyncMemoryClient`). The synchronous `Memory` / `MemoryClient` are not supported.\"","messagePattern":"\"Mem0Middleware requires an async mem0 client \\(`mem0\\.AsyncMemory` or `mem0\\.AsyncMemoryClient`\\)\\. The synchronous `Memory` / `MemoryClient` are not supported\\.\"","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py","lineNumber":485,"sourceCode":"                    \"`mem0_config` is not given.\",\n                )\n\n            from mem0 import AsyncMemory\n\n            from ._agentscope_adapter import build_mem0_config\n\n            client = AsyncMemory(\n                config=build_mem0_config(\n                    chat_model=chat_model,\n                    embedding_model=embedding_model,\n                    mem0_config=mem0_config,\n                ),\n            )\n\n        if not _looks_async(\n            getattr(client, \"search\", None),\n        ) or not _looks_async(getattr(client, \"add\", None)):\n            raise TypeError(\n                \"Mem0Middleware requires an async mem0 client \"\n                \"(`mem0.AsyncMemory` or `mem0.AsyncMemoryClient`). \"\n                \"The synchronous `Memory` / `MemoryClient` are not \"\n                \"supported.\",\n            )\n        return client\n\n    # ==================================================================\n    # mem0 client adapters (OSS + Platform share this call shape)\n    # ==================================================================\n    async def _async_search(\n        self,\n        query: str,\n        *,\n        user_id: str,\n        agent_id: str | None,\n        top_k: int | None = None,\n    ) -> list[str]:","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py#L467-L503","documentation":"Mem0Middleware only awaits client.search/add, so the client must be async. _looks_async inspects the callables and a synchronous mem0.Memory or MemoryClient fails the check with this explanatory TypeError.","triggerScenarios":"Passing client=Memory.from_config(...) (sync) or MemoryClient(...) instead of AsyncMemory/AsyncMemoryClient.","commonSituations":"Copying sync mem0 quickstart code into an agentscope pipeline; mem0 version where the sync/async split moved classes.","solutions":["Use mem0.AsyncMemory.from_config(...) or AsyncMemoryClient","Keep the mem0_config/models path, which constructs AsyncMemory internally","Verify with inspect.iscoroutinefunction(client.search) before passing"],"exampleFix":"// before\nfrom mem0 import Memory\nmw = Mem0Middleware(user_id='u1', client=Memory.from_config(cfg))\n// after\nfrom mem0 import AsyncMemory\nmw = Mem0Middleware(user_id='u1', client=AsyncMemory.from_config(cfg))","handlingStrategy":"type-guard","validationCode":"import inspect\nassert inspect.iscoroutinefunction(getattr(client, 'search', None)), 'use AsyncMemory'\nassert inspect.iscoroutinefunction(getattr(client, 'add', None)), 'use AsyncMemory'","typeGuard":"import inspect\ndef is_async_memory_client(c) -> bool:\n    return inspect.iscoroutinefunction(getattr(c, 'search', None)) and inspect.iscoroutinefunction(getattr(c, 'add', None))","tryCatchPattern":"try:\n    mw = Mem0Middleware(user_id='u1', client=client)\nexcept TypeError as e:\n    if 'async mem0 client' in str(e):\n        from mem0 import AsyncMemory\n        mw = Mem0Middleware(user_id='u1', client=AsyncMemory.from_config(cfg))\n    else:\n        raise","preventionTips":["Always construct mem0 clients from the Async* classes in async apps","Run the iscoroutinefunction guard at wiring time"],"tags":["mem0","async","type-error","client"],"backgroundTag":"sync-client-in-async-context","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}