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 locate the relevant files for the OpenAI realtime plugin. Let's first get an overview.
- Assistant
Let me look for the livekit agents plugins specifically.
- Assistant
Let me look at the livekit-plugins directory for the OpenAI plugin.
- Assistant
Let me look at the OpenAI plugin directory.
- Assistant
Let me look at the structure of the openai plugin.
- Assistant
Now let me look at the realtime_model.py file which is likely where RealtimeModel is defined.
- Assistant
Let me see more of the file, especially the RealtimeModel class definition.
- Assistant
Let me see the RealtimeModel class definition and its constructor.
- Assistant
Let me continue reading the
__init__method and see where the session is created. - Assistant
Let me see the
_RealtimeOptionsdataclass to understand what fields are available. - Assistant
Let me look at the _RealtimeOptions class definition.
- Assistant
Now let me find where the session update is sent, to see how the options are used to configure the session.
- Assistant
Let me look at the
_create_session_update_eventmethod to see how the session update event is created. - Assistant
Let me check what
RealtimeSessionCreateRequestsupports: - Assistant
Let me try using the virtual environment's python.
- Assistant
I can see that
RealtimeSessionCreateRequestalready has areasoningfield of typeOptional[RealtimeReasoning]. Let me check whatRealtimeReasoninglooks like: - Assistant
Let me also check what RealtimeReasoningEffort is:
- Assistant
It's a Literal type. Let me check what it contains.
- Assistant
Now I have a clear picture. The OpenAI SDK already supports
RealtimeReasoningwitheffortthat can be one of:minimal,low,medium,high,xhigh. I need to:- Add
reasoningparameter to_RealtimeOptionsclass - Add
reasoningparameter to theRealtimeModel.__init__method (both overloads and the actual implementation) - Pass
reasoningto theRealtimeSessionCreateRequestin_create_session_update_event
Let me also check if there are other places where session updates happen that need to include reasoning:
- Add
- Assistant
Let me also check the update_config method and lines 1220, 1447, and 1461 where other session updates happen:
- Assistant
Let me look at the full
update_configmethod signature: - Assistant
Now let me also check the imports at the top to see what's already imported.
- Assistant
Now let me check if
RealtimeReasoningis importable from the openai types: - Assistant
Now let me check if the Azure session update event also supports reasoning:
- Assistant
Now let me also look at the
_oai_session_to_azurefunction to understand the Azure conversion: - Assistant
Now let me also look at the rest of the
update_optionsmethod to see the pattern used for updating settings: - Assistant
Now let me check the other places where RealtimeSessionCreateRequest is constructed:
- Assistant
Now let me check the models.py to see if
gpt-realtime-2is listed: - Assistant
Good. Now I have a complete understanding of what needs to be done. Let me implement the changes:
- Import
RealtimeReasoningfromopenai.types.realtime - Add
reasoningfield to_RealtimeOptionsclass - Add
reasoningparameter to theRealtimeModel.__init__method (all three overloads) - Pass
reasoningto_RealtimeOptionsin the constructor - Pass
reasoningtoRealtimeSessionCreateRequestin_create_session_update_event - Add
reasoningtoupdate_optionsmethod
Let me start:
- Import
- Assistant
First, let me add
RealtimeReasoningto the imports: - Assistant
Good. Now let me also check if there's a
RealtimeReasoningtype available in the Azure session: - Assistant
Now let me start making the changes. First, add
RealtimeReasoningto the imports: - Assistant
Good. Now let me add the
reasoningfield to_RealtimeOptions: - Assistant
Now I need to add the
reasoningfield to_RealtimeOptions. Let me add it with a default ofNone: - Assistant
Good. Now let me add
reasoningto the first@overloadfor OpenAI (non-Azure). Let me look at lines around the first overload: - Assistant
Now let me add
reasoningto the first overload (OpenAI): - Assistant
I see there's a duplicate
api_keyline. Let me fix that: - Assistant
I notice the first overload seems to be missing
tracing. Let me scroll up to check the full first overload: - Assistant
I see the first overload is missing
tracing. Let me fix that: - Assistant
Good. Now let me add
reasoningto the second overload (Azure): - Assistant
I see there's a duplicate
http_sessionline. Let me fix that: - Assistant
Good. Now I need to add
reasoningto the actual implementation__init__method. Let me look at the implementation: - Assistant
Now let me add
reasoningto the actual implementation: - Assistant
Good. Now let me add the
reasoningdocstring to the Args section: - Assistant
Good. Now I need to store the
reasoningin_RealtimeOptions. Let me find where_RealtimeOptionsis constructed: - Assistant
Let me see the full _RealtimeOptions creation block:
- Assistant
Now let me add
reasoningto the_RealtimeOptionsconstructor call: - Assistant
I see there's a duplicate
truncationline. Let me fix that: - Assistant
Good. Now I need to update
_create_session_update_eventto passreasoningto the session request. Let me look at that method: - Assistant
Now let me add
reasoningto theRealtimeSessionCreateRequestconstructor: - Assistant
I see there's an issue - it seems like I lost the
session.instructionsline. Let me check: - Assistant
I see the issue - the
if self._instructions is not None:line is missing its body. Let me fix that: - Assistant
Good. Now I need to add
reasoningto theupdate_optionsmethod. Let me update that: - Assistant
I see there's a duplicate
) -> None:line. Let me fix that: - Assistant
Good. Now I need to add the
reasoningupdate logic in theupdate_optionsmethod body. Let me add it after the truncation update block: - Assistant
Now let me also update the
with_azureclass method to pass throughreasoningif provided. Let me check that method: - Assistant
Let me see the rest of the
with_azuremethod: - Assistant
I notice there might be a second
update_optionsmethod. Let me check: - Assistant
There are TWO
update_optionsmethods! Let me check the first one at line 654: - Assistant
I see! There are two
update_optionsmethods. The first one (line 654) is on theRealtimeModelclass and it delegates to individual sessions. The second one (line 1211) is on theRealtimeSessionclass. I need to addreasoningto the first one as well. Let me add it: - Assistant
Now I need to add the
reasoninghandling in the body and pass it through to the session. Let me add that: - Assistant
Now I need to also pass
reasoningthrough to the session'supdate_optionscall. Let me update that: - Assistant
Now let me also check the
_oai_session_to_azurefunction to see if I need to handle reasoning there as well: - Assistant
The Azure Session doesn't have a
reasoningfield, so I don't need to add it there. Now let me verify the changes look correct by running a quick syntax check: - Assistant
Good, syntax is fine. Now let me run a more thorough check by importing the module to make sure there are no import errors:
- Assistant
Let me check the
__init__.pyfile to see what's exported: - Assistant
Let me check if
RealtimeReasoningcan accept a dict as shown in the issue description: - Assistant
Let me also test passing a dict directly:
- Assistant
Now let me verify that my changes to the
update_optionsmethod onRealtimeSessionare complete. Let me check what the current signature looks like: - Assistant
Let me check the session's update_options method:
- Assistant
Wait, I see the session's
update_optionsdoesn't havetracing. Let me check the full signature: - Assistant
I see that
tracingis used in the body (line 1248) but not in the signature. This was likely already the case before my changes. Let me verify by checking git diff: - Assistant
Let me see the full diff to verify all changes:
- Assistant
I see some issues in the diff. I accidentally removed
tool_choicefrom the second overload andtracingfrom the session'supdate_options. Let me fix these. First, let me check the current state of the second overload: - Assistant
I see the second overload is missing
tool_choice. Let me fix that: - Assistant
I see I have a duplicate
turn_detectionblock. Let me fix that: - Assistant
I see there's still a duplicate line at 316. Let me fix that:
- Assistant
Now let me fix the docstring - I need to add back
tracingwhich was removed: - Assistant
Now let me fix the session's
update_optionsmethod - I need to add backtracing: - Assistant
I need to add
tracingback to the session'supdate_options: - Assistant
I see that
reasoningis missing from the session'supdate_optionssignature. Let me add it: - Assistant
I also need to check if
RealtimeErrorEventimport was accidentally removed. Let me check: - Assistant
I see
RealtimeErrorEventis still used but was removed from imports. Let me check: - Assistant
Let me check the imports section to see if
RealtimeErrorEventwas accidentally removed: - Assistant
I see that
RealtimeErrorEventwas removed from imports and replaced withRealtimeReasoning. I need to addRealtimeErrorEventback: - Assistant
Good. Now let me run the syntax check again and verify everything is correct:
- Assistant
Good. Now let me test importing the module:
- Assistant
Good. Now let me run any existing tests to make sure nothing is broken:
- Assistant
Let me search for tests more broadly:
- Assistant
Let me check if there are any tests related to OpenAI realtime:
- Assistant
Let me check the test_realtime directory:
- Assistant
Let me look at the test_realtime.py file to see if there are any tests that might be affected by my changes:
- Assistant
Good, the tests are integration tests that require API keys. Let me run a more thorough syntax and import check:
- Assistant
All checks pass. Now let me create a simple test script to verify that the feature works as expected:
- Assistant
All tests pass. Let me also check the final diff to make sure everything looks correct:
- Assistant
Let me check the full diff to make sure there are no unintended changes:
- Assistant
The diff looks clean and correct. All changes are pure additions. Let me also check if there are any other places in the codebase that might reference the RealtimeModel parameters to ensure consistency:
- Assistant
Let me also check the main
__init__.pyto see ifRealtimeReasoningshould be exported there: - Assistant
Good, users will import
RealtimeReasoningfromopenai.types.realtimeas shown in the issue. Let me run a final comprehensive test: - Assistant
The error is expected - we can't create a session outside an async context. Let me fix the test:
- Assistant
All tests pass. Let me also clean up and check if there are any existing tests that we should run:
- Assistant
That test fails due to a missing module, not related to our changes. Let me run the tests more selectively:
- Assistant
Let me run the tests that are more relevant to our changes:
- Assistant
Let me run a broader set of tests:
- Assistant
The test failure is unrelated to my changes - it's a codec issue with audio decoding. Let me run just the basic tests that don't require special audio files:
- Assistant
All 121 tests passed. Let me clean up and check the final diff one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.