Skip to content

A tool raising a plain exception crashes the whole agent run #176

@w7-mgfcode

Description

@w7-mgfcode

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions