feat(openai): add realtime reasoning option#1699
feat(openai): add realtime reasoning option#1699rosetta-livekit-bot[bot] wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: cad5ba1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 34 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| const currentReasoning = this._options.reasoning ?? null; | ||
| const nextReasoning = reasoning ?? null; | ||
| if (currentReasoning !== nextReasoning) { | ||
| options.reasoning = reasoning; | ||
| hasChanges = true; | ||
| } |
There was a problem hiding this comment.
🟡 Object reference equality comparison for reasoning always detects change for non-null objects
In updateOptions, the reasoning change detection at line 811 uses !== (reference equality) to compare the current and next reasoning objects. Since each call typically provides a new object literal (e.g., { effort: 'medium' }), the comparison will always evaluate to true for non-null values, even when the content is identical. This defeats the no-op optimization that the hasChanges flag is designed to provide (contrast with toolChoice, where toOaiToolChoice() normalizes to a string for proper value comparison). Every repeated updateOptions({ reasoning: { effort: 'medium' } }) call sends a redundant session.update event to the server.
Prompt for agents
In updateOptions() in plugins/openai/src/realtime/realtime_model.ts, the reasoning change detection at lines 809-814 uses reference equality (currentReasoning !== nextReasoning) for object comparison. Since RealtimeReasoning is an object type (with an effort field), two objects with identical content but different references will always appear different. This means calling updateOptions({ reasoning: { effort: 'medium' } }) twice will always send a redundant session.update event.
To fix this, implement a value-based comparison, for example by comparing the serialized effort field:
const currentEffort = (this._options.reasoning ?? null)?.effort ?? null;
const nextEffort = (reasoning ?? null)?.effort ?? null;
if (currentEffort !== nextEffort) { ... }
Alternatively, use JSON.stringify for a deep comparison, though this is more fragile if new fields are added to RealtimeReasoning.
Was this helpful? React with 👍 or 👎 to provide feedback.
available for gpt-realtime-2