Summary
list_dir raised FileNotFoundError on non-existent directories, which @base_tool wrapped as ToolExecutionError. Since ToolExecutionError is in NON_RETRYABLE_ERRORS, the agent halted instead of letting the LLM self-correct with a valid path.
Context
Surfaced when agent called list_dir("/home/tuna/tunacode/apps") - a directory that doesn't exist. Agent crashed with ToolExecutionError instead of retrying.
Root Cause
Error propagation chain:
list_dirraisesFileNotFoundError@base_tooldecorator wraps it asToolExecutionErrortool_executor.pyhasToolExecutionErrorinNON_RETRYABLE_ERRORS- Non-retryable errors propagate immediately, halting the agent
First attempted fix: switch to @file_tool decorator. Failed because @file_tool expects required filepath positional arg, but list_dir has optional directory=".".
Changes
- Import
ModelRetryfrompydantic_ai.exceptions - Replace
raise FileNotFoundError(...)withraise ModelRetry(...) - Replace
raise NotADirectoryError(...)withraise ModelRetry(...) - Keep
@base_tooldecorator (not@file_tool)
Behavioral Impact
- Agent no longer halts on bad directory paths
- LLM receives retry signal with error message, can self-correct
- No change to valid path behavior
Related Cards
- [[glob-grep-error-strings]] - similar smell: return error strings instead of raising