basic.py — anthropic-sdk-python Source File
Architecture documentation for basic.py, a python file in the anthropic-sdk-python codebase. 10 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR ffd4efa5_68eb_4c4c_51fe_26bc27478a2b["basic.py"] fc8f16cf_4f31_976d_68d3_fa49ea4ffdd0["time"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> fc8f16cf_4f31_976d_68d3_fa49ea4ffdd0 6e5d3c1a_548e_ed3b_b036_648fba2a0937["shutil"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> 6e5d3c1a_548e_ed3b_b036_648fba2a0937 c1bd74b2_608d_ae8b_a66d_adfbd1920c15["threading"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> c1bd74b2_608d_ae8b_a66d_adfbd1920c15 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 525f4270_cbfe_512c_fbe4_e6566e0cdf13["pathlib"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> 525f4270_cbfe_512c_fbe4_e6566e0cdf13 37c05070_ca59_d596_7250_de9d1939227f["typing_extensions"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> 37c05070_ca59_d596_7250_de9d1939227f 21de8837_7dae_989e_fdbb_1415c0770d90["pydantic"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> 21de8837_7dae_989e_fdbb_1415c0770d90 d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> d10c5377_2939_0f0b_cc44_8759393f2853 401f8a6c_a177_4dcd_662b_ade2f5d17081["anthropic.lib.tools"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> 401f8a6c_a177_4dcd_662b_ade2f5d17081 02abf1f6_b512_32df_c4f5_940df96192d8["anthropic.types.beta"] ffd4efa5_68eb_4c4c_51fe_26bc27478a2b --> 02abf1f6_b512_32df_c4f5_940df96192d8 style ffd4efa5_68eb_4c4c_51fe_26bc27478a2b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import time
import shutil
import threading
from typing import List, Optional, cast
from pathlib import Path
from typing_extensions import override
from pydantic import TypeAdapter
from anthropic import Anthropic
from anthropic.lib.tools import BetaAbstractMemoryTool
from anthropic.types.beta import (
BetaMessageParam,
BetaContentBlockParam,
BetaMemoryTool20250818Command,
BetaContextManagementConfigParam,
BetaMemoryTool20250818ViewCommand,
BetaMemoryTool20250818CreateCommand,
BetaMemoryTool20250818DeleteCommand,
BetaMemoryTool20250818InsertCommand,
BetaMemoryTool20250818RenameCommand,
BetaMemoryTool20250818StrReplaceCommand,
)
MEMORY_SYSTEM_PROMPT = """- ***DO NOT just store the conversation history**
- No need to mention your memory tool or what you are writting in it to the user, unless they ask
- Store facts about the user and their preferences
- Before responding, check memory to adjust technical depth and response style appropriately
- Keep memories up-to-date - remove outdated info, add new details as you learn them
- Use an xml format like <xml><name>John Doe</name></user></xml>"""
# Context management automatically clears old tool results to stay within token limits
# Triggers when input exceeds 20k tokens, clears down to 10k tokens
CONTEXT_MANAGEMENT = {
"edits": [
{
"type": "clear_tool_uses_20250919",
# The below parameters are OPTIONAL:
# Trigger clearing when threshold is exceeded
"trigger": {"type": "input_tokens", "value": 30000},
# Number of tool uses to keep after clearing
"keep": {"type": "tool_uses", "value": 3},
# Optional: Clear at least this many tokens
"clear_at_least": {"type": "input_tokens", "value": 5000},
# Exclude these tools uses from being cleared
"exclude_tools": ["web_search"],
}
]
}
class LocalFilesystemMemoryTool(BetaAbstractMemoryTool):
"""File-based memory storage implementation for Claude conversations"""
def __init__(self, base_path: str = "./memory"):
super().__init__()
self.base_path = Path(base_path)
self.memory_root = self.base_path / "memories"
self.memory_root.mkdir(parents=True, exist_ok=True)
// ... (333 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- anthropic
- anthropic.lib.tools
- anthropic.types.beta
- pathlib
- pydantic
- shutil
- threading
- time
- typing
- typing_extensions
Source
Frequently Asked Questions
What does basic.py do?
basic.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the ExtensibilityTools domain, MemorySystem subdomain.
What functions are defined in basic.py?
basic.py defines 1 function(s): conversation_loop.
What does basic.py depend on?
basic.py imports 10 module(s): anthropic, anthropic.lib.tools, anthropic.types.beta, pathlib, pydantic, shutil, threading, time, and 2 more.
Where is basic.py in the architecture?
basic.py is located at examples/memory/basic.py (domain: ExtensibilityTools, subdomain: MemorySystem, directory: examples/memory).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free