From 5fe5523d1362a3e7209831076687c6c7a4ec8216 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 20 May 2026 15:31:02 +0800 Subject: [PATCH] fix: prefer rg in agent prompts --- app/agent/prompt/__init__.py | 6 ++++++ tests/test_agent_prompt_style.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/app/agent/prompt/__init__.py b/app/agent/prompt/__init__.py index 6d1072acf..03d08b0ee 100644 --- a/app/agent/prompt/__init__.py +++ b/app/agent/prompt/__init__.py @@ -388,6 +388,12 @@ class PromptManager: info_lines.extend( f" - {command}: {path}" for command, path in available_commands ) + # `rg` 同时覆盖文件枚举和文本检索,且比通用 shell 查找更适合 + # Agent 的代码阅读与定位场景;只有在它不可用或不适合时才退回其他工具。 + if any(command == "rg" for command, _ in available_commands): + info_lines.append( + "- When searching files or text, prefer `rg` / `rg --files`. Only fall back to other search tools when `rg` is unavailable or unsuitable." + ) return "\n".join(info_lines) diff --git a/tests/test_agent_prompt_style.py b/tests/test_agent_prompt_style.py index 3b32641d8..d5b8dfa31 100644 --- a/tests/test_agent_prompt_style.py +++ b/tests/test_agent_prompt_style.py @@ -61,6 +61,10 @@ class TestAgentPromptStyle(unittest.TestCase): self.assertIn("- 可用系统命令(可通过 `execute_command` 调用):", prompt) self.assertIn(" - ssh: /usr/bin/ssh", prompt) self.assertIn(" - rg: /opt/homebrew/bin/rg", prompt) + self.assertIn( + "When searching files or text, prefer `rg` / `rg --files`", + prompt, + ) self.assertNotIn(" - git:", prompt) def test_base_prompt_omits_shell_command_section_when_none_available(self):