BetaAsyncAbstractMemoryTool Class — anthropic-sdk-python Architecture
Architecture documentation for the BetaAsyncAbstractMemoryTool class in _beta_builtin_memory_tool.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD a0c776a7_63ce_9752_6068_14794f180e7d["BetaAsyncAbstractMemoryTool"] a076b136_74cf_8d21_4bad_0286750910e3["BetaAsyncBuiltinFunctionTool"] a0c776a7_63ce_9752_6068_14794f180e7d -->|extends| a076b136_74cf_8d21_4bad_0286750910e3 ca69ff78_767e_b6e6_385a_2992d126613b["_beta_builtin_memory_tool.py"] a0c776a7_63ce_9752_6068_14794f180e7d -->|defined in| ca69ff78_767e_b6e6_385a_2992d126613b 208424cf_6a85_5efe_3255_e1ed03057bb3["__init__()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| 208424cf_6a85_5efe_3255_e1ed03057bb3 86ab3662_ef11_c92a_de9a_3fb5c882ec44["to_dict()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| 86ab3662_ef11_c92a_de9a_3fb5c882ec44 cd7c56a6_976c_8d3b_3975_2c30ce839874["call()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| cd7c56a6_976c_8d3b_3975_2c30ce839874 19b9272d_d835_6305_8e21_55eb6c8b2f96["execute()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| 19b9272d_d835_6305_8e21_55eb6c8b2f96 f055f63a_c08c_67ec_6945_96f5aba95a16["view()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| f055f63a_c08c_67ec_6945_96f5aba95a16 0d62f96b_9675_c053_7ae8_5d58680e01d1["create()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| 0d62f96b_9675_c053_7ae8_5d58680e01d1 18e36d35_e1f1_40ea_0eeb_cfa2d4e034bf["str_replace()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| 18e36d35_e1f1_40ea_0eeb_cfa2d4e034bf 7398632d_dacc_dd76_2fbd_666fa697ea60["insert()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| 7398632d_dacc_dd76_2fbd_666fa697ea60 0284c100_26f4_84a6_8211_ff9fa6f593fc["delete()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| 0284c100_26f4_84a6_8211_ff9fa6f593fc 8954cd86_9574_d593_3805_ee2a036111b3["rename()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| 8954cd86_9574_d593_3805_ee2a036111b3 76b718ed_c4f0_55dc_ec46_843808a9ff25["clear_all_memory()"] a0c776a7_63ce_9752_6068_14794f180e7d -->|method| 76b718ed_c4f0_55dc_ec46_843808a9ff25
Relationship Graph
Source Code
src/anthropic/lib/tools/_beta_builtin_memory_tool.py lines 135–245
class BetaAsyncAbstractMemoryTool(BetaAsyncBuiltinFunctionTool):
"""Abstract base class for memory tool implementations.
This class provides the interface for implementing a custom 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:
...
return "view result"
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-3-5-sonnet-20241022",
messages=[{"role": "user", "content": "Remember that I like coffee"}],
tools=[memory_tool],
).until_done()
```
"""
def __init__(self, *, cache_control: BetaCacheControlEphemeralParam | None = None) -> None:
super().__init__()
self._cache_control = cache_control
@override
def to_dict(self) -> BetaMemoryTool20250818Param:
param: BetaMemoryTool20250818Param = {"type": "memory_20250818", "name": "memory"}
if self._cache_control is not None:
param["cache_control"] = self._cache_control
return param
@override
async def call(self, input: object) -> BetaFunctionToolResultType:
command = cast(
BetaMemoryTool20250818Command,
construct_type_unchecked(value=input, type_=cast(Any, BetaMemoryTool20250818Command)),
)
return await self.execute(command)
async def execute(self, command: BetaMemoryTool20250818Command) -> BetaFunctionToolResultType:
"""Execute a memory command and return the result.
This method dispatches to the appropriate handler method based on the
command type (view, create, str_replace, insert, delete, rename).
You typically don't need to override this method.
"""
if command.command == "view":
return await self.view(command)
elif command.command == "create":
return await self.create(command)
elif command.command == "str_replace":
return await self.str_replace(command)
elif command.command == "insert":
return await self.insert(command)
elif command.command == "delete":
return await self.delete(command)
elif command.command == "rename":
return await self.rename(command)
elif TYPE_CHECKING: # type: ignore[unreachable]
assert_never(command)
else:
raise NotImplementedError(f"Unknown command: {command.command}")
@abstractmethod
async def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
"""View the contents of a memory path."""
Domain
Extends
Source
Frequently Asked Questions
What is the BetaAsyncAbstractMemoryTool class?
BetaAsyncAbstractMemoryTool is a class in the anthropic-sdk-python codebase, defined in src/anthropic/lib/tools/_beta_builtin_memory_tool.py.
Where is BetaAsyncAbstractMemoryTool defined?
BetaAsyncAbstractMemoryTool is defined in src/anthropic/lib/tools/_beta_builtin_memory_tool.py at line 135.
What does BetaAsyncAbstractMemoryTool extend?
BetaAsyncAbstractMemoryTool extends BetaAsyncBuiltinFunctionTool.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free