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 explore the plugins directory to find the OpenAI plugin:
Assistant
Let me see the full RealtimeModel class definition, looking specifically at the
__init__method and the relevant options:Assistant
Now let me look at the
update_optionsmethod and the session creation code:Assistant
Let me check the OpenAI SDK to see if RealtimeSessionCreateRequest already has a
reasoningfield:Assistant
Let me explore the
RealtimeReasoningtype:Assistant
And
RealtimeReasoningEffort:Assistant
Now let me look at the existing tests and the Azure session update handling for context:
Assistant
Let me look at how the
truncationoption is implemented as it's similar in structure:Assistant
Let me look at how
with_azurehandles options:Assistant
Let me look at the Azure Session type for the session update event:
Assistant
Let me look at the
_oai_session_to_azurefunction and check what additional fields should be supported in Azure mode. Let me also check the JS PR implementation in detail by checking the GitHub PR contents:Assistant
Now let me look at the AzureSession type to confirm it has a
reasoningfield:Assistant
Now I have a clear picture. Let me also check what types are exposed in the realtime module:
Assistant
Let me see what NotGivenOr and NotGiven imports look like:
Assistant
Let me look at how Azure mode skips fields, and let me also look at the JS PR for reference:
Assistant
Let me first write a reproduction script to confirm the issue:
Assistant
I confirmed the issue. Now let me check the JS PR to see what they did exactly, but since I don't have access to that, let me focus on making my implementation consistent with existing patterns. Let me look at the JS PR #1575 if it's accessible via the system:
Assistant
Let me check the
_supports_reasoning_effort:Assistant
Let me trace all the places where
truncationis used to find any spots I might have missed:Assistant
Let me also look at the docs area for truncation to understand what docstrings to update:
Assistant
Now I have a complete understanding. Let me implement the changes step by step:
Assistant
Now let me make the actual changes. First, add the import for
RealtimeReasoning:Assistant
Now let me update the
_RealtimeOptionsdataclass to add thereasoningfield:Assistant
Now I can see the exact contents. Let me do the edit:
Assistant
The edit was applied. Now let me add the
reasoningfield. I'll do a replace instead.Assistant
Now let me add the
reasoningparameter to the first__init__overload:Assistant
Now let me do the edit in pieces. First the first overload:
Assistant
The edit was applied incorrectly - I see a duplicate section was created. Let me revert and try a cleaner approach:
Assistant
Now let me make the changes more carefully. Let me use a script-based approach:
Assistant
Let me verify the changes:
Assistant
Now let me handle the Azure conversion. The Azure session type doesn't have a
reasoningfield, so we need to handle this case:Assistant
Let me check how Pydantic handles unknown fields with
model_construct:Assistant
Let me check the existing pattern for fields that aren't supported by Azure:
Assistant
Now let me verify the fix by running the reproduction script:
Assistant
Now let me write a more thorough test to verify the behavior:
Assistant
Let me update the script to handle async properly:
Assistant
Let me verify: is
RealtimeSession.update_optionsasync or sync?Assistant
Both
update_optionsare sync. Let me also check what's at line 1220 and 658 to understand the twoupdate_optionsmethods. The first one isRealtimeModel.update_optionsand the second isRealtimeSession.update_options. Let me confirm:Assistant
Both
update_optionsmethods are sync. Let me update the test:Assistant
Let me check how
is_givenandNOT_GIVENwork:Assistant
Let me check what the existing truncation logic does for None case:
Assistant
Let me verify the
is_givensemantics:Assistant
Let me re-examine the test to see if my code is correct - notice that
session.update_optionsonly updatessession._opts(a copy):Assistant
Let me update the test to check the right field:
Assistant
All tests pass. Let me run the existing tests to make sure I haven't broken anything:
Assistant
Let me check what conditions the realtime tests need:
Assistant
These tests require OpenAI/Azure API keys, which I don't have. So I'll need to rely on my own tests to verify the changes.
Let me look at any unit tests that don't require API keys - maybe there's a models test:
Assistant
Let me run a few more checks to make sure nothing is broken:
Assistant
Let me look at the current state of the docstrings to ensure consistency:
Assistant
Let me look at the diff one more time to verify the final state:
Assistant
Let me also check how
kwargsare handled in__init__:Assistant
Let me also see how
with_azureworks in the responses/llm.py:Assistant
Let me think about whether to add reasoning to
with_azure. Let me also verify what happens with the Azure session when reasoning is set:Assistant
Let me also run my test_config.py:
Assistant
Let me also check if there's any documentation that needs updating:
Assistant
Let me also verify the type signature and the JSON encoding work properly:
Assistant
Let me adjust my test to convert the event to a dict first:
Assistant
Let me verify with the JSON serialization that the data is sent correctly:
Assistant
Let me also try running mypy/pyright to check for any type errors:
Assistant
Let me also run mypy on the broader test directory:
Assistant
Let me confirm these errors are pre-existing by checking a file I didn't modify:
Assistant
Let me restore my changes:
Assistant
Let me review the final state of the changes:
Assistant
Let me do a final test using the exact example from the issue:
Assistant
Let me set the env var and re-run:
Assistant
The exact example from the issue now works. Let me do a final comprehensive test:
Assistant
Let me clean up the temporary test files:
Assistant
Let me view the final diff one more time:
Assistant
Let me do one final check to see if there are any other places I might have missed:
Assistant
The implementation is complete and consistent with the existing pattern. Let me check one more aspect - that the responses/llm.py uses a different pattern with
is_given(self._opts.reasoning):Assistant
My implementation is complete and follows the existing patterns. Let me run the tests one more time to confirm:
Assistant
All 36 tests pass. Let me also verify the file compiles correctly:
Assistant
All checks pass. Let me also do one final check on the diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.