__init__() — langchain Function Reference
Architecture documentation for the __init__() function in file_search.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5e762dee_61b5_cd13_bdc0_96a8285f41ee["__init__()"] 90afd8f3_1e0a_8505_387a_6cda18a008c3["StateFileSearchMiddleware"] 5e762dee_61b5_cd13_bdc0_96a8285f41ee -->|defined in| 90afd8f3_1e0a_8505_387a_6cda18a008c3 8a879678_2844_abbb_fe87_14ae1c8a856c["_handle_glob_search()"] 5e762dee_61b5_cd13_bdc0_96a8285f41ee -->|calls| 8a879678_2844_abbb_fe87_14ae1c8a856c 9c9a2eda_be6c_5f6f_9a0a_3f3e5575dc2e["_handle_grep_search()"] 5e762dee_61b5_cd13_bdc0_96a8285f41ee -->|calls| 9c9a2eda_be6c_5f6f_9a0a_3f3e5575dc2e style 5e762dee_61b5_cd13_bdc0_96a8285f41ee fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/middleware/file_search.py lines 116–199
def __init__(
self,
*,
state_key: str = "text_editor_files",
) -> None:
"""Initialize the search middleware.
Args:
state_key: State key to search
Use `'memory_files'` to search memory tool files.
"""
self.state_key = state_key
# Create tool instances
@tool
def glob_search( # noqa: D417
runtime: ToolRuntime[None, AnthropicToolsState],
pattern: str,
path: str = "/",
) -> str:
"""Fast file pattern matching tool that works with any codebase size.
Supports glob patterns like `**/*.js` or `src/**/*.ts`.
Returns matching file paths sorted by modification time.
Use this tool when you need to find files by name patterns.
Args:
pattern: The glob pattern to match files against.
path: The directory to search in.
If not specified, searches from root.
Returns:
Newline-separated list of matching file paths, sorted by modification
time (most recently modified first).
Returns `'No files found'` if no matches.
"""
return self._handle_glob_search(pattern, path, runtime.state)
@tool
def grep_search( # noqa: D417
runtime: ToolRuntime[None, AnthropicToolsState],
pattern: str,
path: str = "/",
include: str | None = None,
output_mode: Literal[
"files_with_matches", "content", "count"
] = "files_with_matches",
) -> str:
"""Fast content search tool that works with any codebase size.
Searches file contents using regular expressions.
Supports full regex syntax and filters files by pattern with the include
parameter.
Args:
pattern: The regular expression pattern to search for in file contents.
path: The directory to search in. If not specified, searches from root.
include: File pattern to filter (e.g., `'*.js'`, `'*.{ts,tsx}'`).
output_mode: Output format.
Options:
- `'files_with_matches'`: Only file paths containing matches
- `'content'`: Matching lines with file:line:content format
- `'count'`: Count of matches per file
Returns:
Search results formatted according to `output_mode`.
Returns `'No matches found'` if no results.
"""
return self._handle_grep_search(
pattern, path, include, output_mode, runtime.state
)
Domain
Subdomains
Source
Frequently Asked Questions
What does __init__() do?
__init__() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/file_search.py.
Where is __init__() defined?
__init__() is defined in libs/partners/anthropic/langchain_anthropic/middleware/file_search.py at line 116.
What does __init__() call?
__init__() calls 2 function(s): _handle_glob_search, _handle_grep_search.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free