Repository navigation
Return invalid tool arguments to the model instead of failing the workflow - #92
Merged
brianstrauch merged 3 commits intoOct 19, 2026
Conversation
avanish-garg
marked this pull request as ready for review
October 15, 2026 09:03
brianstrauch
left a comment
Member
There was a problem hiding this comment.
Two suggestions: make failure_error_function=None fail the workflow promptly, and add workflow-level coverage for corrected tool calls and async error callbacks.
avanish-garg
force-pushed
the
fix/openai-agents-tool-argument-errors
branch
from
October 16, 2026 09:08
f67e2d7 to
1fbc9af
Compare
Contributor
Author
|
Thanks @brianstrauch! |
…kflow activity_as_tool and nexus_operation_as_tool validated model-supplied arguments inside the workflow without handling errors. A missing or wrong-typed argument, or a JSON list, raised a pydantic ValidationError that the Agents SDK wraps in a UserError. That is not a Temporal failure exception, so the workflow task failed and was retried indefinitely. Arguments that were not valid JSON raised an ApplicationError that failed the whole workflow. Parse and validate the arguments the way function_tool does and return the error text to the model as the tool output so it can retry. Errors raised by the activity or Nexus operation itself are unchanged. An empty input string is now treated as no arguments, as in function_tool. Add a failure_error_function parameter to both functions to customize the error text. It defaults to the Agents SDK's default_tool_error_function and raises the error if None.
…e model With failure_error_function=None, activity_as_tool and nexus_operation_as_tool re-raised ModelBehaviorError. The Agents SDK passes that through unwrapped, and the plugin does not treat it as a workflow failure, so the workflow task was retried until the execution timed out. Raise a non-retryable ApplicationError of type ModelBehaviorError instead, which the Agents runner surfaces as an AgentsWorkflowError and fails the workflow. Add workflow-level tests for both tools covering a corrected call after an invalid one, failure_error_function=None, and an async failure_error_function.
With failure_error_function=None, an invalid tool call fails with a non-retryable ApplicationError, but the runner rewrapped it as an AgentsWorkflowError, which serializes as retryable. A Workflow retry policy therefore reran the whole agent run for a failure marked non-retryable. When the cause is a non-retryable ApplicationError, the runner now raises a subclass of AgentsWorkflowError that serializes as non-retryable. The failure type and message are unchanged, and all other failures keep their retryability.
avanish-garg
force-pushed
the
fix/openai-agents-tool-argument-errors
branch
from
October 19, 2026 09:19
1fbc9af to
15520c1
Compare
brianstrauch
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was changed
_parse_tool_argumentsinworkflow.py, mirroring the Agents SDK'sfunction_toolparsing: bad JSON, anon-object payload and pydantic
ValidationErrorbecomeModelBehaviorErrorwith the same messages as a stockfunction tool.
run_activity(activity_as_tool) andrun_operation(nexus_operation_as_tool) catch only thatModelBehaviorError, around the parse step alone, and return the formatted text as the tool output. Theactivity or operation is not run for bad arguments.
With failure_error_function=None, an invalid tool call fails the workflow promptly with a non-retryable ApplicationError of type ModelBehaviorError. The Agents runner surfaces it as an AgentsWorkflowError, the same shape as other tool failures. It does not retry the workflow task, and the model never sees the error.
AgentsWorkflowError), andthe successful path is unchanged.
{}, as a stockfunction_tooldoes (a zero-parameter tool runs; atool with required parameters gets the validation error). Before, it failed the workflow.
Why?
One malformed model call (missing/wrong-typed argument, JSON list, not JSON) either retried the workflow task
until the execution timeout or failed the whole workflow, where a normal
@function_toollets the model recover.The conversion happens inside
on_invoke_toolbecause the SDK's own error wrapper only applies to tools built byfunction_tool, and it would also swallow activity errors, which must keep their current behaviour.Checklist
Closes [Bug] openai_agents: activity_as_tool / nexus_operation_as_tool fail or wedge the workflow when the model sends invalid tool arguments #91
How was this tested:
New
tests/test_openai_tool_argument_errors.py(35 tests): eight bad-input shapes foractivity_as_toolandfive for
nexus_operation_as_tool(the workflow completes and the model receives the error text; theactivity/operation is not run), text equality with a stock
function_toolin redacted and unredacted modes,custom and
Nonefailure_error_function, the parsing helper, and regressions (valid arguments in four shapes,an activity that raises still fails the workflow). On
main, 20 of the 26 selected tests fail(
Workflow timed out/AgentsWorkflowError); the 6 that pass are the regressions.make lintis clean andmake testpasses (311). Only openai-agents 0.22.0 (the pinned range) was checked.Any docs updates needed?
The docstrings of both functions describe the new parameter. The README is not changed.