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
Let me explore the repository structure to understand the codebase and find the relevant OpenAI Realtime plugin file.
Assistant
Let me look at the key sections of the file - the options class, the init, the session update, and the update_session method.
Assistant
Now let me look at the RealtimeSession class and its session update logic, plus how session is constructed.
Assistant
Now let me look at the imports and the
RealtimeSessionCreateRequesttype to understand thereasoningfield.Assistant
The
RealtimeSessionCreateRequestalready has areasoningfield of typeOptional[RealtimeReasoning]. Let me check theRealtimeReasoningtype.Assistant
Now let me check the Azure session conversion function and look at how the JS PR handled this. Let me look at the Azure conversion.
Assistant
Now I have a good understanding. Let me implement the
reasoningsupport. I'll need to:- Add
reasoningfield to_RealtimeOptionsdataclass. - Add
reasoningparameter toRealtimeModel.__init__(both overloads and the main implementation). - Pass it to
_RealtimeOptions. - Add
reasoningto_create_session_update_event. - Add
reasoningsupport toRealtimeSession.update_optionsandRealtimeModel.update_options. - Handle Azure conversion (if Azure supports it - the legacy Azure format may not support reasoning, but let me check what AzureSession has).
- Add
reasoningtowith_azure.
Let me check the Azure session model for reasoning field.
- Add
Assistant
Azure's beta realtime session doesn't support reasoning, so it'll be silently dropped in the Azure conversion (which only maps known fields). That's fine. Now let me implement the changes.
First, add
reasoningto_RealtimeOptionsdataclass:Assistant
Let me add the import for
RealtimeReasoningandRealtimeReasoningEffort. Let me check if they're exported fromopenai.types.realtime:Assistant
Both are exported. Now let me make the edits. First, add the imports:
Assistant
Now let me open the file and make the edits:
Assistant
Now let me add
reasoningto the_RealtimeOptionsdataclass:Assistant
Now add
reasoningto the overloads and main__init__. Let me view the relevant lines again with current line numbers:Assistant
Let me look at context around each occurrence to add the
reasoningparameter. Let me check each:Assistant
Let me look at each occurrence more carefully to craft a unique replacement. Let me view all three overloads/init contexts.
Overload 1 (line 288): truncation line followed by
api_key: str | None = None,thenbase_url. Overload 2 (line 320): truncation line followed byhttp_session. Main init (line 346): truncation line followed byapi_key: str | None = None,.Let me view lines around 320 and 346.
Assistant
Now let me add the
reasoningparameter to all three__init__signatures. I'll do them one by one with unique context:Assistant
Now add a docstring entry and pass reasoning to
_RealtimeOptions. Let me find the docstring and the_RealtimeOptionsconstruction:Assistant
Now let me look at the
_RealtimeOptionsconstruction and add thereasoningfield. Let me also create a helper to normalize the reasoning input. First let me view the construction:Assistant
Let me check the utils.py to add a
to_reasoninghelper following the existing pattern:Assistant
Let me add a
to_reasoninghelper to utils.py. Let me look at the imports at the top of utils.py:Assistant
Now let me add the import for
RealtimeReasoningto utils.py and add ato_reasoninghelper. Let me update the import block in utils.py:Assistant
Now add the
to_reasoninghelper function afterto_noise_reduction:Assistant
Now import
to_reasoningin realtime_model.py and use it in the_RealtimeOptionsconstruction:Assistant
Now add the
reasoningfield in the_RealtimeOptionsconstruction:Assistant
Now add
reasoningto the_create_session_update_event. Let me view that function again with current line numbers:Assistant
Now let me handle the Azure conversion. The
_oai_session_to_azurefunction maps fields 1:1. Azure's beta session doesn't have a reasoning field, so it'll be dropped. But let me check ifAzureSession.model_constructwould error. It usesmodel_constructwhich doesn't validate, so extra fields are just ignored (pydantic models ignore extra by default unless configured). Actuallymodel_constructsets attributes — if the field doesn't exist, it would set it as a private attribute? Let me verify AzureSession doesn't have reasoning and check extra config:Assistant
Need to use the venv. Let me activate it:
Assistant
There's a subtle issue with
exclude_unset=Truein the dump. When I setsession.reasoningafter construction, pydantic may not mark it as "set". Let me verify:Assistant
Good, setting the attribute marks it as set. Now let me add
reasoningtowith_azureand theupdate_optionsmethods. Let me view thewith_azuresignature:Assistant
Now add the docstring entry and pass
reasoningto theRealtimeModel(...)call inwith_azure. Let me view the with_azure docstring and return call:Assistant
Now pass
reasoningto theRealtimeModel(...)call inwith_azure:Assistant
Now add
reasoningtoRealtimeModel.update_optionsandRealtimeSession.update_options. Let me view both:Assistant
Now let's update
RealtimeSession.update_options. Let me view it:Assistant
Now let me verify the file compiles and run a quick functional test:
Assistant
Now let me write a reproduction script to confirm reasoning flows through to the session update event:
Assistant
The opts are correct. The RealtimeSession needs a running event loop. Let me test within an async context:
Assistant
The session update event now includes the reasoning configuration. Let me also test the
update_optionspath on the session and verify Azure path drops reasoning:Assistant
Both paths work correctly. Now let me run existing tests to ensure nothing breaks:
Assistant
These tests likely require API keys/credentials. Let me check if there are any import-level tests that I can run to verify the module still imports correctly:
Assistant
These are integration tests requiring live API connections. Let me check whether they use a fake/mock server that could be run offline:
Assistant
These tests need real credentials. Let me try running one to see behavior without creds:
Assistant
These integration tests require real credentials, so they can't run here. Let me verify the xai realtime plugin (which may depend on the openai realtime module) still works with the new parameter:
Assistant
Now let me review the complete diff to make sure everything is consistent:
Assistant
The diff looks comprehensive. Let me reconsider the
to_reasoninghelper — usingmodel_validateinstead ofmodel_constructfor the dict path would validate theeffortvalue against the allowed literals, catching invalid values early. Let me update:Assistant
Now the
RealtimeReasoningEffortimport in realtime_model.py is unused. Let me remove it to avoid lint errors:Assistant
Now let me re-run the functional tests, including an invalid effort value to confirm validation works:
Assistant
All edge cases work correctly. Let me check if ruff is available and lint the changed files:
Assistant
Ruff passes. Let me also run the format check to ensure code style is consistent:
Assistant
Let me also run a broader set of offline unit tests to confirm nothing broke at import/collection time across the openai plugin:
Assistant
Let me run the mypy type-check if configured, since the repo may enforce types:
Assistant
Mypy passes. Let me verify the exact usage example from the issue works:
Assistant
The exact example from the issue works. Let me also check the
__init__.pyof the realtime module to confirmRealtimeModelis properly exported (the issue usesopenai.realtime.RealtimeModel):Assistant
Everything is in place. Let me do a final review of the complete diff:
Assistant
The diff is complete and clean. Let me verify there are no stray untracked files from my work:
Assistant
Only the two intended files are modified, with no stray files. Let me do a final comprehensive verification run of all the key behaviors:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.