Home / Class/ _FilesystemClaudeFileToolMiddleware Class — langchain Architecture

_FilesystemClaudeFileToolMiddleware Class — langchain Architecture

Architecture documentation for the _FilesystemClaudeFileToolMiddleware class in anthropic_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8fe6cc85_9f97_b147_028a_db962cd6b744["_FilesystemClaudeFileToolMiddleware"]
  6d9956c5_7c84_9ec3_58a3_b6b89f42fd0b["AgentMiddleware"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|extends| 6d9956c5_7c84_9ec3_58a3_b6b89f42fd0b
  5f8ab4b6_f98f_f653_1208_76332f94ecba["anthropic_tools.py"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|defined in| 5f8ab4b6_f98f_f653_1208_76332f94ecba
  e5be7c59_74bf_39bf_5c0d_68e7464528d5["__init__()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| e5be7c59_74bf_39bf_5c0d_68e7464528d5
  6a64399c_cea8_35c7_9314_632769843ad5["wrap_model_call()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| 6a64399c_cea8_35c7_9314_632769843ad5
  8fa6e522_084e_ae38_8b46_d841d12dac41["awrap_model_call()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| 8fa6e522_084e_ae38_8b46_d841d12dac41
  a959d410_fe90_f6ec_b682_718935b4989d["_validate_and_resolve_path()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| a959d410_fe90_f6ec_b682_718935b4989d
  bd1716db_54f0_3a38_c477_aac0add6ef96["_handle_view()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| bd1716db_54f0_3a38_c477_aac0add6ef96
  0307c541_5403_0f61_4ea8_d539e7feba37["_handle_create()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| 0307c541_5403_0f61_4ea8_d539e7feba37
  3732ee4a_2f6c_734d_2fa4_f8dfef934faf["_handle_str_replace()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| 3732ee4a_2f6c_734d_2fa4_f8dfef934faf
  584d0264_1341_9376_93f6_1b3a96560be5["_handle_insert()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| 584d0264_1341_9376_93f6_1b3a96560be5
  b25452b5_6029_0705_04b9_0521b9712fee["_handle_delete()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| b25452b5_6029_0705_04b9_0521b9712fee
  277428f5_5ca6_a1a7_1c0c_cbcf11e77185["_handle_rename()"]
  8fe6cc85_9f97_b147_028a_db962cd6b744 -->|method| 277428f5_5ca6_a1a7_1c0c_cbcf11e77185

Relationship Graph

Source Code

libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py lines 657–1061

class _FilesystemClaudeFileToolMiddleware(AgentMiddleware):
    """Base class for filesystem-based file tool middleware (internal)."""

    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)

Extends

Frequently Asked Questions

What is the _FilesystemClaudeFileToolMiddleware class?
_FilesystemClaudeFileToolMiddleware is a class in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py.
Where is _FilesystemClaudeFileToolMiddleware defined?
_FilesystemClaudeFileToolMiddleware is defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py at line 657.
What does _FilesystemClaudeFileToolMiddleware extend?
_FilesystemClaudeFileToolMiddleware extends AgentMiddleware.

Analyze Your Own Codebase

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

Try Supermodel Free