Repository navigation
feat(openai): complete hosted-discovery function execution - #9085
Yafe (YAfe27) wants to merge 7 commits into
Conversation
Add a tool_search option to OpenAICompletion. When enabled on the Responses API with two or more function tools, the hosted tool_search tool is added and function tools are sent with defer_loading=True. An explicit defer_loading flag on a tool is preserved during conversion. Eager loading stays the default. Refs crewAIInc#8008
OpenAI rejects a deferred function tool unless tool_search is in the request. A single tool with defer_loading=True (or any explicitly deferred tool without the tool_search option) was sent without it. Tools without the flag are only deferred when tool_search is enabled and there are two or more of them, as before.
Verify hosted discovery and eager calls through the existing authorized tool catalog, including matching call IDs and error results. Reject non-object JSON arguments before execution instead of falling back to tool defaults. Refs crewAIInc#8125. Depends on crewAIInc#8040.
Strix Security ReviewWarning This pull request has 95 commits after the last Strix review ( ✅ No open security findings. PR summary: Adds opt-in OpenAI hosted tool search for the Responses API (`tool_search` config, `defer_loading` on function tools, request-side wiring) and makes the shared tool-argument parser reject non-object JSON so malformed arguments can no longer execute a tool with its defaults. Includes docs updates and new fake-client tests for hosted and eager tool execution. Review summaryI reviewed both production changes in this PR — the tightened The parser rewrite is a strict fail-closed improvement: every native tool-execution sink ( Three suspect paths were investigated and independently validated as non-issues: the pre-existing Ruled out (3)
Review 1 on this PR · Reviewed by Strix |
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
Related issue
Fixes #8125.
Summary
Hosted-search function calls use the existing CrewAI native execution path and the caller's authorized tool catalog. This completes the execution milestone on top of #8040 with behavioral coverage and validation of malformed arguments.
The existing executor already resolves function names and returns results under the matching
call_id. The remaining validation gap allowed JSONnullor[]to become empty arguments and execute a tool using its defaults. The shared argument parser now rejects non-object JSON before execution and returns the existing invalid-input failure with the original call ID. Valid eager function calls keep their existing behavior.The new fake Responses sequences cover successful hosted discovery followed by a function call, an unknown function advertised by discovery, malformed JSON and non-object arguments, and tool failure. The same cases run with eager loading. They check the authorized request catalog, execution counts, matching result IDs, and synchronous non-streaming behavior.
Verification
Tests added or updated for the changed behavior
Relevant tests and quality checks pass locally
286 tests passed across the hosted-execution tests, prerequisite request-building tests, existing Responses tests, agent utilities, native JSON parsing, and tool-failure tests.
The six non-object argument cases failed before the parser fix;
nulland[]executed the tool with default arguments.Ruff and formatting checks passed on our changed source and test file. Strict mypy runs through the repository's commit hook; the new test file also passes a targeted type check.
Test responses are local SDK objects with a fake client; no paid API calls or credentials are required.
Additional context
Depends on #8040, which is still open. Its original commits and authorship are included in this branch. The configuration, request builder, and translated documentation belong to that prerequisite; this contribution adds the argument-validation change and
test_hosted_tool_execution.pyin a separate final commit.Syed Ahnaf Raza (@syahra712), this uses your existing
tool_search/defer_loadinginterface unchanged. It adds no competing configuration or tool catalog. #7972's separate streaming work is not included.Prepared with OpenAI Codex assistance. The required
llm-generatedlabel needs a maintainer because this account does not have permission to apply repository labels.Note
Medium Risk
Changes the shared native tool-argument parser and OpenAI Responses request assembly; behavior shifts for non-object tool args and large tool catalogs when
tool_searchis enabled.Overview
This PR finishes hosted tool discovery on the OpenAI Responses API path and tightens how native function calls validate arguments.
Responses API
tool_search:OpenAICompletiongains opt-intool_search(normalized fromTrue/FalsetoOpenAIToolSearchConfig). When enabled with two or more function tools, requests add OpenAI’s hostedtool_searchtool and setdefer_loadingon functions (with rules for explicit flags and single-tool edge cases). Tool conversion preservesdefer_loadingfrom tool metadata. Docs in en/ar/ko/pt-BR document the new parameter.Execution path: Discovered function calls still run through CrewAI’s existing native loop against the agent’s authorized tool list (not ad-hoc definitions from the model). New
test_hosted_tool_executionexercises hosted vs eager loading for success, unknown tools, bad JSON, non-object args (null, arrays, strings), and tool failures.Argument parsing:
parse_tool_call_argsnow rejects parsed JSON that is not a object before execution, returning the sameINVALID_INPUTshape as malformed JSON—fixing cases wherenullor[]previously ran tools with defaults.Reviewed by Cursor Bugbot for commit 3c50a6f. Bugbot is set up for automated code reviews on this repo. Configure here.