Skip to content

Commit fd68645

Browse files
abdelhadi703claude
andcommitted
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 <noreply@anthropic.com>
1 parent d7c0974 commit fd68645

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/anthropic/lib/tools/_beta_builtin_memory_tool.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,31 @@ def clear_all_memory(self) -> BetaFunctionToolResultType:
157157

158158

159159
class BetaAsyncAbstractMemoryTool(BetaAsyncBuiltinFunctionTool):
160-
"""Abstract base class for memory tool implementations.
160+
"""Abstract base class for async memory tool implementations.
161161
162-
This class provides the interface for implementing a custom memory backend for Claude.
162+
This class provides the interface for implementing a custom memory backend for Claude
163+
with async/await support.
163164
164165
Subclass this to create your own memory storage solution (e.g., database, cloud storage, encrypted files, etc.).
165166
166167
Example usage:
167168
168169
```py
169-
class MyMemoryTool(BetaAbstractMemoryTool):
170-
def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
170+
class MyMemoryTool(BetaAsyncAbstractMemoryTool):
171+
async def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
171172
...
172173
return "view result"
173174
174-
def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType:
175+
async def create(self, command: BetaMemoryTool20250818CreateCommand) -> BetaFunctionToolResultType:
175176
...
176177
return "created successfully"
177178
178179
# ... implement other abstract methods
179180
180181
181-
client = Anthropic()
182+
client = AsyncAnthropic()
182183
memory_tool = MyMemoryTool()
183-
message = client.beta.messages.run_tools(
184+
message = await client.beta.messages.run_tools(
184185
model="claude-sonnet-4-5",
185186
messages=[{"role": "user", "content": "Remember that I like coffee"}],
186187
tools=[memory_tool],

0 commit comments

Comments
 (0)