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 then find the relevant files for the OpenAI Realtime plugin.
Assistant
Let me find the livekit plugins directory specifically.
Assistant
Let me look at the key files for the realtime plugin
Assistant
Let me just open one file at a time.
Assistant
Let me look at the RealtimeModel class definition to understand its structure.
Assistant
Let me look at the
_create_session_update_eventmethod and the__init__method.Assistant
Let me use the scroll_down and grep approach instead.
Assistant
Now let me see the
_create_session_update_eventmethod and how the session is constructedAssistant
Let me look at the
update_optionsmethod and the options class to understand the full picture.Assistant
Let me check the OpenAI types for
RealtimeSessionCreateRequestto see ifreasoningis already supported there.Assistant
Let me look at the definition of RealtimeSessionCreateRequest to see if it already has a reasoning field.
Assistant
The OpenAI SDK already has
reasoningsupport inRealtimeSessionCreateRequest. Let me check theRealtimeReasoningtype.Assistant
Let me check the
RealtimeReasoningEfforttypeAssistant
Let me find where the options class/struct is defined for the realtime model
Assistant
Let me look at the dataclasses defined near line 218 onwards
Assistant
Now let me look at the actual implementation of
__init__(the non-overloaded one)Assistant
Now let me check what imports already exist and also look at the
session_update_eventnear line 1440 to understand session update flowAssistant
Let me view the two overloaded
__init__signaturesAssistant
Let me see the full
update_optionsmethod more closely to understand how session updates work thereAssistant
Now I have a complete understanding. Let me implement the changes.
First, let me add the
RealtimeReasoningimport:Assistant
Let me use sed to make the edits
Assistant
Now let me add the import:
Assistant
Now let me add
reasoningto the_RealtimeOptionsdataclass:Assistant
Add
reasoningto_RealtimeOptionsaftertruncation:Assistant
Now add
reasoningparameter to the first@overloadinit. Let me find the exact line numbers:Assistant
Add
reasoningparameter to the first overload aftertruncation:Assistant
Now let me add
reasoningto the second overload. Let me check its line numbers:Assistant
Add
reasoningparameter to the second overload aftertruncation:Assistant
Now add
reasoningto the actual implementation__init__. Let me check the line numbers:Assistant
Add
reasoningto the actual implementation aftertruncation:Assistant
Now I need to store
reasoninginself._opts. Let me find the exact line where truncation is stored:Assistant
Add
reasoningto the_RealtimeOptionsconstructor call aftertruncation:Assistant
Now include
reasoningin_create_session_update_event. Let me find it:Assistant
Add
reasoningtoRealtimeSessionCreateRequestin_create_session_update_event:Assistant
Now add
reasoningto theupdate_optionsmethod. Let me find its current signature and body:Assistant
Add
reasoningparameter toupdate_optionssignature:Assistant
Now add the reasoning handling code in
update_optionsbody, after thetruncationblock:Assistant
Let me verify all the changes look correct:
Assistant
I notice the
reasoningfield in_RealtimeOptionswas placed afterapi_keyinstead of aftertruncation. Let me fix the ordering:Assistant
Let me fix the positioning of
reasoningin_RealtimeOptions:Assistant
Let me verify the
update_optionsbody for proper indentation:Assistant
Let me clean up the blank line:
Assistant
Let me now verify the entire set of changes looks correct:
Assistant
Let me add a blank line after the reasoning block in
update_options:Assistant
Now let me verify the file is still syntactically valid:
Assistant
The file compiles. Let me check if there are any tests for the OpenAI realtime plugin:
Assistant
Let me create a quick test script to verify the changes work:
Assistant
Let me use the virtual environment:
Assistant
Let me check the current state of
update_options:Assistant
There are two
update_optionsmethods! Let me check both:Assistant
Let me understand which class each
update_optionsbelongs to:Assistant
Let me check the indentation context around both methods:
Assistant
Let me check if there's a nested class:
Assistant
I need to also modify
RealtimeModel.update_optionsat line 656. Let me look at itAssistant
Now I need to add
reasoningto theRealtimeModel.update_optionsmethod at line 656 as well. Let me do that:Assistant
Now add the handling code for
reasoninginRealtimeModel.update_options:Assistant
Now add
reasoningto thesess.update_options(...)call:Assistant
Let me verify the
RealtimeModel.update_optionschanges:Assistant
Let me also check the
RealtimeSession.update_optionsand look at thewith_azureclassmethod:Assistant
I see there's a duplicated reasoning block in
RealtimeSession.update_options. Let me fix it:Assistant
Let me find the exact duplicate lines:
Assistant
I need to remove the first duplicate block (lines 1262-1264):
Assistant
Let me verify the fix:
Assistant
Good. Let me verify the file still compiles and run the test script
Assistant
Now let me run my full test again
Assistant
Let me check if the
with_azureclassmethod also needs updating:Assistant
Let me also check if there are any existing tests for the Openai realtime plugin:
Assistant
Let me look at the final diff of all changes:
Assistant
Let me verify the user's example from the issue works:
Assistant
Let me check the
__init__.pyfor the realtime module:Assistant
Let me also check if there's an initial session create that might need reasoning:
Assistant
Everything looks good. Let me do a final comprehensive verification:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.