From 091e868dfc7da3279c117517f44eb84f2ec9da4d Mon Sep 17 00:00:00 2001 From: Lim-jooyoung Date: Wed, 25 Mar 2026 10:35:26 +0900 Subject: [PATCH] fix: update BetaAsyncAbstractMemoryTool docstring for async usage The docstring example was copy-pasted from the sync BetaAbstractMemoryTool without being updated. Following the example verbatim raises TypeError at instantiation time. Changes: - Use BetaAsyncAbstractMemoryTool as base class (not BetaAbstractMemoryTool) - Add async keyword to method definitions - Replace Anthropic() with AsyncAnthropic() - Wrap usage in async def main() / asyncio.run(main()) Fixes #1290 --- .../lib/tools/_beta_builtin_memory_tool.py | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/anthropic/lib/tools/_beta_builtin_memory_tool.py b/src/anthropic/lib/tools/_beta_builtin_memory_tool.py index c58d54a2..ea775732 100644 --- a/src/anthropic/lib/tools/_beta_builtin_memory_tool.py +++ b/src/anthropic/lib/tools/_beta_builtin_memory_tool.py @@ -157,34 +157,43 @@ def clear_all_memory(self) -> BetaFunctionToolResultType: class BetaAsyncAbstractMemoryTool(BetaAsyncBuiltinFunctionTool): - """Abstract base class for memory tool implementations. + """Abstract base class for async memory tool implementations. - This class provides the interface for implementing a custom memory backend for Claude. + This class provides the interface for implementing a custom async memory backend for Claude. Subclass this to create your own memory storage solution (e.g., database, cloud storage, encrypted files, etc.). Example usage: ```py - class MyMemoryTool(BetaAbstractMemoryTool): - def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType: + import asyncio + + from anthropic import AsyncAnthropic + + + class MyMemoryTool(BetaAsyncAbstractMemoryTool): + async def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType: ... return "view result" - def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType: + async def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType: ... return "created successfully" # ... implement other abstract methods - client = Anthropic() - memory_tool = MyMemoryTool() - message = client.beta.messages.run_tools( - model="claude-sonnet-4-5", - messages=[{"role": "user", "content": "Remember that I like coffee"}], - tools=[memory_tool], - ).until_done() + async def main() -> None: + client = AsyncAnthropic() + memory_tool = MyMemoryTool() + message = await client.beta.messages.run_tools( + model="claude-sonnet-4-5", + messages=[{"role": "user", "content": "Remember that I like coffee"}], + tools=[memory_tool], + ).until_done() + + + asyncio.run(main()) ``` """