Home / File/ file_search.py — langchain Source File

file_search.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 7 imports 4 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  9561b9e8_b708_da44_5788_42f932041a59["file_search.py"]
  6981cd94_29a7_1048_c996_e1c505576216["fnmatch"]
  9561b9e8_b708_da44_5788_42f932041a59 --> 6981cd94_29a7_1048_c996_e1c505576216
  67ec3255_645e_8b6e_1eff_1eb3c648ed95["re"]
  9561b9e8_b708_da44_5788_42f932041a59 --> 67ec3255_645e_8b6e_1eff_1eb3c648ed95
  b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8["pathlib"]
  9561b9e8_b708_da44_5788_42f932041a59 --> b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  9561b9e8_b708_da44_5788_42f932041a59 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  50acc543_e5f0_2162_cf07_c2bf50723e0c["langchain.agents.middleware.types"]
  9561b9e8_b708_da44_5788_42f932041a59 --> 50acc543_e5f0_2162_cf07_c2bf50723e0c
  e85266a5_b172_4ddd_2fa6_e91b38ae8c0e["langchain.tools"]
  9561b9e8_b708_da44_5788_42f932041a59 --> e85266a5_b172_4ddd_2fa6_e91b38ae8c0e
  d03d9663_5201_66f4_af13_03c9f4d7984d["langchain_anthropic.middleware.anthropic_tools"]
  9561b9e8_b708_da44_5788_42f932041a59 --> d03d9663_5201_66f4_af13_03c9f4d7984d
  style 9561b9e8_b708_da44_5788_42f932041a59 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""File search middleware for Anthropic text editor and memory tools.

This module provides Glob and Grep search tools that operate on files stored
in state or filesystem.
"""

from __future__ import annotations

import fnmatch
import re
from pathlib import Path, PurePosixPath
from typing import TYPE_CHECKING, Literal, cast

if TYPE_CHECKING:
    from typing import Any

from langchain.agents.middleware.types import AgentMiddleware
from langchain.tools import ToolRuntime, tool

from langchain_anthropic.middleware.anthropic_tools import AnthropicToolsState


def _expand_include_patterns(pattern: str) -> list[str] | None:
    """Expand brace patterns like `*.{py,pyi}` into a list of globs."""
    if "}" in pattern and "{" not in pattern:
        return None

    expanded: list[str] = []

    def _expand(current: str) -> None:
        start = current.find("{")
        if start == -1:
            expanded.append(current)
            return

        end = current.find("}", start)
        if end == -1:
            raise ValueError

        prefix = current[:start]
        suffix = current[end + 1 :]
        inner = current[start + 1 : end]
        if not inner:
            raise ValueError

        for option in inner.split(","):
            _expand(prefix + option + suffix)

    try:
        _expand(pattern)
    except ValueError:
        return None

    return expanded


def _is_valid_include_pattern(pattern: str) -> bool:
    """Validate glob pattern used for include filters."""
    if not pattern:
        return False
// ... (295 more lines)

Subdomains

Dependencies

  • fnmatch
  • langchain.agents.middleware.types
  • langchain.tools
  • langchain_anthropic.middleware.anthropic_tools
  • pathlib
  • re
  • typing

Frequently Asked Questions

What does file_search.py do?
file_search.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in file_search.py?
file_search.py defines 4 function(s): _expand_include_patterns, _is_valid_include_pattern, _match_include_pattern, typing.
What does file_search.py depend on?
file_search.py imports 7 module(s): fnmatch, langchain.agents.middleware.types, langchain.tools, langchain_anthropic.middleware.anthropic_tools, pathlib, re, typing.
Where is file_search.py in the architecture?
file_search.py is located at libs/partners/anthropic/langchain_anthropic/middleware/file_search.py (domain: CoreAbstractions, subdomain: RunnableInterface, 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