Home / Function/ _handle_rename() — langchain Function Reference

_handle_rename() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  d5828fea_01d0_2456_5f33_0a53ee547827["_handle_rename()"]
  cc57e604_ebeb_0d7e_259e_ae26b40e03fa["_StateClaudeFileToolMiddleware"]
  d5828fea_01d0_2456_5f33_0a53ee547827 -->|defined in| cc57e604_ebeb_0d7e_259e_ae26b40e03fa
  e9dbd5b2_27e4_e878_3cde_25abd3acf9b7["__init__()"]
  e9dbd5b2_27e4_e878_3cde_25abd3acf9b7 -->|calls| d5828fea_01d0_2456_5f33_0a53ee547827
  e036d288_ed03_4984_8199_018cccb818c3["_handle_rename()"]
  e036d288_ed03_4984_8199_018cccb818c3 -->|calls| d5828fea_01d0_2456_5f33_0a53ee547827
  e036d288_ed03_4984_8199_018cccb818c3["_handle_rename()"]
  d5828fea_01d0_2456_5f33_0a53ee547827 -->|calls| e036d288_ed03_4984_8199_018cccb818c3
  c3b02d97_e5fe_b3c4_bc92_7f2655652ed9["_validate_path()"]
  d5828fea_01d0_2456_5f33_0a53ee547827 -->|calls| c3b02d97_e5fe_b3c4_bc92_7f2655652ed9
  style d5828fea_01d0_2456_5f33_0a53ee547827 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py lines 529–569

    def _handle_rename(
        self, args: dict, state: AnthropicToolsState, tool_call_id: str | None
    ) -> Command:
        """Handle rename command."""
        old_path = args["old_path"]
        new_path = args["new_path"]

        normalized_old = _validate_path(
            old_path, allowed_prefixes=self.allowed_prefixes
        )
        normalized_new = _validate_path(
            new_path, allowed_prefixes=self.allowed_prefixes
        )

        # Read file
        files = cast("dict[str, Any]", state.get(self.state_key, {}))
        file_data = files.get(normalized_old)
        if file_data is None:
            msg = f"File not found: {old_path}"
            raise ValueError(msg)

        # Update timestamp
        now = datetime.now(timezone.utc).isoformat()
        file_data_copy = file_data.copy()
        file_data_copy["modified_at"] = now

        return Command(
            update={
                self.state_key: {
                    normalized_old: None,
                    normalized_new: file_data_copy,
                },
                "messages": [
                    ToolMessage(
                        content=f"File renamed: {old_path} -> {new_path}",
                        tool_call_id=tool_call_id,
                        name=self.tool_name,
                    )
                ],
            }
        )

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free