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
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
Let me start by understanding the repository structure and finding the relevant files for the OpenAI Realtime plugin.
Assistant
Let me look at the project structure more specifically. This seems to be the livekit agents repository. Let me find the relevant plugin files.
Assistant
Let me look at the main OpenAI realtime model file and explore its
Assistant
Let me look at the key parts of this file, particularly the
RealtimeModelclass and its constructor and the session update logic.Assistant
Let me look at the
__init__methods and the_create_session_update_eventmethodAssistant
Let me see the full
__init__implementation.Assistant
Let me continue reading the
__init__method.Assistant
Let me look at the
_RealtimeOptionsdataclass and the_create_session_update_eventmethod:Assistant
Let me look at the _RealtimeOptions class and the _create_session_update_event method.
Assistant
Now let me look at the
_create_session_update_eventmethod:Assistant
Let me also check the JS PR for reference on what was done there, and look at the rest of the
update_optionsmethodAssistant
Let me check what the OpenAI Python client types look like for the session update event, and look at the JS PR reference for guidance.
Assistant
Let me look at the OpenAI types in more
Assistant
Good. Now let me also check the
realtime_reasoning_param.pyand how session_create_request uses it:Assistant
Now let me check how
reasoningis used inRealtimeSessionCreateRequest:Assistant
Now let me look at the Azure session conversion to see how it handles other fields:
Assistant
Let me look at that function and also the AzureSession type:
Assistant
Let me check if AzureSession supports reasoning:
Assistant
Let me now look at the full imports section and understand how the model currently handles
truncation(since it's similar):Assistant
Let me check that
RealtimeReasoningis available in theopenai.types.realtimeAssistant
Now I have a clear picture. Let me implement the changes:
- Add
RealtimeReasoningimport - Add
reasoningto_RealtimeOptionsdataclass - Add
reasoningto both@overload__init__signatures - Add
reasoningto the actual__init__implementation - Use
reasoningin_create_session_update_event - Add
reasoningtoupdate_options
Let's start:
- Add
Assistant
Let me check the current state of the file around line 87
Assistant
Let me fix the imports. The
realtime_truncationimport was removed accidentally. Let me add it back along with reasoning.Assistant
I see the issue. I need to use the proper multi-line syntax. Let me first restore the file and then use the correct syntax.
Assistant
Let me verify the file is restored:
Assistant
Good, the file is restored. Now let me make the changes one at a time using proper syntax.
First, add the
RealtimeReasoningimportAssistant
Now add
reasoningto the_RealtimeOptionsdatAssistant
Now let me add
reasoningto the_RealtimeOptionsdataAssistant
Now add
reasoningto the first@overloadinit (OpenAI variant). Let me insert after thetruncationparameterAssistant
Now add
reasoningto the second@overload(Azure variant). I'll add it aftertruncationon line 320Assistant
Now add
reasoningto the actual__init__implementationAssistant
Now update the
_optsinitialization in__init__to includereasoning. Let me findAssistant
Now I need to add
reasoningto the_optsconstruction. Let me edit thetruncationline to add reasoningAssistant
Now update
_create_session_update_eventto include reasoning. Let me find itAssistant
Now add
reasoningto the session creation in_create_session_update_eventAssistant
I see there's a duplicate line issue. Let me fix it and also add reasoning to `update_options
Assistant
Now add
reasoningto theupdate_optionsparameter list andAssistant
Now add the reasoning handling logic after the truncation block in
update_optionsAssistant
Let me check for other places where session update events are created that might need reasoning support. Let me also check
update_instructionsand any other session update methodsAssistant
Let me also check
update_instructionsandupdate_toolsto make sure they don't need special handling. Let me look at lineAssistant
Now let me verify the changes compile correctly:
Assistant
Let me install the package first:
Assistant
Now test the import
Assistant
Just an API key issue, not related to our changes. Let me test with a dummy key
Assistant
Let me check if there's another
update_optionsmethod that'sAssistant
Let me verify the current state of the
update_optionssignatureAssistant
Let me look at the base class
update_optionsAssistant
Let me check which module is being imported - it might be the old installed version not our
Assistant
Let me verify the function signature in the loaded
Assistant
There's a cached
.pycfile. Let me clear it and retest:Assistant
Wait, I see that the signature shows
temperaturebut notreasoning. This is really strange. Let me look more carefully at the file. It could be that there's anotherupdate_optionsmethod defined somewhere else in the class hierarchy. Or maybe there's a__init_subclass__doing something.Let me check if there is a
RealtimeSession.update_optionsthat is being shown instead ofRealtimeModel.update_options.Actually, looking at the signature output more carefully:
codevoice: NotGivenOr[str] turn_detection: NotGivenOr[RealtimeAudioInputTurnDetection | TurnDetection | None] tool_choice: NotGivenOr[llm.ToolChoice | None]This order looks like the
RealtimeSession.update_optionsfrom the file, except the base class only hastool_choice. Let me check if there might be twoupdate_optionsmethods.Assistant
There are TWO
update_optionsmethods! Let me look at the one at line 656 (theRealtimeSessionAssistant
Now I see the issue. There are TWO
update_optionsmethods. TheRealtimeModelone at line 656 delegates toRealtimeSession.update_options. I need to addreasoningto BOTH.Let me update the
RealtimeModel.update_optionsat line 656:Assistant
I see a duplicate line. Let me fix it:
Assistant
Still have a duplicate. Let me fix it more precisely:
Assistant
This is getting messy. Let me restore the file and start fresh with all changes at once in a more careful manner.
Assistant
Let me write a Python script to apply all changes at once to avoid
Assistant
Now let me verify the changes:
Assistant
All tests pass. Let me also verify the session-level
update_optionsacceptsreasoning:Assistant
Both methods now have
reasoning. Let me run the existing tests to ensure nothing is broken:Assistant
The test failure is unrelated to our changes (missing dotenv). Let me verify the file syntax is correct and the overall structure is good:
Assistant
Let me run a more thorough integration test to verify session update events include reasoning:
Assistant
Let me check which class has
_create_session_update_eventAssistant
Let me verify the session-level
update_optionsworksAssistant
Let me use asyncio to test
Assistant
Let me review the final state of the file by looking at all the key changed areas:
Assistant
The diff looks clean and correct. Let me clean up the temporary patch file and run a final verification:
Assistant
Let me run one final comprehensive test:
Assistant
Let me also check the
with_azureclassmethod to see if it needsAssistant
The temp file was deleted. Let me reopen the
Assistant
Let me see the rest of the
with_azuremethod to check what it passes to the constructor:Assistant
Let me verify one more time that
RealtimeSessionCreateRequesthas areasoningfield:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.