_handle_str_replace() — langchain Function Reference
Architecture documentation for the _handle_str_replace() function in anthropic_tools.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD ca64d5cb_384c_c03b_d650_455c3ed4afca["_handle_str_replace()"] 87c73dc6_9eac_4f37_3263_c6a4d3764b6e["_FilesystemClaudeFileToolMiddleware"] ca64d5cb_384c_c03b_d650_455c3ed4afca -->|defined in| 87c73dc6_9eac_4f37_3263_c6a4d3764b6e d5be6f58_fb1c_3813_50f1_02703977d3ba["_handle_str_replace()"] d5be6f58_fb1c_3813_50f1_02703977d3ba -->|calls| ca64d5cb_384c_c03b_d650_455c3ed4afca 32d77b79_4a98_2de5_3e92_7514829faaa3["__init__()"] 32d77b79_4a98_2de5_3e92_7514829faaa3 -->|calls| ca64d5cb_384c_c03b_d650_455c3ed4afca f268378f_de49_cc43_eb3b_bb6313c21433["_validate_and_resolve_path()"] ca64d5cb_384c_c03b_d650_455c3ed4afca -->|calls| f268378f_de49_cc43_eb3b_bb6313c21433 d5be6f58_fb1c_3813_50f1_02703977d3ba["_handle_str_replace()"] ca64d5cb_384c_c03b_d650_455c3ed4afca -->|calls| d5be6f58_fb1c_3813_50f1_02703977d3ba style ca64d5cb_384c_c03b_d650_455c3ed4afca fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py lines 928–963
def _handle_str_replace(self, args: dict, tool_call_id: str | None) -> Command:
"""Handle `str_replace` command."""
path = args["path"]
old_str = args["old_str"]
new_str = args.get("new_str", "")
full_path = self._validate_and_resolve_path(path)
if not full_path.exists():
msg = f"File not found: {path}"
raise FileNotFoundError(msg)
# Read file
content = full_path.read_text()
# Replace string
if old_str not in content:
msg = f"String not found in file: {old_str}"
raise ValueError(msg)
new_content = content.replace(old_str, new_str, 1)
# Write back
full_path.write_text(new_content)
return Command(
update={
"messages": [
ToolMessage(
content=f"String replaced in {path}",
tool_call_id=tool_call_id,
name=self.tool_name,
)
]
}
)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _handle_str_replace() do?
_handle_str_replace() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py.
Where is _handle_str_replace() defined?
_handle_str_replace() is defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py at line 928.
What does _handle_str_replace() call?
_handle_str_replace() calls 2 function(s): _handle_str_replace, _validate_and_resolve_path.
What calls _handle_str_replace()?
_handle_str_replace() is called by 2 function(s): __init__, _handle_str_replace.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free