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 and find the relevant OpenAI realtime plugin file.
Assistant
One tool call at a time.
Assistant
Now let me look at the RealtimeSession class and the session update logic where the payload is built.
Assistant
Now let me check the imports and the
RealtimeSessionCreateRequesttype to understand what fields it supports (especiallyreasoning).Assistant
RealtimeSessionCreateRequesthas areasoningfield. Let me check its type.Assistant
Let me look at the utils.py helpers to understand patterns, and check how the JS PR handled it.
Assistant
Let me view the full
_oai_session_to_azurefunction.Assistant
Let me check the Azure Session model fields to see if it has a
reasoningfield.Assistant
The Azure legacy Session doesn't have a
reasoningfield. But since it'smodel_construct, we can still add extra fields. But better to only include it for non-azure path. Actually for the Azure legacy path, since it usesmodel_constructand dumps withexclude_defaults=False, we can addmapped["reasoning"] = session.reasoningonly ifsession.reasoning is not None. But since the legacy Azure API may not support reasoning... However, the issue is specifically about OpenAI gpt-realtime-2, not Azure.Let me check the JS PR approach. Since I can't access it, I'll add reasoning support and include it in the Azure mapping too with a guard, similar to tracing. Since the Azure Session uses model_construct, adding will work in the dumped dict. But to be safe and consistent with tracing, I'll add it conditionally.
Assistant
Now let me view the rest of the session
update_optionsto add reasoning handling there.Assistant
I now have a full understanding. Let me implement
reasoningsupport. First, add ato_reasoninghelper in utils.py.Assistant
Now let me add the import and the
to_reasoninghelper in utils.py.Assistant
Now add the
to_reasoninghelper afterto_turn_detection.Assistant
Let me refine the helper to handle the BaseModel case properly and use Python's edit.
Assistant
Now I need to add the
BaseModelimport to utils.py.Assistant
Let me reorder the import for cleanliness.
Assistant
Now verify utils imports cleanly.
Assistant
Now let me edit realtime_model.py. First, add the import of
to_reasoningandRealtimeReasoning.Assistant
Now add the
RealtimeReasoningimport near the other realtime imports.Assistant
Now add the
reasoningfield to_RealtimeOptionsdataclass.Assistant
Now add
reasoningparameter to the three__init__overloads. Let me view the exact lines for the truncation param in each overload.Assistant
Lines 288, 320, 346 are the three
__init__overloads. Line 670 iswith_azure. Line 1221 isRealtimeModel.update_options. Wait, I need to check which lines belong to which function. Let me look at each.Actually the issue: 288, 320, 346 - these are in the two overloads (288 in first overload, 320 in second overload) and the main
__init__at 346. Wait there are 3? Let me check - there are 2 @overload and 1 main init. So 288 (overload 1), 320 (overload 2), 346 (main init).Line 670 is in
with_azure. Line 1221 is inRealtimeModel.update_options.And the RealtimeSession.update_options has truncation too. Let me grep again to find all.
Assistant
Let me look at the
with_azureand RealtimeSessionupdate_optionssignatures fully.Assistant
I'll do a global replacement to add the
reasoningparameter to all signatures, then handle each body separately.Assistant
Now add
reasoningto the docstring of the main__init__. Let me view the docstring section for truncation.Assistant
Now add
reasoning=to_reasoning(reasoning)to the_RealtimeOptions(...)construction.Assistant
Now add reasoning to
_create_session_update_event. Let me view it.Assistant
Now add reasoning to
_oai_session_to_azuremapping.Assistant
Now add
reasoning=reasoningto thewith_azureRealtimeModel constructor call.Assistant
Line 650 is in the
with_azurereturn RealtimeModel(...) call. I need to addreasoning=reasoning,there. Let me check the context around 650.Assistant
Now add the reasoning docstring to
with_azure's docstring.Assistant
Now handle the
RealtimeModel.update_optionsbody (propagate to sessions). Let me view it.Assistant
Now handle the
RealtimeSession.update_optionsbody. Let me view it.Assistant
Let me reconsider the RealtimeSession.update_options reasoning handling to match the existing
tracingpattern (which sets the field directly even when None). Let me simplify.Assistant
Now let me verify the module imports cleanly and write a reproduction test.
Assistant
Now let me test that the session update event includes reasoning, both for OpenAI and Azure.
Assistant
Creating a session needs a running event loop and would attempt a websocket connection. Let me check existing tests for how they test the session update payload.
Assistant
These are integration tests requiring API keys. Let me verify the payload logic directly via the module-level helpers.
Assistant
Let me check the RealtimeSession
__init__andsend_eventto see if I can testupdate_optionswithout a live connection.Assistant
Let me write an async test that mocks
_main_taskandsend_eventto testupdate_optionsreasoning propagation.Assistant
All paths work. Let me run lint/type checks on the changed files if configured.
Assistant
Let me auto-fix import sorting with ruff.
Assistant
Let me check the
with_azuresignature to confirmreasoningparam was added.Assistant
That's the
with_azure's return RealtimeModel call (line 648-657). Thedef with_azureis earlier. Let me look at the with_azure signature to confirm reasoning param.Assistant
with_azuredoes NOT have atruncationparam, so the global replace skipped it — but I referencedreasoningin its body. I need to add areasoningparam to thewith_azuresignature. Let me view it.Assistant
with_azurehastracingbut nottruncation. Let me addreasoningaftertracingin thewith_azuresignature.Assistant
Now let me run mypy with the pydantic plugin on the changed file.
Assistant
Let me re-run my full verification suite after the auto-fix.
Assistant
Let me do a compile check across the openai plugin package to ensure nothing is broken.
Assistant
Now let me review the complete diff to make sure everything is consistent.
Assistant
The diff looks complete and consistent. Let me clean up temp files and do a final lint check.
Assistant
Both ruff and mypy pass. Let me verify the
__init__.pyre-exports are unaffected and do a final import sanity check.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.