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, the underlying openai SDK already supports
reasoning. Now let's look at the full realtime_model.py to add support.Assistant
Now let's view the full realtime_model.py file to plan the edits.
Assistant
Now let's look at the constructor overloads and main body in full, lines 265-720.
Assistant
Now let's view the with_azure classmethod and update_options method and session creation code around 1140-1300.
Assistant
Now let's view the RealtimeSession class where session update options happen (around 1140-1300), and where session create request is built.
Assistant
Good, confirms
tracingisSessionTracingtype in legacy but noreasoningfield there - so legacy Azure doesn't support reasoning, which is expected since it's a gpt-realtime-2-only feature. Now let's implement the changes.Assistant
Now let's edit imports.
Assistant
Now let's add a helper
to_reasoningconversion function in utils.py, similar toto_turn_detection/to_noise_reduction.Assistant
Now add
to_reasoningfunction afterto_turn_detection.Assistant
Now insert
to_reasoningfunction after line 130.Assistant
I need to use heredoc syntax properly for edit command.
Assistant
Need to add two blank lines before
def livekit_item_to_openai_item.Assistant
Good, utils.py is done. Now update realtime_model.py to import
to_reasoningand add the reasoning option support throughout.Assistant
Looks correct; maybe whitespace mismatch (perhaps trailing spaces). Let me try with sed directly instead.
Assistant
Now update
_RealtimeOptionsdataclass to addreasoningfield.Assistant
Now let's add
reasoningparameter to both__init__overloads and the actual__init__.Assistant
Looks like normal text. I'll just use
editwith line ranges directly since replace tool seems inconsistent. Let's insert reasoning param line by line usingedit LINE:LINE.Assistant
Now add the reasoning handling logic inside this update_options body (after the tracing block).
Assistant
Good. Now update
_create_session_update_eventto include reasoning field.Assistant
Oops, my line range was miscalculated -- messed up the audio config block. Let me fix lines 1171-1192.
Assistant
Good, this section is fixed now. Now update
RealtimeModel.update_options(line ~670) andwith_azure(~516) and the three__init__signatures (288/320/346). Let's find current line numbers again since file has grown.Assistant
Now let's edit RealtimeModel.update_options at line 670.
Assistant
There's leftover duplicate lines 718-723. Let me remove them.
Assistant
Good, that's clean now. Now let's add the
reasoningparam towith_azureclassmethod. Let's find current line numbers.Assistant
Let's add reasoning param to
with_azuretoo, for completeness (some Azure endpoints may support gpt-realtime-2 with reasoning in future).Assistant
Now update the docstring line for tracing to add reasoning doc, and update the return RealtimeModel(...) call to pass reasoning through.
Assistant
Now update the
return RealtimeModel(...)call in with_azure.Assistant
Now let's update the two
__init__overloads and the actual__init__method (originally lines 288, 320, 346). Let's re-grep current line numbers.Assistant
Good, lines 288/320/346 unchanged. Insert reasoning after each, going bottom to top.
Assistant
This is the main
__init__. Let's also update its docstring line and add reasoning to_RealtimeOptions(...)construction below.Assistant
Now let's find
_RealtimeOptions(constructor call to addreasoning=to_reasoning(reasoning).Assistant
Now the first overload (line 288).
Assistant
All three signatures are updated now. Let's also check the
_oai_session_to_azurefunction to include reasoning mapping (in case new-style Azure supports it, but legacy Azure session type doesn't have that field). Let's check ifAzureSessionhas "reasoning" attribute.Assistant
Syntax is fine. Let's check whether openai package is now available in the venv and try importing the module directly.
Assistant
Now let's write a quick reproduction/test script exercising the new
reasoningparam end-to-end (constructing model with reasoning dict, checking_opts.reasoningand the generated session update event contains reasoning).Assistant
Need asyncio context for session creation. Let's wrap in async function.
Assistant
Excellent! Everything works as expected. Now let's check RealtimeSession's own
update_optionsto make sure passing reasoning triggers a session update event properly.Assistant
Now let's run the existing test suite for the openai plugin to make sure nothing is broken.
Assistant
These require actual API keys, likely skipped in CI without network. Let's check for a livekit-plugins-openai specific test directory.
Assistant
Confirmed this is a pre-existing baseline behavior unrelated to my change (missing credentials). Let's set a dummy API key and see if more of the test collection can pass (mocked network calls?), just to gain more confidence.
Assistant
All checks pass. Now let's format with ruff format to keep consistent style (line lengths etc.), since some new lines might be long.
Assistant
Diff looks clean. Let's view rest of diff.
Assistant
The diff looks complete and correct. Let's run ruff check again on the whole plugin dir to make sure nothing else broke.
Assistant
Now let's re-run our earlier manual reproduction script once more to double check everything still works after formatting changes.
Assistant
All assertions pass, confirming the feature works correctly including edge cases (dict, model instance, bare string, None, and default unset). Let's do a final review of the full diff.
Assistant
Now let's review the checklist items carefully.
Assistant
This diff comprehensively adds
reasoningsupport throughout theRealtimeModelAPI: constructor overloads,with_azure,update_optionsat both model and session level, and session creation event building. Let's also checkRealtimeReasoningEffortimport isn't unused anywhere and check CHANGELOG conventions in the repo (some repos require changesets).Assistant
Let's add a changeset for this feature following the same convention.
Assistant
Now let's do a final comprehensive check: re-run ruff, run the reproduction script once more, and check
git status.Assistant
Now
git diff(unstaged) picks up the new file properly via intent-to-add. Let's verify content is fully shown.Assistant
Everything is now correctly set up for submission. Let's do one more final verification run of the reproduction test to be completely sure before submitting.
Assistant
Now let's go through the checklist explicitly:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.