Grep Tool¶
Search file contents with regex.
Quick Example¶
from mamba_agents.tools import grep_search
# Search for pattern
matches = grep_search(
pattern=r"def \w+\(",
path="/project",
)
# With file filter
matches = grep_search(
pattern="TODO",
path="/src",
file_pattern="*.py",
)
# With context lines
matches = grep_search(
pattern="error",
path="/logs",
context_lines=2,
)
# Process results
for match in matches:
print(f"{match.file}:{match.line}: {match.content}")
API Reference¶
grep_search
¶
grep_search(
pattern: str,
path: str,
recursive: bool = True,
file_pattern: str = "*",
context_lines: int = 0,
ignore_case: bool = False,
regex: bool = True,
max_results: int = 100,
security: FilesystemSecurity | None = None,
) -> list[GrepMatch]
Search file contents for a pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
Pattern to search for (string or regex).
TYPE:
|
path
|
File or directory to search.
TYPE:
|
recursive
|
Search directories recursively.
TYPE:
|
file_pattern
|
Glob pattern for files to search (e.g., "*.py").
TYPE:
|
context_lines
|
Number of lines to include before/after matches.
TYPE:
|
ignore_case
|
Case-insensitive search.
TYPE:
|
regex
|
Treat pattern as regex (default: True).
TYPE:
|
max_results
|
Maximum number of matches to return.
TYPE:
|
security
|
Optional security context for path validation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[GrepMatch]
|
List of GrepMatch objects. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the path doesn't exist. |
PermissionError
|
If access is denied. |