Home / Function/ __init__() — langchain Function Reference

__init__() — langchain Function Reference

Architecture documentation for the __init__() function in anthropic_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  32d77b79_4a98_2de5_3e92_7514829faaa3["__init__()"]
  87c73dc6_9eac_4f37_3263_c6a4d3764b6e["_FilesystemClaudeFileToolMiddleware"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|defined in| 87c73dc6_9eac_4f37_3263_c6a4d3764b6e
  258e5027_e9a7_79ad_980f_e88ab9706215["_handle_view()"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| 258e5027_e9a7_79ad_980f_e88ab9706215
  08a8e224_c9ef_ff31_d248_ad37bce62ba4["_handle_create()"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| 08a8e224_c9ef_ff31_d248_ad37bce62ba4
  ca64d5cb_384c_c03b_d650_455c3ed4afca["_handle_str_replace()"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| ca64d5cb_384c_c03b_d650_455c3ed4afca
  e26ad50c_f58e_2a8a_dcf4_f2fc823c4f6b["_handle_insert()"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| e26ad50c_f58e_2a8a_dcf4_f2fc823c4f6b
  7f1c464d_8675_7e1c_5edb_485ad3e24a4b["_handle_delete()"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| 7f1c464d_8675_7e1c_5edb_485ad3e24a4b
  e036d288_ed03_4984_8199_018cccb818c3["_handle_rename()"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| e036d288_ed03_4984_8199_018cccb818c3
  f2bf3aba_56f3_0a65_e91d_2e98b4adca69["_handle_view()"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| f2bf3aba_56f3_0a65_e91d_2e98b4adca69
  cccfcdcd_b72a_d23f_92ed_37c67cf37874["_handle_create()"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| cccfcdcd_b72a_d23f_92ed_37c67cf37874
  style 32d77b79_4a98_2de5_3e92_7514829faaa3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py lines 660–752

    def __init__(
        self,
        *,
        tool_type: str,
        tool_name: str,
        root_path: str,
        allowed_prefixes: list[str] | None = None,
        max_file_size_mb: int = 10,
        system_prompt: str | None = None,
    ) -> None:
        """Initialize.

        Args:
            tool_type: Tool type identifier.
            tool_name: Tool name.
            root_path: Root directory for file operations.
            allowed_prefixes: Optional list of allowed virtual path prefixes.
            max_file_size_mb: Maximum file size in MB.
            system_prompt: Optional system prompt to inject.
        """
        self.tool_type = tool_type
        self.tool_name = tool_name
        self.root_path = Path(root_path).resolve()
        self.allowed_prefixes = allowed_prefixes or ["/"]
        self.max_file_size_bytes = max_file_size_mb * 1024 * 1024
        self.system_prompt = system_prompt

        # Create root directory if it doesn't exist
        self.root_path.mkdir(parents=True, exist_ok=True)

        # Create tool that will be executed by the tool node
        @tool(tool_name)
        def file_tool(
            runtime: ToolRuntime,
            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 filesystem.

            Args:
                runtime: Tool runtime providing `tool_call_id`.
                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 message 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.tool_call_id)
                if command == "create":
                    return self._handle_create(args, runtime.tool_call_id)
                if command == "str_replace":

Domain

Subdomains

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 660.
What does __init__() call?
__init__() calls 8 function(s): _handle_create, _handle_create, _handle_delete, _handle_insert, _handle_rename, _handle_str_replace, _handle_view, _handle_view.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free