Summary
When an agent tool's underlying service raises a plain exception, it propagates and aborts the entire run. A capture_run_messages diagnostic caught it:
ValueError: No data found for store=1, product=101 between 2023-01-01 and 2023-06-30
The model had picked a store/product/date range with no data; tool_run_backtest -> run_backtest raised ValueError, and the run died instead of letting the model correct its inputs.
Root cause
PydanticAI turns ModelRetry exceptions into a retry prompt, but lets other exceptions propagate. The agent tool wrappers do not translate expected, input-driven ValueErrors (no data, unknown id) into ModelRetry.
Fix
Convert expected ValueErrors raised by tool service calls into ModelRetry so the model receives the error message and can retry with corrected inputs. Genuine bugs (other exception types) still propagate.
Summary
When an agent tool's underlying service raises a plain exception, it propagates and aborts the entire run. A
capture_run_messagesdiagnostic caught it:The model had picked a store/product/date range with no data;
tool_run_backtest->run_backtestraisedValueError, and the run died instead of letting the model correct its inputs.Root cause
PydanticAI turns
ModelRetryexceptions into a retry prompt, but lets other exceptions propagate. The agent tool wrappers do not translate expected, input-drivenValueErrors (no data, unknown id) intoModelRetry.Fix
Convert expected
ValueErrors raised by tool service calls intoModelRetryso the model receives the error message and can retry with corrected inputs. Genuine bugs (other exception types) still propagate.