__init__() — langchain Function Reference
Architecture documentation for the __init__() function in anthropic_tools.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e9dbd5b2_27e4_e878_3cde_25abd3acf9b7["__init__()"] cc57e604_ebeb_0d7e_259e_ae26b40e03fa["_StateClaudeFileToolMiddleware"] e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 -->|defined in| cc57e604_ebeb_0d7e_259e_ae26b40e03fa f2bf3aba_56f3_0a65_e91d_2e98b4adca69["_handle_view()"] e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 -->|calls| f2bf3aba_56f3_0a65_e91d_2e98b4adca69 cccfcdcd_b72a_d23f_92ed_37c67cf37874["_handle_create()"] e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 -->|calls| cccfcdcd_b72a_d23f_92ed_37c67cf37874 d5be6f58_fb1c_3813_50f1_02703977d3ba["_handle_str_replace()"] e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 -->|calls| d5be6f58_fb1c_3813_50f1_02703977d3ba 219744f9_1d86_457c_0923_cb1c51e6d7c4["_handle_insert()"] e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 -->|calls| 219744f9_1d86_457c_0923_cb1c51e6d7c4 63459622_9e3d_3c8b_3a8d_2d55f8abb393["_handle_delete()"] e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 -->|calls| 63459622_9e3d_3c8b_3a8d_2d55f8abb393 d5828fea_01d0_2456_5f33_0a53ee547827["_handle_rename()"] e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 -->|calls| d5828fea_01d0_2456_5f33_0a53ee547827 style e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py lines 164–260
def __init__(
self,
*,
tool_type: str,
tool_name: str,
state_key: str,
allowed_path_prefixes: Sequence[str] | None = None,
system_prompt: str | None = None,
) -> None:
"""Initialize.
Args:
tool_type: Tool type identifier.
tool_name: Tool name.
state_key: State key for file storage.
allowed_path_prefixes: Optional list of allowed path prefixes.
system_prompt: Optional system prompt to inject.
"""
self.tool_type = tool_type
self.tool_name = tool_name
self.state_key = state_key
self.allowed_prefixes = allowed_path_prefixes
self.system_prompt = system_prompt
# Create tool that will be executed by the tool node
@tool(tool_name)
def file_tool(
runtime: ToolRuntime[None, AnthropicToolsState],
command: str,
path: str,
file_text: str | None = None,
old_str: str | None = None,
new_str: str | None = None,
insert_line: int | None = None,
new_path: str | None = None,
view_range: list[int] | None = None,
) -> Command | str:
"""Execute file operations on virtual file system.
Args:
runtime: Tool runtime providing access to state.
command: Operation to perform.
path: File path to operate on.
file_text: Full file content for create command.
old_str: String to replace for str_replace command.
new_str: Replacement string for str_replace command.
insert_line: Line number for insert command.
new_path: New path for rename command.
view_range: Line range `[start, end]` for view command.
Returns:
Command for state update or string result.
"""
# Build args dict for handler methods
args: dict[str, Any] = {"path": path}
if file_text is not None:
args["file_text"] = file_text
if old_str is not None:
args["old_str"] = old_str
if new_str is not None:
args["new_str"] = new_str
if insert_line is not None:
args["insert_line"] = insert_line
if new_path is not None:
args["new_path"] = new_path
if view_range is not None:
args["view_range"] = view_range
# Route to appropriate handler based on command
try:
if command == "view":
return self._handle_view(args, runtime.state, runtime.tool_call_id)
if command == "create":
return self._handle_create(
args, runtime.state, runtime.tool_call_id
)
if command == "str_replace":
return self._handle_str_replace(
args, runtime.state, runtime.tool_call_id
)
if command == "insert":
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does __init__() do?
__init__() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py.
Where is __init__() defined?
__init__() is defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py at line 164.
What does __init__() call?
__init__() calls 6 function(s): _handle_create, _handle_delete, _handle_insert, _handle_rename, _handle_str_replace, _handle_view.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free