From fd686452ac89355803f1a6189ef27cfa2c9e67c5 Mon Sep 17 00:00:00 2001 From: Abdelhadi Salmaoui Date: Sat, 28 Mar 2026 01:47:57 +0100 Subject: [PATCH] fix(docs): correct BetaAsyncAbstractMemoryTool docstring for async usage The docstring example for BetaAsyncAbstractMemoryTool was copy-pasted from the synchronous BetaAbstractMemoryTool class without being updated for async usage, causing TypeError when following the example verbatim. Changes: - Use BetaAsyncAbstractMemoryTool as base class (was BetaAbstractMemoryTool) - Use async def for method definitions (was sync def) - Use AsyncAnthropic client (was Anthropic) - Add await to the run_tools call Fixes #1290 Co-Authored-By: Claude Opus 4.6 --- .../lib/tools/_beta_builtin_memory_tool.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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..7a4e3d00 100644 --- a/src/anthropic/lib/tools/_beta_builtin_memory_tool.py +++ b/src/anthropic/lib/tools/_beta_builtin_memory_tool.py @@ -157,30 +157,31 @@ 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 memory backend for Claude + with async/await support. 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: + 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() + client = AsyncAnthropic() memory_tool = MyMemoryTool() - message = client.beta.messages.run_tools( + message = await client.beta.messages.run_tools( model="claude-sonnet-4-5", messages=[{"role": "user", "content": "Remember that I like coffee"}], tools=[memory_tool],