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:
pythonfrom 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 call ) 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
Good, there is a
reasoningfield. Let's inspect its type.Assistant
Now let's view lines 480-720 for update_options and how session gets built including azure path.
Assistant
Now let's find the RealtimeSession class, where
session()is created, and where session_update payload is built (line ~1160-1250).Assistant
Now I have a clear pattern to follow, mirroring
tracing. Let's now addreasoningsupport throughout: import type, add to_RealtimeOptions, add to__init__overloads/impl,with_azure,update_options(model+session),_create_session_update_event,_oai_session_to_azuremapping (Azure might not support reasoning - let's check but include field mapping conditionally), and docstrings.Assistant
Good, it's exported. Now let's add the import.
Assistant
Now need to import
Mappingin utils.py.Assistant
Now let's verify the
to_reasoningfunction is correctly placed.Assistant
Now let's edit realtime_model.py. First import
to_reasoningfrom utils.Assistant
Now add
reasoningfield to_RealtimeOptionsdataclass.Assistant
Now let's check
Anytype is imported already (yes,from typing import Any, Literal, overload). Let's verify.Assistant
Now let's view the impacted sections to add the actual logic (assigning to _RealtimeOptions, docstrings, session creation, update_options bodies).
Assistant
Good, that matches. Now let's view the impl init body to add reasoning to _RealtimeOptions and docstring.
Assistant
Now let's update docstring and _RealtimeOptions construction in the impl.
Assistant
Now let's check
with_azuresection (needs the reasoning param already inserted at line ~519, but body of with_azure doesn't pass reasoning through toRealtimeModel(...)call). Let's view.Assistant
Let's add
reasoningto docstring and to the RealtimeModel(...) call within with_azure.Assistant
Now let's handle
RealtimeModel.update_options(model-level, around former line 669+1=674 now).Assistant
This looks fine actually. Now let's check
RealtimeSession.update_options(session level) to add reasoning handling.Assistant
Now let's add reasoning handling in this session-level update_options, mirroring tracing/truncation pattern.
Assistant
Now let's update
_create_session_update_eventto includereasoningin the initial session creation.Assistant
Good —
replace(realtime_model._opts)will automatically carry overreasoningfield since it's part of the dataclass. That's fine, no further changes needed here.Now let's check
_oai_session_to_azuremapping doesn't need reasoning since it's unsupported, but let's double check that ifis_azurepath uses full session dump then reasoning included by default? Let's inspect the whole flow for is_azure but no api_version (new Azure API).Assistant
Fine, that path already handled generically. Now let's run a python compile check and write a quick script to verify session update event includes reasoning.
Assistant
First part worked (
_opts.reasoningcorrectly set). Let's wrap in asyncio to test session creation properly.Assistant
Now let's test
update_optionsat model and session level.Assistant
Now let's test session-level
update_optionsdirectly with a RealtimeReasoning object and with a dict, and test that reasoning=None clears it.Assistant
Excellent, all working. Now let's test
with_azurestill works (it should not break, even though reasoning unsupported there for legacy Azure).Assistant
Now let's run existing tests for the openai plugin realtime module.
Assistant
This test likely needs API keys/mock server; let's check if it can run offline.
Assistant
Now let's check that
to_reasoninghandles case where user passes a plainRealtimeReasoningParam/dict with invalid key gracefully via pydantic validation, and verify overall diff.Assistant
This looks complete and consistent. Now let's also update CHANGELOG if the repo uses changesets (common in this style of repo).
Assistant
Good, let's add a changeset for this feature too, following the pattern.
Assistant
Good, only one construction site, already updated. Now let's run ruff/mypy again for the whole plugin package to be thorough, and try to run the pytest for realtime tests in dry-run/collect mode (they'll likely error due to missing API keys but let's check collection works).
Assistant
Collection works fine — no syntax/import errors. These tests need real API keys to run, so we won't run them fully (network-dependent), but collection succeeding confirms the code changes don't break imports/instantiation of the fixtures.
Assistant
Everything works as expected. Let's finalize with
git diffreview and remove any leftover test artifacts (none created outside repo).Assistant
Now let's go through the checklist explicitly.
Checklist review:
-
If an error was reported in the issue description, I have successfully reproduced it. — This was a feature request, not an error report. There was nothing to "reproduce" as a bug; instead I confirmed the described gap existed (no
reasoningparameter anywhere inRealtimeModel/RealtimeSession, and noreasoningfield being sent in the session-update payload) by inspecting the source andopenaiSDK types before making changes. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. — Not applicable (feature request), but I verified the new feature works as requested:
RealtimeModel(model="gpt-realtime-2", reasoning={"effort": "low"})now stores a validatedRealtimeReasoning(effort='low')and includes it in thesession.updatepayload (_create_session_update_event), andupdate_options(reasoning=...)propagates it to live sessions, including clearing it withNone.
-
Assistant
All three assertions passed ("ALL GOOD" printed) despite the noisy connection-retry logs from
m.session()trying to actually connect to OpenAI (expected in a sandbox with no real network/API key).Assistant
-
I have thought about edge cases and made sure my fix handles them as well. Handled: dict/mapping input converted via pydantic validation (
to_reasoning), nativeRealtimeReasoningobjects passed through unchanged,Noneexplicitly clears the setting (verified above),NOT_GIVEN(default) leaves it untouched, Azure legacy session mapping doesn't includereasoning(since Azure's flatSessionschema has no such field) so it's simply omitted rather than causing a validation error, and the option is carried over correctly when a newRealtimeSessioncopies model options viadataclasses.replace. -
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Ran
ruff checkandmypyon the modified files (both pass cleanly), and ran/collectedtests/test_realtime/test_realtime.py— collection succeeds for all 49 parametrized cases (no import/signature breakage), and theopenai-parametrized tests attempt real network calls to OpenAI which fail only due to the sandbox having no valid API key/network access (pre-existing environment limitation, unrelated to this change).
-
Assistant
The implementation is complete. Let's do a final review of the full diff before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.