-
Notifications
You must be signed in to change notification settings - Fork 61
Description
Hey,
When using stopWhen with hasToolCall(...), the agent stops execution even when the tool call fails argument validation (e.g., Zod returns an error).
In this case, the tool call never actually succeeds, but the agent transitions to a stopped state (output-available) instead of retrying or handling the validation error gracefully.
Example setup
stopWhen: [
hasToolCall("generateImage"),
],Observed behavior
If the agent calls a tool with invalid arguments (e.g., the Zod validator rejects it), the stopWhen condition still triggers, stopping the agent.
Example state:
State:
output-available
Type:
tool-generateImage
Arguments:
-- invalid / malformed --
Return Value:
"ArgumentValidationError: Value does not match validator.\nPath: .id\nValue: \"kn...??\"\nValidator: v.id(\"images\")\n\n"
Expected behavior
The agent should not stop when the tool call fails validation.
Instead, it should:
- Recognize the tool call as unsuccessful, and
- Retry or continue reasoning to produce a valid tool call.
Only successful tool calls (i.e., those that pass validation and run) should trigger hasToolCall(...) conditions inside stopWhen.
If the tool returns an error, that’s a separate issue; however, the agent should attempt to call the tool again when the initial invocation fails.