BetaAbstractMemoryTool Class — anthropic-sdk-python Architecture
Architecture documentation for the BetaAbstractMemoryTool class in _beta_builtin_memory_tool.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD d2acad16_3d69_9ffc_b385_3f353b4288f2["BetaAbstractMemoryTool"] 6f841778_0364_167a_4fa4_ad1b5aa754ea["BetaBuiltinFunctionTool"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|extends| 6f841778_0364_167a_4fa4_ad1b5aa754ea ca69ff78_767e_b6e6_385a_2992d126613b["_beta_builtin_memory_tool.py"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|defined in| ca69ff78_767e_b6e6_385a_2992d126613b 25d9584d_d03f_f628_f991_1973cd75ea0f["__init__()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| 25d9584d_d03f_f628_f991_1973cd75ea0f 04df7c29_dc8a_3bf6_2706_4e4ef3292a71["to_dict()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| 04df7c29_dc8a_3bf6_2706_4e4ef3292a71 c1795f4c_e68a_1e1f_d9fb_ea2c6aae248d["call()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| c1795f4c_e68a_1e1f_d9fb_ea2c6aae248d 6f0540a3_65b1_70b4_ce28_d4ad7f2afd09["execute()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| 6f0540a3_65b1_70b4_ce28_d4ad7f2afd09 819ec211_5934_b63a_723a_ba1f1eba16cb["view()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| 819ec211_5934_b63a_723a_ba1f1eba16cb 0ece2516_b8ca_11b1_03fd_264c81bbd81d["create()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| 0ece2516_b8ca_11b1_03fd_264c81bbd81d a877ff69_249a_dde6_6779_91863320f091["str_replace()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| a877ff69_249a_dde6_6779_91863320f091 a8e570a9_f267_d6dd_f9fe_8f2094e09854["insert()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| a8e570a9_f267_d6dd_f9fe_8f2094e09854 d4a60127_6116_899b_7836_1244f71efe18["delete()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| d4a60127_6116_899b_7836_1244f71efe18 757cd931_8743_ce72_96e5_a33e8d974d1b["rename()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| 757cd931_8743_ce72_96e5_a33e8d974d1b b1b5cc7e_a9e3_5be0_d6e0_77754fa5e6c7["clear_all_memory()"] d2acad16_3d69_9ffc_b385_3f353b4288f2 -->|method| b1b5cc7e_a9e3_5be0_d6e0_77754fa5e6c7
Relationship Graph
Source Code
src/anthropic/lib/tools/_beta_builtin_memory_tool.py lines 22–132
class BetaAbstractMemoryTool(BetaBuiltinFunctionTool):
"""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-sonnet-4-5",
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
def call(self, input: object) -> BetaFunctionToolResultType:
command = cast(
BetaMemoryTool20250818Command,
construct_type_unchecked(value=input, type_=cast(Any, BetaMemoryTool20250818Command)),
)
return self.execute(command)
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 self.view(command)
elif command.command == "create":
return self.create(command)
elif command.command == "str_replace":
return self.str_replace(command)
elif command.command == "insert":
return self.insert(command)
elif command.command == "delete":
return self.delete(command)
elif command.command == "rename":
return self.rename(command)
elif TYPE_CHECKING: # type: ignore[unreachable]
assert_never(command)
else:
raise NotImplementedError(f"Unknown command: {command.command}")
@abstractmethod
def view(self, command: BetaMemoryTool20250818ViewCommand) -> BetaFunctionToolResultType:
"""View the contents of a memory path."""
Domain
Extends
Source
Frequently Asked Questions
What is the BetaAbstractMemoryTool class?
BetaAbstractMemoryTool is a class in the anthropic-sdk-python codebase, defined in src/anthropic/lib/tools/_beta_builtin_memory_tool.py.
Where is BetaAbstractMemoryTool defined?
BetaAbstractMemoryTool is defined in src/anthropic/lib/tools/_beta_builtin_memory_tool.py at line 22.
What does BetaAbstractMemoryTool extend?
BetaAbstractMemoryTool extends BetaBuiltinFunctionTool.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free