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) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /agents, current file: none) bash-$
Assistant
I'll start by exploring the repository structure to understand how it's organized and find the relevant files for the OpenAI realtime plugin.
Assistant
The
opencommand doesn't need--fileprefix, let me check the correct syntax.Actually, looking at the tool definition again:
Usage: open [OPTIONS] [FILE] [LINE_NUMBER]So it should be
open FILEnotopen --file FILE. Let me try again.Assistant
Let me look at the RealtimeModel class definition and its
__init__method:Assistant
Now let me look at the
_RealtimeOptionsdataclass to see what options are currently supported:Assistant
Now let me check how session updates are sent. Let me search for where the session is created and updated:
Assistant
Let me look at the
_create_session_update_eventmethod to see how session parameters are being sent:Assistant
Now let me look at the
RealtimeSessionCreateRequestto see what fields it supports. Let me also check the OpenAI SDK types:Assistant
Great! I can see that
reasoningis a field inRealtimeSessionCreateRequest. Now let me check what thereasoningfield expects:Assistant
Perfect! Now I understand the structure. The
reasoningfield expects aRealtimeReasoningobject with aneffortattribute that can be one of:'minimal','low','medium','high','xhigh'.Let me also check the related JS PR that was mentioned in the issue to see how they implemented it:
Assistant
Let me look at the
update_optionsmethod to see what parameters it accepts:Assistant
Now let me check if there's an
update_optionsin theRealtimeModelclass as well:Assistant
Now let me look at the imports section to see what's already imported:
Assistant
Now I have a good understanding of the codebase. Let me create a plan:
Plan
- Add
RealtimeReasoningto the imports fromopenai.types.realtime.realtime_reasoning - Add a
reasoningfield to the_RealtimeOptionsdataclass - Add a
reasoningparameter to both__init__overloads ofRealtimeModel - Add a
reasoningparameter to the actual__init__implementation - Store the reasoning option in
_optsduring initialization - Include
reasoningin the session creation in_create_session_update_event - Add
reasoningparameter toupdate_optionsmethods (both inRealtimeModelandRealtimeSession) - Update the session when reasoning is changed
Let me start implementing:
- Add
Assistant
The import doesn't exist yet. Let me add it and make all the necessary changes. Let me create a script to make all the changes:
Assistant
Let me verify the changes were applied correctly:
Assistant
Good! Now let me verify the
_RealtimeOptionsinitialization includes reasoning:Assistant
Let me verify the reasoning is included in the session creation:
Assistant
Let me verify the
update_optionsmethod in RealtimeModel handles reasoning:Assistant
Now let me verify the
update_optionsin RealtimeSession handles reasoning:Assistant
Perfect! All the changes have been applied. Now let me create a test script to verify the implementation works:
Assistant
Right, I need to provide an API key. Let me update the test:
Assistant
Excellent! The tests pass. Now let me also check that the reasoning is properly included in the session update event. Let me create a more comprehensive test:
Assistant
That's expected - we can't create a session without an event loop. The basic tests are sufficient. Let me now check if there are existing tests in the repository that we should run:
Assistant
Let me check if there are any specific tests for the RealtimeModel initialization that I should be aware of.
Now let me verify the code by looking at the actual implementation to see if there are any syntax errors or issues.
Assistant
Good! The file compiles without syntax errors. Let me also check if the imports are correct by trying to import the module:
Assistant
Perfect! Now let me create a test that matches the example in the issue description to ensure it works as expected:
Assistant
Excellent! The feature is working. Now let me check if we can also support the dict syntax from the issue for convenience. Let me look at how other parameters like
tracingandtruncationare handled - do they accept dicts or only their respective types?Assistant
The pattern in the codebase is to use the typed objects directly (like
TracingandRealtimeTruncation), not dictionaries. This is consistent with the OpenAI SDK's approach. So our implementation is correct.Now let me check the
__init__.pyfile to see if we need to exportRealtimeReasoning:Assistant
The
RealtimeReasoningtype is from the OpenAI SDK, so users can import it directly from there. This is consistent with how other types likeAudioTranscriptionandTracingare used in the codebase. Let me verify this is the pattern used elsewhere:Assistant
I can see that users import from
openai.typesdirectly. Our implementation follows this pattern.Now let's run the existing tests to make sure we haven't broken anything:
Assistant
The test failures are due to missing API credentials (OPENAI_API_KEY, AZURE_OPENAI_API_KEY, etc.), not due to our code changes. This is expected in this test environment.
Let me verify that the code changes are syntactically correct and complete:
Assistant
Perfect! Let me also verify that the documentation/docstring has been updated properly. Let me check if there's a docstring in the
__init__method and update it to include reasoning:Assistant
I should add documentation for the reasoning parameter. Let me update the docstring:
Assistant
Perfect! Now let me run the final comprehensive test to make sure everything works correctly:
Assistant
The previous command was successful - all tests passed. Now I need to verify the changes once more and then submit. Let me check the git diff to see all the changes I made.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →