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) 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.
Assistant
Let me look at the structure of the realtime_model.py in more detail to find the right place to add the reasoning effort support.
Assistant
Let me look at how the responses/llm.py handles the reasoning field:
Assistant
Now let me see the full structure of the realtime_model.py file to understand its options and constructor:
Assistant
Let me see the
RealtimeModelclass, its__init__method, and where session.update is sent:Assistant
Let me check the OpenAI Realtime type to see what the reasoning effort field looks like:
Assistant
Let me check the existing JS PR mentioned in the issue for reference (since I can't access GitHub from here, I'll rely on the existing pattern in the responses/llm.py):
Assistant
Good - the
RealtimeReasoningtype andRealtimeReasoningEffortare both exported. Let me look at the Azure session create request to confirm reasoning is not there:Assistant
Now let me look at the models.py to see if it lists
gpt-realtime-2:Assistant
Now let me check the realtime module's init.py:
Assistant
Now let me look at the tests:
Assistant
Let me see how existing tests work to understand if I should be concerned about adding new tests:
Assistant
Now I have a clear understanding. Let me look at the full
_create_session_update_eventmethod and the_RealtimeOptionsdataclass to understand exactly where I need to add the changes:Assistant
Let me see if RealtimeResponseCreateParams has reasoning too:
Assistant
Now I have enough understanding. Let me set up a plan:
- Add
reasoningfield to_RealtimeOptionsdataclass - Add
reasoningparameter toRealtimeModel.__init__ - Pass
reasoningto session update event in_create_session_update_event - Add
reasoningtoupdate_optionsof bothRealtimeModelandRealtimeSession - Add helper to convert dict input to
RealtimeReasoning
Let me first write a script to reproduce the current state and verify the missing feature:
- Add
Assistant
Interesting! The
reasoningis silently absorbed by**kwargsand does nothing. Let me check what is actually being sent in the session update event:Assistant
Let me look at the utils.py for relevant helper functions:
Assistant
Let me check the available models:
Assistant
Now I'll start making changes. First, let me add the import for
RealtimeReasoning:Assistant
Now let me make changes step by step.
Step 1: Add import for
RealtimeReasoningAssistant
Now let me add the import for
RealtimeReasoning:Assistant
Step 2: Add the
to_reasoninghelper toutils.pyAssistant
Now let me add the
to_reasoninghelper function in utils.py after theto_noise_reduction:Assistant
Step 3: Update the import statement in
realtime_model.pyfor the newto_reasoninghelperAssistant
Step 4: Add
reasoningfield to_RealtimeOptionsdataclassAssistant
Step 5: Update
__init__method overloads and signature to acceptreasoningAssistant
Now I understand the structure. Let me first update both overloads and the main init:
Assistant
Now let me update the actual implementation signature:
Assistant
Now let me update the docstring to include the new
reasoningparameter:Assistant
Step 6: Now update the actual construction of
_RealtimeOptionsto includereasoningLet me locate where
self._optsis constructed:Assistant
Now let me update the
with_azureclassmethod to acceptreasoning:Assistant
Now let me update
with_azureto acceptreasoning:Assistant
Now let me find the rest of the
with_azureto also passreasoning:Assistant
Step 7: Update
RealtimeModel.update_optionsto handlereasoningAssistant
Step 8: Update
_create_session_update_eventto includereasoningAssistant
Step 9: Update
RealtimeSession.update_optionsto also handlereasoningAssistant
Now let me test my implementation:
Assistant
Let me also test the
update_optionsmethod:Assistant
Let me test the Azure path to ensure it doesn't break:
Assistant
Let me test the new Azure API path:
Assistant
Let me now run a test that simulates the actual session.update event transmission:
Assistant
Now let me test error cases for the to_reasoning helper:
Assistant
Now let me also test that existing tests don't break. Let me first check the existing tests:
Assistant
Let me check the basic syntax of the realtime file:
Assistant
Now let me also check if the typing still works. Let me look at the lint:
Assistant
Let me check the existing realtime test:
Assistant
Now let me look at the rest of the test:
Assistant
Let me check that the model factory tests still work by simulating that case:
Assistant
Let me verify imports still work and the code is syntactically correct:
Assistant
Let me also verify the with_azure method now also accepts reasoning:
Assistant
Let me also check the agent tests work, specifically if there are any places that might break:
Assistant
Let me run this basic test to make sure my changes don't break anything:
Assistant
All Personaplex tests pass. Let me also run the existing OpenAI plugin tests to make sure nothing is broken:
Assistant
Let me run all tests that don't require external services:
Assistant
All tests pass. Let me also verify the imports test pass for
test_plugin_perplexity.pyand other plugins that use openai types:Assistant
Let me check pyright / mypy for typechecking:
Assistant
Let me clean up the test files I created:
Assistant
Now let me look at the diff of my changes:
Assistant
Let me run the exact example from the issue one more time to verify:
Assistant
The exact example from the issue now works. Let me also test the various valid
effortvalues:Assistant
Let me verify the dynamic update of reasoning:
Assistant
There's a Pydantic warning because
RealtimeSession.update_optionsdoesn't convert dict toRealtimeReasoning. Let me fix this:Assistant
Let me also look at the RealtimeSession.update_options and accept dict for consistency:
Assistant
Now let me update the body of
RealtimeSession.update_optionsto useto_reasoning:Assistant
Let me test again to confirm the warning is gone:
Assistant
Let me also do one more comprehensive integration check:
Assistant
Let me also verify xAI's RealtimeModel still works (it inherits from OpenAI RealtimeModel):
Assistant
The xAI model doesn't expose
reasoningeven though it inherits from OpenAI. Let me update xAI's model too:Assistant
Let me update the xAI RealtimeModel to also accept and pass reasoning. This isn't strictly required by the issue (which only mentions OpenAI's RealtimeModel), but it's good practice to keep it consistent.
Assistant
Now let me test the xAI's RealtimeModel with reasoning:
Assistant
Now let me run all the tests one more time to confirm:
Assistant
All 68 tests pass. Let me also check that there are no other realtime subclasses in the livekit-plugins:
Assistant
Let me look at the whole diff to confirm:
Assistant
Let me do one final comprehensive test that uses the exact example from the issue:
Assistant
Let me view the final diff for the entire change:
Assistant
Let me also do a final check to ensure nothing else uses session.update that needs updating:
Assistant
Let me ensure I haven't introduced any type errors:
Assistant
Let me run the tests one more time to confirm everything works:
Assistant
All 68 tests pass. Let me check that I haven't left any debug files behind:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.