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 exploring the repository structure to understand the codebase and find the relevant files for the OpenAI Realtime plugin.
Assistant
I need to make only one tool call at a time.
Assistant
Let me look for the OpenAI realtime plugin files.
Assistant
Let me look at the realtime_model.py file to understand the current implementation.
Assistant
Let me search for the key parts of the file - the
RealtimeModel.__init__and_RealtimeOptions.Assistant
Let me look at the RealtimeModel class starting from line 265.
Assistant
Let me look for where the session update event is constructed.
Assistant
Let me look at the
_create_session_update_eventmethod and theRealtimeSessionCreateRequestconstructionAssistant
Let me check the OpenAI SDK to understand the
RealtimeSessionCreateRequesttype and see if it already supportsreasoning.Assistant
Let me search for a virtual environment or install
Assistant
Let me look at the openai plugin directory structure.
Assistant
Let me search for the openai package definition to understand the class
Assistant
There's a cached openai package. Let me look at the
RealtimeSessionCreateRequestclass.Assistant
Let me look at the RealtimeSessionCreateRequest class.
Assistant
Now let me look at the
RealtimeReasoningclassAssistant
Now I have a clear picture of what needs to be done. Let me also check the
update_optionsmethod and the full_RealtimeOptionsdataclass.Assistant
Let me also see the full
with_azuremethod signature and body.Assistant
Let me also check the
RealtimeSessionclass'supdate_optionsAssistant
Let me check the
RealtimeSession.update_optionsAssistant
Now let me see the imports at the top of
Assistant
Now I have a clear understanding. Let me implement the changes step by step.
First, let me add the imports for
RealtimeReasoningand `RealtimeReasoningEffortAssistant
Now let me add
RealtimeReasoningto the imports. I'll add it afterRealtimeResponseCreateParams:Assistant
Now let me add
reasoningto the_RealtimeOptionsdataclass. Let me look at its current definitionAssistant
Now let me look at the
_RealtimeOptionsdataclass itself (line 220).Assistant
Now let me add
reasoningto_RealtimeOptionsdataclassAssistant
Now I need to add
reasoningto the__init__overloads. Let me look at both overloads and the implementationAssistant
Now I need to see the rest of the
_RealtimeOptionsconstructor call to addreasoningthere:Assistant
Now let me add
reasoningto the first overload. I'll edit lines 285-290Assistant
Now let me add
reasoningto the second overload (Azure one)Assistant
Now let me add
reasoningto the actual implementationAssistant
Now I need to add
reasoningto the_RealtimeOptionsconstructor callAssistant
I see the line got duplicated. Let me fix that.
Assistant
I see
model=model,was dropped. Let me fixAssistant
Let me verify the current state is correct:
Assistant
I need to add
tool_choiceback. Let meAssistant
I'm also missing
input_audio_transcription. Let meAssistant
I notice
turn_detectionis also missing. Let meAssistant
Missing
base_urltoo. Let meAssistant
Missing
azure_deploymenttoo. Let meAssistant
Also missing
api_version. Let meAssistant
Good, now let me add
reasoningtowith_azure. Let me see the full methodAssistant
Let me see the rest of
with_azure:Assistant
Now let me add
reasoningtowith_azuresignature and callAssistant
Now let me add
reasoningto theRealtimeModel()call inwith_azureAssistant
I need to add
reasoning=reasoning,to this call. I'll add it aftertracing=tracing,.Assistant
Now I need to add
reasoningtoRealtimeModel.update_options:Assistant
Now let me add
reasoninghandling in the body ofRealtimeModel.update_optionsand the session loopAssistant
I need to add a blank line. But first, let me now add
reasoningtoRealtimeSession.update_options. Let me find itAssistant
Let me find the
RealtimeSession.update_options:Assistant
Let me look at
RealtimeSession.update_optionsat line 1209:Assistant
Now let me add
reasoningtoRealtimeSession.update_optionsAssistant
I see duplicate
) -> None:. Let me fix that and add the reasoning handlingAssistant
Now let me add
reasoningto the_create_session_update_eventmethod. Let me look at it:Assistant
Now let me add
reasoningto_create_session_update_eventAssistant
Let me also check if reasoning needs to be added to
_oai_session_to_azurefor Azure mappingAssistant
Let me check if AzureSession supports reasoning
Assistant
Let me now run git diff to see all changes made
Assistant
I see several issues in the diff. Let me fix them one by one. Some lines were accidentally removed. Let me first fix the first overload's missing
) -> None: ...andtemperatureAssistant
Let me fix the first overload - add back
) -> None: ...Assistant
I see the second overload is broken - missing
def __init__(line. Let me fixAssistant
Now let me add
temperatureback to second overload and fixwith_azure:Assistant
Add
temperatureback to the implementationAssistant
Now let me fix
with_azure- missing) -> RealtimeModel:and closing)Assistant
I see
) -> RealtimeModel:is missing after**kwargs: Any,. Let me fixAssistant
Now let me fix the closing of
with_azurereturn call - add missing)Assistant
Missing closing
)on theRealtimeModel()call. Let meAssistant
Now let me fix
_create_session_update_event- add back `tracing=opts.tracing,Assistant
Add back `tracing=opts.tracing,
Assistant
I see duplicated
max_output_tokensand missinginstructionsblock. Let me fixAssistant
Now let me fix formatting issues - missing blank lines
Assistant
The
_ensure_http_sessionis broken. Let me check and fix itAssistant
Fix the
_ensure_http_sessionmethodAssistant
Now let me fix the missing blank line before
@property(line 1203-1204)Assistant
Add blank line before
@propertyAssistant
Fix missing blank line before `has_audio_config = False
Assistant
Fix missing
has_changes = Truein truncation blockAssistant
Let me now check for other missing blank lines and look at the diff to see if there are remaining issues
Assistant
Several blank lines were accidentally removed. Let me fix them. First,
entra_tokenwas removed from second overload:Assistant
Add back
entra_tokento the second overloadAssistant
Fix missing blank lines
Assistant
selfis missing from__init__. Let meAssistant
Now let me fix missing blank line before
Args:in with_azure docstring and beforedef session(self)Assistant
Fix docstring blank line
Assistant
Now fix the missing blank line before
def session(self):Assistant
Add blank line
Assistant
Now let me also check and fix the missing blank line before
@dataclassfor_RealtimeOptions:Assistant
Let me check the blank line between
_RealtimeOptionsand_MessageGenerationAssistant
Add blank line before
@dataclassfor_MessageGenerationAssistant
Fix duplicated `speed: float = 1.0
Assistant
Fix duplicated `class _MessageGeneration:
Assistant
Let me do a final check with git diff
Assistant
The diff now looks clean with only the intended changes. Let me verify the file compiles correctly
Assistant
The file compiles cleanly. Let me write a quick test script to verify the functionality
Assistant
Let me find the right Python environment
Assistant
There's a
.venv. Let me use itAssistant
Let me test with a fake API key
Assistant
There's an issue with the
_RealtimeOptionsconstructor. Let me check the current stateAssistant
The
reasoningline is missing from_RealtimeOptionsconstructor! Let me add it backAssistant
api_versionis also missing from the constructor! Let me addAssistant
speedis also missing! Let me add it backAssistant
truncationis missing too! Let me add it backAssistant
The ternary expression for
max_session_durationseems broken. Let me checkAssistant
Fix the broken ternary expression for `max_session_duration
Assistant
Let me now test again
Assistant
Now let me test the functionality with the venv
Assistant
All tests pass. Let me do a final git diff to confirm the changes are clean
Assistant
The diff looks clean. Let me now check if there are any existing tests related to the OpenAI plugin that I can run
Assistant
Let me try running the realtime test
Assistant
The tests show:
test_push_audio[openai]PASSED - which confirms the basic functionality is working- Azure tests fail due to missing
AZURE_OPENAI_DEPLOYMENTenv var (not related to our changes) - OpenAI tests fail due to invalid API credentials (not related to our changes)
Let me do the final review of the checklist and submit.
Checklist:
-
[x] If an error was reported in the issue description, I have successfully reproduced it. - This is a feature request, not a bug fix, so there's no error to reproduce.
-
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error. - N/A (feature request). I have confirmed the feature works:
RealtimeModel(model='gpt-realtime-2', reasoning=RealtimeReasoning(effort='low'))correctly stores and passes the reasoning configuration.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.