Home / File/ anthropic_tools.py — langchain Source File

anthropic_tools.py — langchain Source File

Architecture documentation for anthropic_tools.py, a python file in the langchain codebase. 11 imports, 0 dependents.

File python CoreAbstractions MessageSchema 11 imports 4 functions 8 classes

Entity Profile

Dependency Diagram

graph LR
  5f8ab4b6_f98f_f653_1208_76332f94ecba["anthropic_tools.py"]
  9e98f0a7_ec6e_708f_4f1b_e9428b316e1c["os"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c
  a7f495f8_a546_d52e_f99a_98da076c977e["shutil"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> a7f495f8_a546_d52e_f99a_98da076c977e
  af34f08b_0ede_2b87_0db6_983d74ed0249["datetime"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> af34f08b_0ede_2b87_0db6_983d74ed0249
  b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8["pathlib"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  50acc543_e5f0_2162_cf07_c2bf50723e0c["langchain.agents.middleware.types"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> 50acc543_e5f0_2162_cf07_c2bf50723e0c
  e85266a5_b172_4ddd_2fa6_e91b38ae8c0e["langchain.tools"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> e85266a5_b172_4ddd_2fa6_e91b38ae8c0e
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> d758344f_537f_649e_f467_b9d7442e86df
  0e93d2ee_1fb2_3a0f_5a76_8aba32d0d4ed["langgraph.types"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> 0e93d2ee_1fb2_3a0f_5a76_8aba32d0d4ed
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> 91721f45_4909_e489_8c1f_084f8bd87145
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  5f8ab4b6_f98f_f653_1208_76332f94ecba --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  style 5f8ab4b6_f98f_f653_1208_76332f94ecba fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Anthropic text editor and memory tool middleware.

This module provides client-side implementations of Anthropic's text editor and
memory tools using schema-less tool definitions and tool call interception.
"""

from __future__ import annotations

import os
import shutil
from datetime import datetime, timezone
from pathlib import Path
from typing import TYPE_CHECKING, Annotated, Any, cast

from langchain.agents.middleware.types import (
    AgentMiddleware,
    AgentState,
    ModelRequest,
    ModelResponse,
    _ModelRequestOverrides,
)
from langchain.tools import ToolRuntime, tool
from langchain_core.messages import SystemMessage, ToolMessage
from langgraph.types import Command
from typing_extensions import NotRequired, TypedDict

if TYPE_CHECKING:
    from collections.abc import Awaitable, Callable, Sequence


# Tool type constants
TEXT_EDITOR_TOOL_TYPE = "text_editor_20250728"
TEXT_EDITOR_TOOL_NAME = "str_replace_based_edit_tool"
MEMORY_TOOL_TYPE = "memory_20250818"
MEMORY_TOOL_NAME = "memory"

MEMORY_SYSTEM_PROMPT = """IMPORTANT: ALWAYS VIEW YOUR MEMORY DIRECTORY BEFORE \
DOING ANYTHING ELSE.
MEMORY PROTOCOL:
1. Use the `view` command of your `memory` tool to check for earlier progress.
2. ... (work on the task) ...
   - As you make progress, record status / progress / thoughts etc in your memory.
ASSUME INTERRUPTION: Your context window might be reset at any moment, so you risk \
losing any progress that is not recorded in your memory directory."""


class FileData(TypedDict):
    """Data structure for storing file contents."""

    content: list[str]
    """Lines of the file."""

    created_at: str
    """ISO 8601 timestamp of file creation."""

    modified_at: str
    """ISO 8601 timestamp of last modification."""


def files_reducer(
// ... (1112 more lines)

Subdomains

Dependencies

  • collections.abc
  • datetime
  • langchain.agents.middleware.types
  • langchain.tools
  • langchain_core.messages
  • langgraph.types
  • os
  • pathlib
  • shutil
  • typing
  • typing_extensions

Frequently Asked Questions

What does anthropic_tools.py do?
anthropic_tools.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in anthropic_tools.py?
anthropic_tools.py defines 4 function(s): _list_directory, _validate_path, collections, files_reducer.
What does anthropic_tools.py depend on?
anthropic_tools.py imports 11 module(s): collections.abc, datetime, langchain.agents.middleware.types, langchain.tools, langchain_core.messages, langgraph.types, os, pathlib, and 3 more.
Where is anthropic_tools.py in the architecture?
anthropic_tools.py is located at libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/partners/anthropic/langchain_anthropic/middleware).

Analyze Your Own Codebase

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

Try Supermodel Free