fix(llm): make to_responses_fnc_ctx.provider_tool_type optional#5892
Merged
Conversation
#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>
u9g
approved these changes
May 29, 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.
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:
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`):
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
Made with Cursor