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
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) usinggit statusorgit diffcommands. 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
I'll start by exploring the repository structure to understand the codebase and find the relevant files for the OpenAI realtime plugin.
Assistant
Let me look for the OpenAI plugin directory and find the RealtimeModel class.
Assistant
Perfect! I found the realtime module. Let me examine the RealtimeModel class to understand its current implementation.
<tool_call> <function=open_bash_terminal> <parameter=command> cat /agents/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py </tool_call>
Assistant
I need to use the open command properly to view the file. Let me try the bash command to cat the file instead.
Assistant
So the file was created. I need to check if there's a syntax issue. Let me look at the end of the file to see if the class is properly closed, and also check if there are any indentation issues. )
<tool_call> <function=bash_terminal> <parameter=command> cd /agents/livekit-plugins/livekit-plugins-openai && python3 -c "import ast; ast.parse(open('livekit/plugins/openai/realtime/realtime_model.py').read())" 2>&1 </tool_call>
Assistant
I'm having issues with my tool calls. Let me properly format them and check the Python file for syntax errors.
Assistant
Great! The syntax is valid. Let me verify the changes I made are complete and check the git diff:
Assistant
The user is asking me to check the git diff to see my changes. The command ran but produced no output, which means either:
- There are no changes yet
- The changes aren't showing
Let me check the git status first to see what's happening.
Assistant
I see - I haven't made any changes yet. Let me start by examining the RealtimeModel class to understand how to add the reasoning.effort support.
Assistant
The user wants me to add support for
reasoning.effortin the OpenAI gpt-realtime-2 model. Let me:- First understand the current structure of the RealtimeModel class
- Look at how other options are handled (like voice, tool_choice, etc.)
- Add the reasoning.effort parameter following the same pattern
- Make sure it's passed to the session update payload
Let me start by examining the RealtimeModel class and its init method to understand the current structure.
Assistant
Let me continue reading the init method to see how the options are being processed:
Assistant
I'm examining the RealtimeModel class to understand how to add the reasoning.effort parameter. Let me continue exploring the code to understand the full structure.
So far I've seen:
- The RealtimeModel class has an init method with many parameters
- There's a _RealtimeOptions dataclass that stores the configuration
- The options are processed and stored in self._opts
Now I need to:
- Find where _RealtimeOptions is defined
- Add the reasoning parameter to _RealtimeOptions
- Add the reasoning parameter to the init method
- Pass the reasoning parameter when creating the session
Let me continue exploring the code. )
<tool_call> <function=bash_terminal> <parameter=command> cd /agents && sed -n '180,220p' livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py </tool_call>
Assistant
I need to properly format my tool calls. Let me use the bash_terminal function with proper formatting.
Assistant
Good, now I can see the
_RealtimeOptionsdataclass is defined around line 216. Let me see the full definition of this dataclass to understand all the fields.Assistant
Now I can see the
_RealtimeOptionsdataclass. I need to:- Add a
reasoningfield to the_RealtimeOptionsdataclass - Add the
reasoningparameter to the__init__method signatures (both overloads and the actual implementation) - Store the reasoning option in
self._opts - Pass the reasoning option when creating sessions
Let me first check how the session is created to see where I need to pass the reasoning parameter. Let me search for where the session update event is created. )
Now I can see the
_RealtimeOptionsdataclass. I need to add areasoningfield. Let me also check how the session is created and where the reasoning parameter should be passed. Let me search for where session updates are sent.<tool_call> <function=bash_terminal> <parameter=command> cd /agents && grep -n "session.update|RealtimeSessionCreateRequest" livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py | head -20 </tool_call>
- Add a
Assistant
Let me search for where the session is created to understand where I need to add the reasoning parameter.
Assistant
I need to find where
_create_session_update_eventis defined to see how the session is created and where I need to add the reasoning parameter.Assistant
Now I understand the structure. I can see where the
RealtimeSessionCreateRequestis created. I need to add support for thereasoningparameter. Let me first check what types are available in the OpenAI SDK for reasoning:Assistant
Let me check if there's a virtual environment or requirements file I need to use:
Assistant
The user hasn't said anything new - this is just the system showing me the result of my last command. Let me continue with my investigation. I need to activate the virtual environment and check the OpenAI SDK types for reasoning support.
Assistant
Now I can see the environment is set up. Let me check what fields are available in the RealtimeSessionCreateRequest by looking at its model fields:
Assistant
Perfect! I can see that
reasoningis already a field inRealtimeSessionCreateRequest. Now let me check what type the reasoning field expects:Assistant
Now let me check what RealtimeReasoning looks like:
Assistant
Perfect! Now I have all the information I need. The OpenAI SDK already supports the
reasoningfield with aRealtimeReasoningtype that has aneffortparameter. Now I need to:- Add a
reasoningfield to the_RealtimeOptionsdataclass - Add the
reasoningparameter to all__init__method overloads and implementation - Pass the reasoning option when creating
RealtimeSessionCreateRequest
Let me also check if there's a similar pattern in the JS PR mentioned in the issue to understand how they implemented it:
- Add a
Assistant
The grep returned nothing, which means RealtimeReasoning is not currently imported or used. I need to:
- Import RealtimeReasoning from openai.types.realtime
- Add reasoning field to _RealtimeOptions dataclass
- Add reasoning parameter to init methods
- Pass reasoning when creating RealtimeSessionCreateRequest
Let me start implementing this.
Assistant
Now I'll make the necessary changes to add reasoning support. Let me start by adding the import:
Assistant
Good, now I can see the imports. I need to add
RealtimeReasoningto the imports. Let me use the edit command to add it:Assistant
Great! Now I need to add the
reasoningfield to the_RealtimeOptionsdataclass. Let me find the exact location and add it:Assistant
The user is telling me that the command executed but didn't produce any visible output. This is likely because the Python script I ran only prints a success message, and the system is showing me the result. Let me verify that the change was made correctly by checking the _RealtimeOptions dataclass.
Assistant
Good! The reasoning field has been added to _RealtimeOptions. Now I need to add the reasoning parameter to all the init method signatures. Let me find and update them:
Assistant
I'll continue verifying and completing the reasoning.effort support implementation. Let me check the current state of the changes.
Assistant
Good! The parameter has been added to all three signatures. Now I need to:
- Store the reasoning option in
self._optsin the init method body - Pass reasoning when creating the RealtimeSessionCreateRequest
- Add documentation for the parameter
Let me find where self._opts is created and add reasoning there:
- Store the reasoning option in
Assistant
I need to properly format my tool calls. Let me check where self._opts is created and add the reasoning parameter.
Assistant
I can see where
self._opts = _RealtimeOptions(...)is created. I need to add the reasoning parameter there. Let me find the right place to insert it - it should be after truncation.Assistant
Good! The reasoning parameter has been added to the initialization. Let me verify the change and then continue with the next step - passing reasoning to the RealtimeSessionCreateRequest.
Assistant
Good! The reasoning parameter has been added to self._opts. Now I need to:
- Pass reasoning when creating RealtimeSessionCreateRequest in _create_session_update_event
- Add documentation for the reasoning parameter in the docstring
- Handle Azure compatibility if needed
Let me find where RealtimeSessionCreateRequest is created and add reasoning there.
Assistant
I can see where the RealtimeSessionCreateRequest is created. I need to add the reasoning parameter. I should add it similarly to how truncation is handled - after the initial construction, set it if it's not None. Let me add this.
Assistant
in the
_create_session_update_eventmethod. Let me verify that change and continue with adding documentation and testing.Assistant
You're right! Let me verify the change I just made and continue with the implementation.
Assistant
Great! The reasoning parameter has been successfully added to the session creation. Now I need to:
- Add documentation for the reasoning parameter in the docstring
- Add reasoning parameter to the
with_azureclass method - Handle Azure compatibility if needed
- Create a test script to verify the changes
Let me add the documentation first:
Assistant
Good! Now I need to add the reasoning parameter to the
with_azureclass method as well. Let me check that method:Assistant
You're right! Let me add the reasoning parameter to the
with_azureclass method and handle Azure compatibility.<tool_call> <function=bash_terminal> <parameter=command> cd /agents && sed -n '493,570p' livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py </tool_call>
Assistant
I need to properly format my bash command. Let me try again with the correct syntax.
Assistant
I can see the
with_azuremethod. I need to add the reasoning parameter to this method as well. Let me check the rest of the method to see where it calls the main init method.Assistant
Let me continue viewing the with_azure method to see where it ends and what parameters it passes to the main init.
Assistant
I can see the
with_azuremethod returns a RealtimeModel instance. I need to:- Add the reasoning parameter to the with_azure method signature
- Pass it to the RealtimeModel constructor call
I also see there's an
update_optionsmethod that I should also update to support reasoning.Let me add the reasoning parameter to the with_azure method and update_options method.
Assistant
Great! I've added reasoning to the with_azure method. Now I need to add it to the update_options method as well. Let me find that method and update it.
Assistant
Good, I can see the update_options method. I need to add the reasoning parameter to this method as well. Let me update it.
Assistant
Good! Now I need to update the RealtimeSession's update_options method as well to accept and handle the reasoning parameter. Let me find that method.
Assistant
There are two update_options methods - one in RealtimeModel (line 659) and one in RealtimeSession (line 1221). I need to update the RealtimeSession's update_options method as well.
Assistant
I need to check the RealtimeSession's update_options method and update it to handle the reasoning parameter. Let me view that method.
Assistant
Good, I can see the RealtimeSession's update_options method. I need to add the reasoning parameter to this method and handle it similar to how truncation is handled. Let me continue viewing to see where the method ends.
Assistant
I can see the RealtimeSession's update_options method. I need to add the reasoning parameter to this method and handle it similar to how truncation is handled. Let me update this method.
Assistant
Good! Now let me verify all the changes have been made correctly by checking the syntax of the file:
Assistant
Great! The syntax is valid. Now let me create a test script to verify that the reasoning parameter works as expected:
Assistant
The user is reminding me that I need to use tool calls. They want me to verify my changes work with actual tests. Let me run the existing tests for the OpenAI realtime module to make sure I haven't broken anything.
Assistant
The user hasn't said anything new. The system is reminding me that I need to use tool calls. I was in the middle of checking for existing tests. Let me continue by running the tests to make sure my changes don't break anything.
Assistant
The user hasn't added any new content. This is just a system reminder. I should continue with my testing. Let me check if there are any existing tests specifically for the OpenAI realtime plugin that I should run to ensure my changes don't break anything.
Assistant
The user hasn't added any new content. I'm getting a system reminder about using tool calls. Let me continue by checking the test files and running them to make sure my changes don't break anything.
Assistant
The system is telling me that I haven't included a tool call in my last response. I need to use a tool call to continue my work. Let me check the test files and run them to verify my changes work correctly.
Assistant
Great! I can see there are existing tests for the realtime module. Let me run them to make sure my changes don't break anything.
Assistant
The tests are failing because they require API keys (OPENAI_API_KEY, AZURE_OPENAI_DEPLOYMENT, etc.) which aren't set in this environment. This is expected for integration tests. The important thing is that the tests are able to import and instantiate the RealtimeModel class - they're only failing at the API key validation stage, not at import or syntax errors.
Let me create a comprehensive test that verifies the reasoning parameter works correctly without needing API keys:
Assistant
Good! All my comprehensive tests pass. Now let me check if I need to add reasoning support to the Azure compatibility layer as well. Let me examine the
_oai_session_to_azurefunction.Assistant
You're right! I need to complete my implementation. Let me add the reasoning field to the Azure compatibility layer as well.
Assistant
The user hasn't provided any feedback, which means I should continue with my implementation. I've successfully:
- Added the
reasoningparameter to the_RealtimeOptionsdataclass - Added the
reasoningparameter to all__init__method signatures (both overloads and implementation) - Stored the reasoning option in
self._optsduring initialization - Passed the reasoning to
RealtimeSessionCreateRequestwhen creating sessions - Added reasoning to the
with_azureclass method - Added reasoning to
update_optionsmethods in bothRealtimeModelandRealtimeSession - Added reasoning to the Azure compatibility layer in
_oai_session_to_azure - Added documentation for the reasoning parameter
Now I should verify that my changes are correct by:
- Checking the syntax of the file again
- Running my comprehensive tests again
- Creating a test that shows the usage example from the issue works
- Checking the git diff to see all changes
Let me do these final verification steps.
- Added the
Assistant
Great! The syntax is valid. Now let me run my comprehensive tests again and verify everything works, then show the final git diff.
Assistant
The system is reminding me that I need to use tool calls in my responses. Let me continue with verifying the implementation and showing the final git diff.
<tool_call> <function=bash_terminal> <parameter=command> cd /agents && git diff livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py | head -200 </tool_call>
Assistant
The system is telling me that I haven't included a tool call in my response. I need to make sure I'm using the bash_terminal function properly. Let me check the git diff to see all my changes.
Assistant
Good! I can see the git diff showing all my changes. The changes look comprehensive and correct. Now let me create a final test script that demonstrates the usage example from the issue to confirm it works as expected.
Assistant
I've successfully completed the implementation of reasoning.effort support for OpenAI gpt-realtime-2! Let me provide a summary of the changes made:
Summary of Implementation
Changes Made:
-
Added RealtimeReasoning import from
openai.types.realtime -
Updated _RealtimeOptions dataclass - Added
reasoning: RealtimeReasoning | Nonefield -
Updated RealtimeModel.init - Added
reasoningparameter to all method signatures (2 overloads + implementation) -
Stored reasoning in self._opts - During initialization with proper NOT_GIVEN handling
-
Passed reasoning to session - Added to
RealtimeSessionCreateRequestin_create_session_update_event
-
Assistant
Perfect! The implementation is complete. Let me verify one more time that the syntax is valid and then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.