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
Good, the SDK supports it already. Let's look at RealtimeReasoning and RealtimeReasoningEffort types.
Assistant
Now let's look at the full RealtimeModel
__init__and update_options methods, and the session update creation code to add reasoning support.Assistant
Now let's look at the RealtimeSession's update_options and
_create_session_update_eventfor constructing SessionUpdateEvent, and how session is created (line ~1160-1230).Assistant
Now add a
to_reasoninghelper function afterto_turn_detection:Assistant
Need one blank line fix (missing blank line before
def livekit_item_to_openai_item).Assistant
Now let's edit
realtime_model.py. First, add imports.Assistant
Now update the
.utilsimport to includeto_reasoning, and addRealtimeReasoningParamimport too since used in signatures.Assistant
Now add
reasoningfield to_RealtimeOptionsdataclass.Assistant
Now add
reasoningparam to both__init__overloads (first one, since only OpenAI's gpt-realtime-2 supports it, not Azure). Let's add to first overload aftertruncation.Assistant
Now update the actual
__init__implementation signature, docstring, and body to add reasoning.Assistant
Now update docstring and add the reasoning line, and update the body to pass reasoning to
_RealtimeOptions.Assistant
Now find
_RealtimeOptions(construction and addreasoning=to_reasoning(reasoning).Assistant
Now update
RealtimeModel.update_optionsto supportreasoning.Assistant
Now let's update
_create_session_update_eventto include reasoning, andRealtimeSession.update_optionsaccordingly.Assistant
Now let's update
RealtimeSession.update_optionsto acceptreasoningparam and set it on session if changed.Assistant
Now let's set up a venv and test with actual openai package installed to verify functionality.
Assistant
Package already importable within venv (likely editable install). Let's write a test script.
Assistant
Need asyncio context for session. Let's wrap in async.
Assistant
Works as expected. Now let's check
RealtimeSession.acloseexists.Assistant
Good, both model and session have aclose. Now let's check that
RealtimeSession.update_optionsinvoked directly via session (not just model) also works properly, and checksend_eventbehavior doesn't crash without connection.Assistant
Default behavior unaffected. Now let's run existing tests for the plugin related to realtime model, if any.
Assistant
These are integration tests requiring network access; not feasible to run here. Let's just make sure they at least collect without error (syntax-wise) and run a quick pytest collection.
Assistant
Good, collection works. Now let's check ruff/lint for the plugin to ensure formatting matches style used in repo.
Assistant
Let's also run ruff format check to match style.
Assistant
Let's re-run the reproduce scripts to make sure everything still works after ruff fix (import order change).
Assistant
All still works. Let's view final diff and check mypy type checking if available.
Assistant
No mypy issues. Let's view the full diff for a final review.
Assistant
This looks complete and consistent. Let's clean up temp test scripts.
Assistant
Let's also double check the CHANGELOG conventions in this repo — perhaps there's a changeset mechanism to add.
Assistant
Good — no manual changelog needed. The implementation is complete. Let's do a final full diff review and run existing repo test suite for the openai plugin quickly (unit tests not requiring network, if any).
Assistant
Only one construction site, already updated. Now let's run a final ruff/mypy check across the whole plugin package to be safe.
Assistant
All checks pass. Now let's review the checklist items.
Assistant
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. I confirmed the missing capability by inspecting the code and verifying that
RealtimeModelhad no parameter and that (from the underlying SDK) supports a field that was never being forwarded.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.