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
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) usinggit statusorgit diffcommands. 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
I’ll first map the repository and locate the Python OpenAI realtime implementation, its option types, payload construction, and relevant tests. Then I’ll reproduce the missing API/payload behavior, implement the smallest type-safe change consistent with existing conventions, and run focused tests plus broader validation.
- Assistant
rgis unavailable in this environment, so I’ll usefindand recursivegrep. The repository is a monorepo with a dedicated OpenAI plugin; I’ll narrow inspection there and read its contributor guidance before editing. - Assistant
I found the target implementation at
livekit-plugins-openai/.../realtime_model.py. Next I’ll inspect repository rules, the constructor/options/session update path, OpenAI plugin tests, and analogous reasoning option definitions elsewhere to match naming and typing conventions. - Assistant
The constructor currently has no
reasoningparameter, and_RealtimeOptionslikewise cannot retain it. The key compatibility question is whether the installed OpenAI SDK’s generatedRealtimeSessionCreateRequestalready modelsreasoning; I’ll inspect that type and the exact session payload assembly/update methods before deciding whether to use the generated SDK type or a local typed dictionary. - Assistant
The installed SDK recognizes
gpt-realtime-2but its generated session request does not appear to expose a nestedReasoningclass. I’ll verify all request fields and inspect model configuration: Pydantic may ignore unknown constructor fields, which would explain why simply forwardingreasoningthrough this SDK model can silently drop it. I’ll also inspect update APIs to determine whether reasoning should be immutable or session-updatable; the requested feature only requires constructor-to-session payload support. - Assistant
The current SDK does expose a
reasoningfield (the earlier class import assumption was just wrong because its type lives elsewhere), and it serializes correctly. Therefore the clean implementation is to use the SDK-provided reasoning type, retain it in_RealtimeOptions, expose it on both OpenAI constructor overloads and the concrete constructor, and set it in the initial session update. I’ll identify the precise generated type and accepted effort literals—includingxhigh—then check model exports and version constraints for Python 3.10 compatibility. - Assistant
The SDK separates response models (
RealtimeReasoning, a Pydantic model) from request parameter types (RealtimeReasoningParam, aTypedDict). Since the requested public call uses a dict literal, the public constructor should accept the request parameter type; internally, the session Pydantic model will validate/store it asRealtimeReasoning. I’ll verify import exports and compare how this file handles other request dict/model pairs so static type checking supports the exact example rather than only permitting it at runtime. - Assistant
I’ll normalize both accepted public forms—
RealtimeReasoningParamdicts andRealtimeReasoningobjects—to the SDK model, while preserving omission when no reasoning is supplied. This avoids emitting an unsolicited"reasoning": nullfor every existing model and lets the exact issue example type-check. Because the plugin currently declares broadopenai>=2, I’ll inspect the locked SDK version/history metadata; if these types were added after 2.0, the package minimum may need tightening to prevent import failures in valid declared environments. - Assistant
The lock uses OpenAI 2.40.0, which contains the needed generated types. Tightening the broad minimum is likely outside this focused change and could unnecessarily affect dependency resolution; the plugin already relies extensively on evolving Realtime v1 SDK types, so I’ll follow its current dependency policy.
Before editing, I’ll reproduce the issue directly by constructing the requested model: Python should currently absorb
reasoninginto**kwargsand silently omit it from the queued initialsession.update. Then I’ll patch the constructor/options/payload and rerun the same script. - Assistant
The reproduction confirms the failure mode exactly: construction succeeds only because
**kwargsswallows the unsupported keyword, and the queued session update has noreasoning. I’ll now add the typed parameter to the OpenAI overload and implementation, normalize it into_RealtimeOptions, document it, and conditionally attach it to the initialRealtimeSessionCreateRequest. I will not expose it through the Azure-specific overload/factory because the legacy Azure conversion does not support this OpenAI-only field. - Assistant
The patch is structurally in place and
git diff --checkis clean. I’ll inspect the exact normalized assignment and full diff, then run the original reproduction with assertions for both the nested payload and all five documented effort values. I’ll also verify omission remains unchanged when the option is absent and that passing an SDK model works. - Assistant
Runtime verification now passes for dict input, SDK-model input, every allowed effort (
minimalthroughxhigh), and backward-compatible omission. Next I’ll run Ruff formatting/lint on the changed file and strict mypy for the OpenAI plugin source. I’ll also locate any OpenAI/realtime-focused tests available in the monorepo; the plugin itself contains no test directory. - Assistant
Ruff lint passes; format-check requests only standard wrapping. Strict mypy reports three pre-existing missing generic arguments at unrelated lines (session futures/tasks), with no errors in the new reasoning code. I’ll apply Ruff formatting, inspect the realtime test suite’s provider requirements, and run it if it is self-contained. I’ll also use a temporary mypy snippet to prove the exact user-facing dict-literal call is accepted statically, since runtime behavior is already validated.
- Assistant
Formatting and lint now pass, and strict mypy accepts the exact requested dict-literal API plus an SDK-model form. The repository’s realtime pytest suite is an external integration suite requiring live OpenAI/Azure credentials, so it cannot be run meaningfully here; the local queued-event reproduction exercises the payload path without network access.
I’ll do one final compatibility review: ensure
gpt-realtime-2is represented in the plugin’s model literal (if that literal is curated), verify no accidental lock/environment files changed duringuv, and inspect the final diff/status. - Assistant
Final review shows
gpt-realtime-2is already inRealtimeModels, only the intended source file changed, and the diff is whitespace-clean. The implementation deliberately applies reasoning only to OpenAI’s initial session configuration and omits it for defaults; Azure’s unsupported legacy payload remains untouched.I’ll perform the final verification pass after formatting: compile the changed module, rerun the exact issue example against the queued serialized event, verify invalid effort values are rejected by SDK validation, and rerun Ruff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.