From 90ba4c9dd46ef330a133744049d747aee47f9bc2 Mon Sep 17 00:00:00 2001 From: sami jaghouar Date: Thu, 11 Jun 2026 01:46:08 +0000 Subject: [PATCH] Prompt agents to use edit skill --- src/rlm/prompt.py | 13 +++++++++++++ tests/test_prompt.py | 24 ++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/rlm/prompt.py b/src/rlm/prompt.py index 8f72012..1c35602 100644 --- a/src/rlm/prompt.py +++ b/src/rlm/prompt.py @@ -63,6 +63,17 @@ "Always assign read/search results to named variables so you can revisit " "them later." ) +EDIT_SKILL_PROMPT = ( + "For file changes that are exact replacements, prefer the pre-imported " + "`edit` skill over manual file writes. Use exactly " + "`await edit(path=\"relative/file.py\", old_str=\"\"\"old text\"\"\", " + "new_str=\"\"\"new text\"\"\")`. The target `old_str` must appear exactly " + "once. The supported keyword arguments are `path`, `old_str`, `new_str`, " + "and optional `cwd`; do not use `file`, `old`, `new`, line numbers, " + "`after`, or `insert`. If the replacement is not unique or the change is " + "too broad for an exact string replacement, then use normal Python file " + "I/O." +) def build_system_prompt( @@ -108,6 +119,8 @@ def build_system_prompt( "Each skill is also available as a shell command by the same name: ` ...`. " "Discover its CLI usage with ` --help`." ) + if "edit" in installed_skills: + skill_lines.append(EDIT_SKILL_PROMPT) if skill_lines: parts.extend(["", *skill_lines]) diff --git a/tests/test_prompt.py b/tests/test_prompt.py index 72bb761..470828f 100644 --- a/tests/test_prompt.py +++ b/tests/test_prompt.py @@ -5,6 +5,7 @@ from dataclasses import dataclass from rlm.prompt import ( + EDIT_SKILL_PROMPT, GIT_HISTORY_GUARD_PROMPT, IPYTHON_CONTROL_PROMPT, build_system_prompt, @@ -16,11 +17,15 @@ class _Tool: name: str -def _prompt(active_tools: list[_Tool]) -> str: +def _prompt( + active_tools: list[_Tool], + *, + installed_skills: list[str] | None = None, +) -> str: return build_system_prompt( "/repo", None, - [], + installed_skills or [], "/repo/.rlm/messages.jsonl", allow_recursion=False, active_tools=active_tools, @@ -62,3 +67,18 @@ def test_ipython_control_prompt_included_for_ipython_tool(): def test_ipython_control_prompt_omitted_without_ipython_tool(): assert IPYTHON_CONTROL_PROMPT not in _prompt([_Tool("bash")]) + + +def test_edit_skill_prompt_included_when_edit_is_installed(): + prompt = _prompt([_Tool("ipython")], installed_skills=["edit"]) + + assert EDIT_SKILL_PROMPT in prompt + assert 'await edit(path="relative/file.py"' in prompt + assert "`old_str` must appear exactly once" in prompt + assert "do not use `file`, `old`, `new`, line numbers" in prompt + + +def test_edit_skill_prompt_omitted_without_edit_skill(): + prompt = _prompt([_Tool("ipython")], installed_skills=["search_docs"]) + + assert EDIT_SKILL_PROMPT not in prompt