Skip to content

fix(llm): make to_responses_fnc_ctx.provider_tool_type optional#5892

Merged
u9g merged 1 commit into
mainfrom
brian/fix-to-responses-fnc-ctx
May 29, 2026
Merged

fix(llm): make to_responses_fnc_ctx.provider_tool_type optional#5892
u9g merged 1 commit into
mainfrom
brian/fix-to-responses-fnc-ctx

Conversation

@toubatbrian
Copy link
Copy Markdown
Contributor

@toubatbrian toubatbrian commented May 29, 2026

Summary

Fixes a regression that's been red on `main` CI since #5865 + #5884 landed back-to-back.

#5865 added a required keyword-only `provider_tool_type` to `to_responses_fnc_ctx`, but `ToolContext.parse_function_tools` forwards `**kwargs` blindly:

elif format == "openai.responses":
    return _provider_format.openai.to_responses_fnc_ctx(self, **kwargs)

So any caller that goes through `parse_function_tools("openai.responses")` without explicitly threading `provider_tool_type` hits a `TypeError`. #5884 landed exactly such a caller (the new `test_serialized_tool_order_is_sorted`):

for fmt in ("openai", "openai.responses", "anthropic", "aws", "google"):
    names = [tool_name(fmt, s) for s in ctx.parse_function_tools(fmt)]

Result: `tests/test_tools.py::TestToolContext::test_serialized_tool_order_is_sorted` fails on every CI run (e.g. run on `6d50c5da`).

Fix

Make `provider_tool_type` optional (`type[ProviderTool] | None = None`) and gate the provider-tool `isinstance` branch on its presence. Behavior is unchanged for legitimate callers — the openai.responses plugin always passes `provider_tool_type=self._llm._provider_tool_type`; the `None` path just emits function-tool schemas, which is the right thing for generic serialization where no provider-tool subtype is in scope.

Also widens the matching `@overload` signature in `tool_context.py` so static callers see the same default.

Test plan

  • `uv run pytest tests/test_tools.py` → 49 passed (was 1 failed on main)
  • `uv run ruff check` / `ruff format --check` → clean
  • `uv run mypy -p livekit.agents.llm` → clean

Made with Cursor

#5865 added a *required* keyword-only `provider_tool_type` to
to_responses_fnc_ctx, but the dispatcher in `ToolContext.parse_function_tools`
just forwards `**kwargs` blindly:

    elif format == "openai.responses":
        return _provider_format.openai.to_responses_fnc_ctx(self, **kwargs)

So any caller that goes through `parse_function_tools("openai.responses")`
without explicitly threading provider_tool_type hits a TypeError. #5884
landed exactly such a caller (the new `test_serialized_tool_order_is_sorted`),
and main CI has been red on `tests/test_tools.py` since both PRs landed.

Make `provider_tool_type` optional with a `None` default and gate the
provider-tool isinstance branch on its presence. Behavior is unchanged
for legitimate callers (the openai.responses plugin always passes
`provider_tool_type=self._llm._provider_tool_type`); the `None` path
just emits function-tool schemas, which is the right thing for generic
serialization where no provider-tool subtype is in scope.

Verified:
- `uv run pytest tests/test_tools.py` -> 49 passed (was 1 failed)
- `uv run ruff check` / `ruff format --check` -> clean
- `uv run mypy -p livekit.agents.llm` -> clean

Co-authored-by: Cursor <cursoragent@cursor.com>
@chenghao-mou chenghao-mou requested a review from a team May 29, 2026 18:14
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@u9g u9g merged commit b903849 into main May 29, 2026
26 checks passed
@u9g u9g deleted the brian/fix-to-responses-fnc-ctx branch May 29, 2026 18:19
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