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
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 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
Now let's look at the full realtime_model.py in the relevant sections to add reasoning support properly.
Assistant
Now let's view the rest of init overloads, main constructor, and update method, and session-building code.
Assistant
Now let's view the from_azure classmethod and update() method for session, along with the session build code.
Assistant
Now let's look at where session is built (RealtimeSessionCreateRequest construction) around line 1150-1270.
Assistant
Now let's add the
to_reasoninghelper function in utils.py.Assistant
Now add the
to_reasoningfunction afterto_turn_detection.Assistant
Need blank line before
def calculate_confidence_from_logprobsand need to addMappingimport.Assistant
The replace command silently failed since it seems the earlier chained command execution stopped after first replace due to
&&but reported "not applied" for the edit part. Let's check if replace succeeded.Assistant
The replace didn't apply (currently open file might have been different context). Let's just do it explicitly.
Assistant
Good. Now let's verify the file compiles fine with python syntax check.
Assistant
Now let's edit realtime_model.py. First add imports.
Assistant
Now let's add
RealtimeReasoningto imports andto_reasoningto utils import list.Assistant
Order is off alphabetically (to_reasoning before to_oai_tool_choice) - let's fix that for cleanliness.
Assistant
There's a duplicate
)on line 106. Fix it.Assistant
Good, imports fixed. Now let's add
reasoningfield to_RealtimeOptionsdataclass.Assistant
Now add
reasoningto both overloads (line 287 and around line 320ish now shifted by +1). Let's search for all occurrences oftracing: NotGivenOr[Tracing | None] = NOT_GIVEN,and add reasoning after each occurrence, except where updates aren't needed for Azure ones we may still add for forward compat.Assistant
Let's verify placement and check the file for consistency.
Assistant
Now let's look at the main
__init__body to add reasoning toself._optsconstruction, and docstring.Assistant
Now let's find where
_optsconstruction happens and addreasoning=to_reasoning(reasoning).Assistant
Now let's find the
with_azureclassmethod call toRealtimeModel(...)at the end, to pass reasoning through.Assistant
Now let's update the
RealtimeModel.update_optionsmethod (lines 703-720) to handle reasoning.Assistant
Now let's find
_create_session_update_eventto add reasoning to the session, and theRealtimeSession.update_optionsmethod.Assistant
There's a leftover duplicate
tracing=opts.tracing,\n)at line 1204-1205. Let's remove that.Assistant
Now let's add reasoning handling in
RealtimeSession.update_options(after tracing block at 1254-1258).Assistant
Now let's verify the whole file parses correctly, and check for the docstring update in
with_azure's already done, and checkRealtimeModel.update_optionsdocstring - not necessary. Let's compile syntax check.Assistant
Now let's try to actually import the module to make sure everything resolves (need dependencies installed).
Assistant
Import successful. Now let's write a quick reproduction script to test that reasoning gets included in the session update event.
Assistant
Need to run inside asyncio loop. Let's wrap with asyncio.run.
Assistant
All tests pass. Now let's check that RealtimeSession-level update_options also works (through model.update_options which propagates to sessions).
Assistant
Excellent, all working. Now let's clean up test scripts and run the existing test suite for this plugin.
Assistant
These likely require actual API access (network). Let's check if OPENAI_API_KEY is set/available; if not, they'll probably fail/skip due to connection errors. Let's just try running a couple to see behavior.
Assistant
Good - as expected, this test requires actual network/API access. This confirms the failure is unrelated to my changes (invalid API key / network). This is expected behavior in a sandboxed environment. Let's verify test file doesn't reference reasoning already, and check
_openai_modelfixture for existing behavior.Assistant
These tests require network/api keys (not available in sandbox), confirmed unrelated to my change. Now let's check ruff/mypy for style compliance if configured.
Assistant
Let's also check mypy if configured for this package.
Assistant
Excellent, clean. Now let's double check the diff overall.
Assistant
I notice a bug -
max_output_tokens=opts.max_response_output_tokens,line was accidentally removed! Let's check.Assistant
Now let's re-check the diff to confirm the max_output_tokens is restored and nothing else missing.
Assistant
Good, now that line shows as unchanged context (not removed). Let's re-run syntax check, ruff, mypy, and the reproduction tests again to be thorough.
Assistant
Both
reasoningandmax_output_tokensare now correctly present. Let's do a final full diff review.Assistant
This looks complete and correct. Let's finally run the full test suite for this specific plugin (excluding network tests) to ensure nothing else broke, and run a broader syntax/type check.
Assistant
All good — collection works without errors, mypy passes on both files. Let's also run ruff/format check for the whole repo to be safe, and confirm no lingering issues.
Assistant
Everything passes. Let's review the checklist items now.
Checklist review:
Assistant
- If an error was reported in the issue description, I have successfully reproduced it. — The issue was a missing feature (no error), so instead I reproduced the absence of the feature by confirming
RealtimeModelhad noreasoningparameter before my change, then verified it now exists and functions correctly. - If an error was reported, I have confirmed my fix resolves the error. — N/A (feature request), but I confirmed the new
reasoningparam works end-to-end: constructingRealtimeModel(model="gpt-realtime-2", reasoning={"effort": "low"}), accepting both dict andRealtimeReasoningobjects, propagating into the session-update payload (session.reasoning), supportingupdate_options(reasoning=...)at both model and session level with proper diffing (only sends update when changed), and defaulting to when not provided.
- If an error was reported in the issue description, I have successfully reproduced it. — The issue was a missing feature (no error), so instead I reproduced the absence of the feature by confirming
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.