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
Now let's check the RealtimeSessionCreateRequestParam to see if it has a
reasoningfield, and view the model file's relevant sections.Assistant
Now let's view the whole realtime_model.py file's relevant sections in detail.
Assistant
Now let's view the
__init__overloads and main constructor fully.Assistant
Now let's look at how tracing/truncation are used in session updates, since reasoning should follow similar pattern.
Assistant
Now let's look at the
_create_session_update_eventmethod and the session update event for tracing/truncation to follow the same pattern.Assistant
Add
RealtimeReasoningandRealtimeReasoningEffortto imports.Assistant
Now let's add
reasoningto_RealtimeOptionsdataclass.Assistant
Now add
reasoningparam to the constructor overloads and main__init__.Assistant
Now find the second overload (Azure) and main
__init__block that needreasoningtoo. Note Azure overload lackstruncationfield already (checking earlier output).Assistant
Now update the docstring and the
_RealtimeOptionsconstruction within__init__to passreasoning. Let's view around that area.Assistant
Now add a
to_realtime_reasoninghelper function afterto_noise_reduction.Assistant
Now import
to_realtime_reasoningin realtime_model.py and use it.Assistant
Now update
_RealtimeOptionsconstruction in__init__and add docstring line, plusupdate_options(RealtimeModel level and RealtimeSession level), and_create_session_update_event.Assistant
Now the
_RealtimeOptions(...)construction:Assistant
Now update
RealtimeModel.update_optionsto addreasoningparam and propagate to sessions.Assistant
Now let's update
_create_session_update_eventto includereasoning.Assistant
Now update
RealtimeSession.update_options(the session-level one at line ~1212, now shifted).Assistant
Now let's verify the file compiles correctly and check for
Anyimport already used.Assistant
Now let's actually import the module to check for runtime errors.
Assistant
Now let's test that
_create_session_update_eventincludes reasoning correctly, and thatupdate_optionsat model level works too (without active session, since_sessionsempty it should just update opts).Assistant
Need asyncio context. Let's use asyncio.run.
Assistant
Works as expected. Now let's check
RealtimeSession.acloseexists, and let's also check forsess.update_optionsbeing called directly (unit-level) to ensurehas_changestriggers session update event properly - already tested indirectly. Let's also check existing tests in repo for realtime_model to ensure nothing broke.Assistant
No specific OpenAI realtime tests here. Let's run broader test suite quickly to make sure nothing broken (maybe test_realtime tests general abstract behavior, unrelated to openai plugin specifics).
Assistant
Same failures pre-exist without my change - confirming these are environment/config issues (missing
OPENAI_API_KEY), not caused by my edits.Assistant
Confirmed: identical failure counts (17 failed, 1 passed, 14 skipped, 18 errors) with and without my changes — these failures are pre-existing environment/network issues unrelated to my fix.
Now let's view the final diff for review.
Assistant
Excellent, mypy passes too. Now let's also verify
with_azuredoesn't need reasoning (Azure doesn't support the new nested config typically) - that's fine as the issue is specifically about OpenAI'sgpt-realtime-2. Let's double check final review of complete diff and run a more thorough reproduction test matching the exact issue example.Assistant
The exact usage from the issue now works. Let's also check invalid effort value raises an appropriate validation error (edge case).
Assistant
Good — invalid values are properly validated. Now also verify passing
reasoning=Noneexplicitly works and passing aRealtimeReasoninginstance directly works.Assistant
All edge cases behave correctly. Let's do a final full diff review.
Assistant
Now let's go through the checklist explicitly.
Assistant
Let's confirm that before the fix, passing
reasoningwould fail (to validate the reported gap existed).Assistant
Confirmed: before the fix,
reasoningwas silently swallowed by**kwargsand never sent to the API. After the fix, it's properly included.Assistant
The fix works correctly. Let me run the full relevant test suite once more and lint check for final sanity.
Assistant
All checks pass. Now let me review the checklist items with reasoning.
Checklist review:
-
If an error was reported in the issue description, I have successfully reproduced it. ✅ — The issue was a feature request (not a runtime error), but I reproduced the underlying gap: I confirmed that before my fix, passing
reasoning={"effort": "low"}toRealtimeModelwas silently swallowed by the**kwargs: Anycatch-all and never included in thesession.updatepayload sent to OpenAI (verifiedev.session.reasoningwasNoneeven after passing the parameter). -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. ✅ — After my fix,
RealtimeModel(model="gpt-realtime-2", reasoning={"effort": "low"})correctly stores a validated object and includes it in the session update event (), exactly matching the example from the issue.
-
Assistant
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. ✅ — I ran
tests/test_realtimeboth before and after my change (with and withoutgit stash), and confirmed the exact same pass/fail/error counts (17 failed, 1 passed, 14 skipped, 18 errors) in both cases — proving the pre-existing failures are due to environment/network limitations (no live OpenAI/Azure WebSocket connectivity in this sandbox) and are completely unrelated to my change. I also ranruff checkandmypyon the modified files, both passing cleanly with no new issues.
Let's do a final full diff review before submitting.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. ✅ — I ran
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.