Skip to content

fix(gateway): serialize tool choice modes as objects - #364

Merged
anbuzin merged 2 commits into
vercel-labs:mainfrom
franklbh:codex/gateway-tool-choice-clean
Nov 17, 2026
Merged

anbuzin merged 2 commits into
vercel-labs:mainfrom
franklbh:codex/gateway-tool-choice-clean

Conversation

@franklbh

Copy link
Copy Markdown
Contributor

Gateway requests currently serialize ToolChoiceMode.AUTO, NONE, and REQUIRED as strings, for example "toolChoice": "auto". Both V3 and V4 require an object such as "toolChoice": {"type": "auto"}. This corrects the shared serializer for direct modes and ToolSelection modes, preserving named-tool requests, omitted settings, and existing activeTools output.

Adds 16 parametrized cases to the existing Gateway stream tests. They exercise the real ai.stream request path with a mocked HTTP transport and synthetic tools, covering both protocols, all three modes, named tools, omission, and tool subsets without a structured-text output schema. Literal expectations reference the official V3 and V4 definitions. The activeTools assertion checks compatibility with existing SDK behavior, not Gateway protocol support.

Validation on Python 3.14.8:

  • Before the fix: the new request tests fail in 12 mode cases; four named-tool/omission controls pass.
  • uv run pytest -q tests/providers/ai_gateway: 208 passed.
  • uv run pytest -q: 1,029 passed.
  • uv run ruff format --check src tests examples, uv run ruff check src tests examples, uv run mypy src tests, and uv run ty check: passed.
  • uv run examples/.test_scripts/check-examples.py: all example mypy/ty checks passed in their own environments.
  • Plain uv run mypy still reports the same 35 existing diagnostics in three example files when checked from the root environment; no new diagnostics.

No live provider requests were made. These tests verify outgoing request serialization; live Gateway acceptance remains unverified.

@franklbh franklbh added the fix Bug fix label Nov 17, 2026
@vercel

vercel Bot commented Nov 17, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

anbuzin
anbuzin approved these changes Nov 17, 2026 •
franklbh and others added 2 commits November 17, 2026 09:59
Keep the 16 cases. Drop the checks that other tests in this file already cover.
@franklbh
franklbh force-pushed the codex/gateway-tool-choice-clean branch from 03a9ab7 to b77ff4e Compare November 17, 2026 17:59
@anbuzin
anbuzin merged commit c23df03 into vercel-labs:main Nov 17, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants