Skip to content

Commit 942f87d

Browse files
authored
Add file reading guardrails to prevent review agent hallucination loops (#77)
1 parent e7d1ab0 commit 942f87d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

review-pr/agents/pr-review.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ agents:
134134
135135
Find **real bugs in the changed code**, not style issues. If the changed code works correctly, approve it.
136136
137+
## CRITICAL: File Reading Guardrails
138+
139+
The root agent MUST NOT exhaustively explore the repository. Follow these rules strictly:
140+
141+
1. **Only read files that are directly relevant**: the diff, AGENTS.md/CLAUDE.md, and files
142+
explicitly referenced in the diff (e.g., imported modules, configuration files mentioned
143+
in changed code). Do NOT speculatively read files to "understand the project."
144+
2. **Never guess file paths**: If you need to check whether a file exists, use `list_directory`
145+
first. Do NOT try `read_file` on paths you are guessing — this wastes time and tokens.
146+
3. **Circuit breaker**: If 3 consecutive `read_file` calls return "not found", STOP reading
147+
files immediately and proceed with what you have. The drafter and verifier have their own
148+
`read_file` access and will read source files as needed during analysis.
149+
4. **Cap total file reads**: The root agent should read at most 10 files total (excluding the
150+
diff itself). The drafter and verifier handle deeper file analysis.
151+
5. **Never enumerate topics as file paths**: Do NOT try to read files named after general
152+
concepts (e.g., `consensus.md`, `raft.md`, `six-sigma.md`). Only read files that
153+
appear in the diff, the project tree, or are referenced by other files you've already read.
154+
137155
## Delivering the Review
138156
139157
You MUST always deliver a review, even if no issues were found.
@@ -230,7 +248,7 @@ agents:
230248

231249
toolsets:
232250
- type: filesystem
233-
tools: [read_file, read_multiple_files, list_directory, directory_tree]
251+
tools: [read_file, read_multiple_files, list_directory]
234252
- type: shell
235253
- type: memory
236254
path: .cache/pr-review-memory.db

0 commit comments

Comments
 (0)