Skip to content

Commit 12b74b5

Browse files
fix: avoid bash commands that may not be installed
Agent runs picked `file` to inspect template readability and hit exit 127 `/bin/sh: 1: file: not found`. The bash tool guidance only covered using dedicated tools over cat/sed/grep, with no rule about missing commands. Tell the model to inspect file existence/readability with ReadFile or basic commands (`ls -l`, `stat`, `head`), and to switch away from a command that exits 127 instead of retrying it.
1 parent d470b40 commit 12b74b5

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/iac_code/agent/system_prompt.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ def _build_tools_section() -> str:
187187
" - Glob instead of find/ls\n"
188188
" - Grep instead of grep/rg\n"
189189
"- Reserve Bash exclusively for system commands and terminal operations.\n"
190+
"- To inspect whether a file exists or is readable, use ReadFile, or basic Bash commands "
191+
"such as `ls -l`, `stat` or `head`. Do not rely on commands that may not be installed, "
192+
"such as `file`.\n"
193+
"- If a Bash command exits with 127 or `not found`, the command is missing from this "
194+
"environment. Switch to a basic command or a dedicated tool instead of retrying it.\n"
190195
"- When calling multiple independent tools, make all calls in parallel.\n"
191196
"- Read files before modifying them.\n"
192197
"- Use EditFile for surgical edits to existing files.\n"

‎tests/agent/test_system_prompt.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
SystemPromptBuilder,
1212
_build_cloud_config_section,
1313
_build_environment_section,
14+
_build_tools_section,
1415
build_base_sections,
1516
build_system_prompt,
1617
split_by_dynamic_boundary,
@@ -437,3 +438,15 @@ def test_section_priorities_has_all_keys(self):
437438
def test_unknown_section_key_ignored(self):
438439
result = build_base_sections(["identity", "nonexistent_section"], cwd="/tmp")
439440
assert "Infrastructure as Code" in result
441+
442+
443+
class TestBuildToolsSection:
444+
def test_file_inspection_prefers_basic_commands(self):
445+
result = _build_tools_section()
446+
assert "`ls -l`, `stat` or `head`" in result
447+
assert "such as `file`" in result
448+
449+
def test_missing_command_exit_code_guidance(self):
450+
result = _build_tools_section()
451+
assert "exits with 127" in result
452+

0 commit comments

Comments
 (0)