feat(agent): add built-in grep and glob search tools
This commit is contained in:
@@ -8,6 +8,12 @@ Each skill is a directory containing a `SKILL.md` file with:
|
||||
- YAML frontmatter (name, description, metadata)
|
||||
- Markdown instructions for the agent
|
||||
|
||||
When skills reference large local documentation or logs, prefer nanobot's built-in
|
||||
`grep` / `glob` tools to narrow the search space before loading full files.
|
||||
Use `grep(output_mode="count")` / `files_with_matches` for broad searches first,
|
||||
use `head_limit` / `offset` to page through large result sets,
|
||||
and `glob(entry_type="dirs")` when discovering directory structure matters.
|
||||
|
||||
## Attribution
|
||||
|
||||
These skills are adapted from [OpenClaw](https://github.com/openclaw/openclaw)'s skill system.
|
||||
|
||||
@@ -16,14 +16,22 @@ always: true
|
||||
Choose the search method based on file size:
|
||||
|
||||
- Small `memory/HISTORY.md`: use `read_file`, then search in-memory
|
||||
- Large or long-lived `memory/HISTORY.md`: use the `exec` tool for targeted search
|
||||
- Large or long-lived `memory/HISTORY.md`: use the built-in `grep` tool first
|
||||
- For broad searches, start with `grep(..., output_mode="count")` or accept the default `files_with_matches` output to scope the result set before asking for full matching lines
|
||||
- Use `head_limit` / `offset` when browsing long histories in chunks
|
||||
- Use `exec` only as a last-resort fallback when you truly need shell-specific behavior
|
||||
|
||||
Examples:
|
||||
- **Linux/macOS:** `grep -i "keyword" memory/HISTORY.md`
|
||||
- **Windows:** `findstr /i "keyword" memory\HISTORY.md`
|
||||
- **Cross-platform Python:** `python -c "from pathlib import Path; text = Path('memory/HISTORY.md').read_text(encoding='utf-8'); print('\n'.join([l for l in text.splitlines() if 'keyword' in l.lower()][-20:]))"`
|
||||
- `grep(pattern="keyword", path="memory/HISTORY.md", case_insensitive=true)`
|
||||
- `grep(pattern="[2026-04-02 10:00]", path="memory/HISTORY.md", fixed_strings=true)`
|
||||
- `grep(pattern="keyword", path="memory/HISTORY.md", output_mode="count", case_insensitive=true)`
|
||||
- `grep(pattern="token", path="memory", glob="*.md", output_mode="files_with_matches", case_insensitive=true)`
|
||||
- `grep(pattern="oauth|token", path="memory", glob="*.md", case_insensitive=true)`
|
||||
- Fallback shell examples:
|
||||
- **Linux/macOS:** `grep -i "keyword" memory/HISTORY.md`
|
||||
- **Windows:** `findstr /i "keyword" memory\HISTORY.md`
|
||||
|
||||
Prefer targeted command-line search for large history files.
|
||||
Prefer the built-in `grep` tool for large history files; only drop to shell when the built-in search cannot express what you need.
|
||||
|
||||
## When to Update MEMORY.md
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ Documentation and reference material intended to be loaded as needed into contex
|
||||
- **Examples**: `references/finance.md` for financial schemas, `references/mnda.md` for company NDA template, `references/policies.md` for company policies, `references/api_docs.md` for API specifications
|
||||
- **Use cases**: Database schemas, API documentation, domain knowledge, company policies, detailed workflow guides
|
||||
- **Benefits**: Keeps SKILL.md lean, loaded only when the agent determines it's needed
|
||||
- **Best practice**: If files are large (>10k words), include grep search patterns in SKILL.md
|
||||
- **Best practice**: If files are large (>10k words), include grep or glob patterns in SKILL.md so the agent can use built-in search tools efficiently; mention when the default `grep(output_mode="files_with_matches")`, `grep(output_mode="count")`, `grep(fixed_strings=true)`, `glob(entry_type="dirs")`, or pagination via `head_limit` / `offset` is the right first step
|
||||
- **Avoid duplication**: Information should live in either SKILL.md or references files, not both. Prefer references files for detailed information unless it's truly core to the skill—this keeps SKILL.md lean while making information discoverable without hogging the context window. Keep only essential procedural instructions and workflow guidance in SKILL.md; move detailed reference material, schemas, and examples to references files.
|
||||
|
||||
##### Assets (`assets/`)
|
||||
|
||||
Reference in New Issue
Block a user