_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 f2bf3aba_56f3_0a65_e91d_2e98b4adca69["_handle_view()"] cc57e604_ebeb_0d7e_259e_ae26b40e03fa["_StateClaudeFileToolMiddleware"] f2bf3aba_56f3_0a65_e91d_2e98b4adca69 -->|defined in| cc57e604_ebeb_0d7e_259e_ae26b40e03fa e9dbd5b2_27e4_e878_3cde_25abd3acf9b7["__init__()"] e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 -->|calls| f2bf3aba_56f3_0a65_e91d_2e98b4adca69 258e5027_e9a7_79ad_980f_e88ab9706215["_handle_view()"] 258e5027_e9a7_79ad_980f_e88ab9706215 -->|calls| f2bf3aba_56f3_0a65_e91d_2e98b4adca69 32d77b79_4a98_2de5_3e92_7514829faaa3["__init__()"] 32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| f2bf3aba_56f3_0a65_e91d_2e98b4adca69 258e5027_e9a7_79ad_980f_e88ab9706215["_handle_view()"] f2bf3aba_56f3_0a65_e91d_2e98b4adca69 -->|calls| 258e5027_e9a7_79ad_980f_e88ab9706215 c3b02d97_e5fe_b3c4_bc92_7f2655652ed9["_validate_path()"] f2bf3aba_56f3_0a65_e91d_2e98b4adca69 -->|calls| c3b02d97_e5fe_b3c4_bc92_7f2655652ed9 19486b37_2ea2_1132_8eb1_d4def5f50de0["_list_directory()"] f2bf3aba_56f3_0a65_e91d_2e98b4adca69 -->|calls| 19486b37_2ea2_1132_8eb1_d4def5f50de0 style f2bf3aba_56f3_0a65_e91d_2e98b4adca69 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py lines 322–368
def _handle_view(
self, args: dict, state: AnthropicToolsState, tool_call_id: str | None
) -> Command:
"""Handle view command."""
path = args["path"]
normalized_path = _validate_path(path, allowed_prefixes=self.allowed_prefixes)
files = cast("dict[str, Any]", state.get(self.state_key, {}))
file_data = files.get(normalized_path)
if file_data is None:
# Try directory listing
matching = _list_directory(files, normalized_path)
if matching:
content = "\n".join(matching)
return Command(
update={
"messages": [
ToolMessage(
content=content,
tool_call_id=tool_call_id,
name=self.tool_name,
)
]
}
)
msg = f"File not found: {path}"
raise FileNotFoundError(msg)
# Format file content with line numbers
lines_content = file_data["content"]
formatted_lines = [f"{i + 1}|{line}" for i, line in enumerate(lines_content)]
content = "\n".join(formatted_lines)
return Command(
update={
"messages": [
ToolMessage(
content=content,
tool_call_id=tool_call_id,
name=self.tool_name,
)
]
}
)
Domain
Subdomains
Called By
Source
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 322.
What does _handle_view() call?
_handle_view() calls 3 function(s): _handle_view, _list_directory, _validate_path.
What calls _handle_view()?
_handle_view() is called by 3 function(s): __init__, __init__, _handle_view.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free