ISSUE DESCRIPTION Add reasoning.effort support for OpenAI gpt-realtime-2 Feature Type…
- User
ISSUE DESCRIPTION
Add reasoning.effort support for OpenAI gpt-realtime-2
Feature Type
Would make my life easier
Feature Description
OpenAI
gpt-realtime-2supports configurable reasoning viareasoning.effort, but the Python OpenAI Realtime plugin does not seem to expose this option onopenai.realtime.RealtimeModel.It would be useful to support something like:
from livekit.plugins import openai llm = openai.realtime.RealtimeModel( model="gpt-realtime-2", reasoning={"effort": "low"}, )Workarounds / Alternatives
I don't think there is a clean workaround through the current Python
RealtimeModelAPI.The only workaround I can see is patching the plugin locally to add
reasoningto the session update payload.Additional Context
OpenAI docs list these effort values:
minimal,low,medium,high,xhigh.References:
- https://developers.openai.com/api/docs/models/gpt-realtime-2
- https://developers.openai.com/api/docs/guides/realtime-models-prompting#set-reasoning-effort
- Related JS issue: https://github.com/livekit/agents-js/issues/1433
- Related JS PR: https://github.com/livekit/agents-js/pull/1575
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
I'll start by exploring the repository structure and finding the relevant files for the OpenAI Realtime plugin.
Assistant
Now let me look at the
_RealtimeOptionsdataclass and the_to_oai_sessionmapping function more closely:Assistant
Now let me look at how the session update payload is built - search for where
_optsis used to build the session update:Assistant
Now let me check the
RealtimeSessionCreateRequesttype to see if it supportsreasoning:Assistant
Let me check if
RealtimeResponseCreateParamsalso supports reasoning:Assistant
Let me check existing tests for the realtime plugin:
Assistant
Let me look at the utils.py to understand the conversion helpers pattern:
Assistant
Now I have a full understanding. Let me implement the changes. First, add
RealtimeReasoningto the imports:Assistant
Now add a
to_reasoninghelper in utils.py:Assistant
Now add the
to_reasoninghelper in utils.py:Assistant
Now add the
to_reasoninghelper function afterto_noise_reduction:Assistant
Now add
reasoningfield to_RealtimeOptionsdataclass:Assistant
Now add
reasoningto the first@overload__init__:Assistant
Now the second overload:
Assistant
Now the actual
__init__method. Addreasoningparam and docstring:Assistant
There's a duplicate
) -> None:line at 359. Let me fix it:Assistant
Now add the docstring entry for
reasoning:Assistant
Now update the
_RealtimeOptionsconstruction in__init__to setreasoning:Assistant
Now update
with_azureto addreasoningparameter and pass it through:Assistant
There's a duplicate
) -> RealtimeModel:at line 527. Let me fix:Assistant
Now add docstring entry for reasoning in with_azure and update the
with_azurereturn statement to passreasoning:Assistant
Add
reasoningto thewith_azurereturn statement:Assistant
Now add
reasoningto the model-levelupdate_optionsmethod:Assistant
Now update the
_create_session_update_eventto includereasoning:Assistant
Now add
reasoningto the session-levelupdate_optionsmethod:Assistant
Now add the reasoning handling logic in the session-level
update_optionsbody. Let me view the area around the truncation handling and the end:Assistant
Fix the missing blank line at 1273-1274:
Assistant
Now let me also add reasoning to the
_oai_session_to_azuremapping function for Azure compatibility. Let me check whether the AzureSessiontype supports reasoning:Assistant
The Azure legacy
Sessiontype doesn't supportreasoning, so it will be silently ignored on the legacy path (acceptable). The newer Azure path usesSessionUpdateEventwhich does support it. Now let me write a reproduction script to verify everything works:Assistant
Tests 1-4 pass. Test 5 needs an event loop. Let me run it inside asyncio:
Assistant
All tests pass. Now let me check the Azure
with_azurepath to verify reasoning flows through correctly. Let me also verify the legacy Azure path doesn't crash when reasoning is set (it should be silently dropped):Assistant
All assertions passed ("AZURE TESTS PASSED"). The traceback at the end is from the background task trying to connect to the fake endpoint — unrelated to my changes. Now let me verify the module imports cleanly and run existing tests:
Assistant
The realtime tests require live API keys/connections. Let me run a broader smoke test to ensure nothing is broken by importing all the plugin modules:
Assistant
Now let me run the existing offline test suite that doesn't need network to ensure I haven't broken anything import-related:
Assistant
Let me fix the import ordering to be alphabetical (ruff/isort convention):
Assistant
Let me run ruff to check formatting compliance:
Assistant
Let me re-run the reproduction tests one final time to confirm everything still works after the import reorder:
Assistant
Everything works. Let me do a final review of the complete diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.