Skip to content

Commit e9bfea8

Browse files
committed
refine(agent): reframe grep step as locate-then-read (drill for detail), not a terminal sweep
1 parent 98d26c5 commit e9bfea8

1 file changed

Lines changed: 29 additions & 28 deletions

File tree

openkb/agent/query.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@
3939
ranges to help you target. Never fetch the whole document.
4040
6. Source content may reference images (e.g. ![image](sources/images/doc/file.png)).
4141
Use the get_image tool to view them when needed.
42-
7. COMPLETENESS SWEEP (do this before finalizing): the summary layer is
43-
lossy, so before you commit to an answer, call grep_wiki for the
44-
question's salient terms — proper nouns, technical terms, numbers, key
45-
entities — plus any claim you asserted in your draft that you have not
46-
yet seen on a wiki page. Because grep is lexical (not semantic), try a
47-
few term variants: acronym and expansion, singular/plural, close
48-
synonyms. For any matching page you have NOT already read, read_file it
49-
(grep_wiki lines are `path:line:text`; pass only the path, before the
50-
first colon) and fold in relevant content. If grep surfaces a claim that contradicts
51-
your draft, note both claims with their citations rather than silently
52-
choosing one. Do at most 3 grep rounds (a round = one concept and its
53-
variants); stop once a round surfaces no new page. grep_wiki is a check,
54-
not the primary search — index.md and summaries still come first.
42+
7. DRILL FOR DETAIL with grep_wiki (after reading the curated pages above):
43+
summaries are lossy, so when the question needs specifics they do not
44+
fully contain — numbers, names, exact claims, edge cases — use grep_wiki
45+
to LOCATE which pages hold them. grep is lexical, so try a few term
46+
variants: acronym and expansion, singular/plural, close synonyms. Treat
47+
the results as a reading list: each line is `path:line:text` — for every
48+
relevant page you have NOT already read in full, read_file that path
49+
(everything before the first colon) and extract the detail. Do NOT answer
50+
from the grep line alone; open the page. If a page contradicts what you
51+
already have, note both claims with their citations rather than silently
52+
choosing one. Repeat locate-then-read until the pages that actually
53+
contain the needed detail have been read (at most 3 grep rounds; stop once
54+
a round surfaces no new relevant page). grep_wiki complements index.md and
55+
summaries (your starting point) — it does not replace them.
5556
8. Synthesize a clear, concise, well-cited answer grounded in wiki content.
5657
5758
Answer based only on wiki content. Be concise.
@@ -103,21 +104,21 @@ def get_image(image_path: str) -> ToolOutputImage | ToolOutputText:
103104

104105
@function_tool
105106
def grep_wiki(pattern: str, ignore_case: bool = True, fixed_string: bool = False) -> str:
106-
"""Lexically grep the wiki's markdown for a pattern.
107-
108-
Use this as a FINAL completeness check, after you have drafted an
109-
answer from index.md / summaries / concepts / entities. It searches
110-
every wiki .md file (including short-doc sources/) for the literal
111-
terms of the question — catching details the summaries compressed
112-
away, pages you never opened, or contradicting mentions. It does NOT
113-
search long-document page content (use get_page_content for that).
114-
115-
Returns up to 50 matches, one per line as 'path.md:LINE:text'. The
116-
path is everything before the FIRST colon — pass only that path to
117-
read_file (not the whole line). Pattern is an extended regex (ERE):
118-
alternation 'a|b', '?', '+', '()' work; set fixed_string=True for a
119-
literal search. Try a few term variants (acronym/expansion,
120-
singular/plural, synonyms) — this is lexical, not semantic.
107+
"""Locate wiki pages that contain specific detail, by lexical grep.
108+
109+
Use this to FIND which pages hold specifics the summaries lack —
110+
numbers, names, exact claims, edge cases — then read_file those pages
111+
to extract the detail. It searches every wiki .md file (including
112+
short-doc sources/); it does NOT search long-document page content
113+
(use get_page_content for that).
114+
115+
Returns up to 50 matches, one per line as 'path.md:LINE:text'. Each
116+
result is a page to OPEN, not an answer: take the path (everything
117+
before the FIRST colon) and read_file it — do not answer from the grep
118+
line alone. Pattern is an extended regex (ERE): alternation 'a|b', '?',
119+
'+', '()' work; set fixed_string=True for a literal search. Try a few
120+
term variants (acronym/expansion, singular/plural, synonyms) — this is
121+
lexical, not semantic.
121122
122123
Args:
123124
pattern: Search pattern (extended regex by default).

0 commit comments

Comments
 (0)