_handle_glob_search() — langchain Function Reference
Architecture documentation for the _handle_glob_search() function in file_search.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 8a879678_2844_abbb_fe87_14ae1c8a856c["_handle_glob_search()"] 90afd8f3_1e0a_8505_387a_6cda18a008c3["StateFileSearchMiddleware"] 8a879678_2844_abbb_fe87_14ae1c8a856c -->|defined in| 90afd8f3_1e0a_8505_387a_6cda18a008c3 5e762dee_61b5_cd13_bdc0_96a8285f41ee["__init__()"] 5e762dee_61b5_cd13_bdc0_96a8285f41ee -->|calls| 8a879678_2844_abbb_fe87_14ae1c8a856c style 8a879678_2844_abbb_fe87_14ae1c8a856c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/middleware/file_search.py lines 201–259
def _handle_glob_search(
self,
pattern: str,
path: str,
state: AnthropicToolsState,
) -> str:
"""Handle glob search operation.
Args:
pattern: The glob pattern to match files against.
path: The directory to search in.
state: The current agent state.
Returns:
Newline-separated list of matching file paths, sorted by modification
time (most recently modified first).
Returns `'No files found'` if no matches.
"""
# Normalize base path
base_path = path if path.startswith("/") else "/" + path
# Get files from state
files = cast("dict[str, Any]", state.get(self.state_key, {}))
# Match files
matches = []
for file_path, file_data in files.items():
if file_path.startswith(base_path):
# Get relative path from base
if base_path == "/":
relative = file_path[1:] # Remove leading /
elif file_path == base_path:
relative = Path(file_path).name
elif file_path.startswith(base_path + "/"):
relative = file_path[len(base_path) + 1 :]
else:
continue
# Match against pattern
# Handle ** pattern which requires special care
# PurePosixPath.match doesn't match single-level paths
# against **/pattern
is_match = PurePosixPath(relative).match(pattern)
if not is_match and pattern.startswith("**/"):
# Also try matching without the **/ prefix for files in base dir
is_match = PurePosixPath(relative).match(pattern[3:])
if is_match:
matches.append((file_path, file_data["modified_at"]))
if not matches:
return "No files found"
# Sort by modification time
matches.sort(key=lambda x: x[1], reverse=True)
file_paths = [path for path, _ in matches]
return "\n".join(file_paths)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _handle_glob_search() do?
_handle_glob_search() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/file_search.py.
Where is _handle_glob_search() defined?
_handle_glob_search() is defined in libs/partners/anthropic/langchain_anthropic/middleware/file_search.py at line 201.
What calls _handle_glob_search()?
_handle_glob_search() is called by 1 function(s): __init__.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free