Skip to content

Agent stopWhen stops even when tool call fails Zod validation #172

@franckdsf

Description

@franckdsf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions