Skip to content

fix(AIC-3586): propagate tool handler errors instead of sending them to the model - #139

Merged
jeffdupont merged 1 commit into
mainfrom
fix/openai-agents-tool-error-propagation
Oct 15, 2026
Merged

jeffdupont merged 1 commit into
mainfrom
fix/openai-agents-tool-error-propagation

Conversation

@jeffdupont

@jeffdupont jeffdupont commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes AIC-3586.

Problem

openai-agents builds each tool with @openai/agents' tool() and leaves errorFunction unset. When it's unset, the SDK catches an error thrown by execute() and returns "An error occurred while running the tool. Please try again. Error: ..." to the model as the tool result. So a failing tool handler never fails the run: the model gets the error text and keeps going, and the caller never sees the error.

The shared spec says the opposite: TESTING.md §1.4, "The handler must propagate the error (not swallow it silently)." Python and Go already propagate.

Fix

  • errorFunction: null on both tool() calls: src/handler.ts and src/native-graph.ts.
  • New test in handler.test.ts and in native-graph.test.ts. Each passes the handler's arguments to the real tool() and checks that invoke() rejects. The existing test mocks tool() and calls the raw execute, which skips the SDK's error wrapper, so it couldn't catch this.
  • agents.md: the tool example shows errorFunction: null, plus a pitfall note on why it's needed.

Testing

  • All 126 openai-agents tests pass; tsc and biome are clean.
  • With only the fix reverted, exactly the 2 new tests fail: promise resolved "An error occurred while running the t…" instead of rejecting.

Not covered: a full run() against a fake model. The tests stop at tool.invoke.

🤖 Generated with Claude Code


Note

Overview
Sets errorFunction: null on every @openai/agents tool() built in the single-agent handler (buildAgentTools) and the native graph adapter (buildNodeTools). Without it, the SDK turns handler failures into a tool result string for the model and the run continues; with it, errors reject per TESTING.md §1.4 (aligned with Python/Go).

Adds integration-style tests in handler.test.ts and native-graph.test.ts that rebuild tools with the real SDK tool() and assert invoke() rejects—mock-only execute tests miss the SDK wrapper. agents.md documents the option in the wiring example and a common pitfall.

Reviewed by Cursor Bugbot for commit 82d1fc3. Bugbot is set up for automated code reviews on this repo. Configure here.

…them to the model

@openai/agents' tool() catches an execute() error and returns it to the model
as the tool result unless errorFunction is null, so a failing tool handler never
failed the run. TESTING.md §1.4 requires the error to propagate. Set
errorFunction: null in both the handler and the native graph adapter.

The existing test called a mocked tool's execute() directly, which skips the
SDK's wrapper. The new tests build the tool with the real tool() and fail
without this fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeffdupont
jeffdupont marked this pull request as ready for review October 15, 2026 20:55
@jeffdupont
jeffdupont merged commit 1f31e85 into main Oct 15, 2026
11 checks passed
@jeffdupont
jeffdupont deleted the fix/openai-agents-tool-error-propagation branch October 15, 2026 21:38
@github-actions github-actions Bot mentioned this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants