Home / Function/ _handle_view() — langchain Function Reference

_handle_view() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  258e5027_e9a7_79ad_980f_e88ab9706215["_handle_view()"]
  87c73dc6_9eac_4f37_3263_c6a4d3764b6e["_FilesystemClaudeFileToolMiddleware"]
  258e5027_e9a7_79ad_980f_e88ab9706215 -->|defined in| 87c73dc6_9eac_4f37_3263_c6a4d3764b6e
  f2bf3aba_56f3_0a65_e91d_2e98b4adca69["_handle_view()"]
  f2bf3aba_56f3_0a65_e91d_2e98b4adca69 -->|calls| 258e5027_e9a7_79ad_980f_e88ab9706215
  32d77b79_4a98_2de5_3e92_7514829faaa3["__init__()"]
  32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| 258e5027_e9a7_79ad_980f_e88ab9706215
  f268378f_de49_cc43_eb3b_bb6313c21433["_validate_and_resolve_path()"]
  258e5027_e9a7_79ad_980f_e88ab9706215 -->|calls| f268378f_de49_cc43_eb3b_bb6313c21433
  f2bf3aba_56f3_0a65_e91d_2e98b4adca69["_handle_view()"]
  258e5027_e9a7_79ad_980f_e88ab9706215 -->|calls| f2bf3aba_56f3_0a65_e91d_2e98b4adca69
  style 258e5027_e9a7_79ad_980f_e88ab9706215 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py lines 861–901

    def _handle_view(self, args: dict, tool_call_id: str | None) -> Command:
        """Handle view command."""
        path = args["path"]
        full_path = self._validate_and_resolve_path(path)

        if not full_path.exists() or not full_path.is_file():
            msg = f"File not found: {path}"
            raise FileNotFoundError(msg)

        # Check file size
        if full_path.stat().st_size > self.max_file_size_bytes:
            max_mb = self.max_file_size_bytes / 1024 / 1024
            msg = f"File too large: {path} exceeds {max_mb}MB"
            raise ValueError(msg)

        # Read file
        try:
            content = full_path.read_text()
        except UnicodeDecodeError as e:
            msg = f"Cannot decode file {path}: {e}"
            raise ValueError(msg) from e

        # Format with line numbers
        lines = content.split("\n")
        # Remove trailing newline's empty string if present
        if lines and lines[-1] == "":
            lines = lines[:-1]
        formatted_lines = [f"{i + 1}|{line}" for i, line in enumerate(lines)]
        formatted_content = "\n".join(formatted_lines)

        return Command(
            update={
                "messages": [
                    ToolMessage(
                        content=formatted_content,
                        tool_call_id=tool_call_id,
                        name=self.tool_name,
                    )
                ]
            }
        )

Domain

Subdomains

Frequently Asked Questions

What does _handle_view() do?
_handle_view() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py.
Where is _handle_view() defined?
_handle_view() is defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py at line 861.
What does _handle_view() call?
_handle_view() calls 2 function(s): _handle_view, _validate_and_resolve_path.
What calls _handle_view()?
_handle_view() is called by 2 function(s): __init__, _handle_view.

Analyze Your Own Codebase

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

Try Supermodel Free