Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-snakes-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openai/agents-realtime': patch
---

fix: #494 Voice input transcription failing in realtime-demo
14 changes: 12 additions & 2 deletions packages/agents-realtime/src/realtimeSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import {
RealtimeOutputGuardrailSettings,
} from './guardrail';
import { RealtimeItem } from './items';
import { OpenAIRealtimeModels } from './openaiRealtimeBase';
import {
DEFAULT_OPENAI_REALTIME_SESSION_CONFIG,
OpenAIRealtimeModels,
} from './openaiRealtimeBase';
import { OpenAIRealtimeWebRTC } from './openaiRealtimeWebRtc';
import { OpenAIRealtimeWebSocket } from './openaiRealtimeWebsocket';
import { RealtimeAgent } from './realtimeAgent';
Expand Down Expand Up @@ -147,6 +150,12 @@ export type RealtimeSessionConnectOptions = {
url?: string;
};

function cloneDefaultSessionConfig(): Partial<RealtimeSessionConfig> {
return JSON.parse(
JSON.stringify(DEFAULT_OPENAI_REALTIME_SESSION_CONFIG),
) as Partial<RealtimeSessionConfig>;
}

/**
* A `RealtimeSession` is the cornerstone of building Voice Agents. It's the equivalent of a
* Runner in text-based agents except that it automatically handles multiple turns by maintaining a
Expand Down Expand Up @@ -206,7 +215,8 @@ export class RealtimeSession<
// modalities, speed, toolChoice, turnDetection, etc.). Without this, updating
// the agent would drop audio format overrides (e.g. g711_ulaw) and revert to
// transport defaults causing issues for integrations like Twilio.
#lastSessionConfig: Partial<RealtimeSessionConfig> | null = null;
#lastSessionConfig: Partial<RealtimeSessionConfig> | null =
cloneDefaultSessionConfig();
#automaticallyTriggerResponseForMcpToolCalls: boolean = true;

constructor(
Expand Down
21 changes: 20 additions & 1 deletion packages/agents-realtime/test/realtimeSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
} from '@openai/agents-core';
import * as utils from '../src/utils';
import type { TransportToolCallEvent } from '../src/transportLayerEvents';
import { OpenAIRealtimeBase } from '../src/openaiRealtimeBase';
import {
DEFAULT_OPENAI_REALTIME_SESSION_CONFIG,
OpenAIRealtimeBase,
} from '../src/openaiRealtimeBase';
import { toNewSessionConfig } from '../src/clientMessages';

function createMessage(id: string, text: string): RealtimeItem {
return {
Expand Down Expand Up @@ -122,6 +126,21 @@ describe('RealtimeSession', () => {
expect(t.connectCalls[0]?.url).toBe('ws://example');
});

it('includes default transcription config when connecting', async () => {
const t = new FakeTransport();
const agent = new RealtimeAgent({ name: 'A', handoffs: [] });
const s = new RealtimeSession(agent, { transport: t });
await s.connect({ apiKey: 'test' });

const normalizedConfig = toNewSessionConfig(
t.connectCalls[0]?.initialSessionConfig ?? {},
);

expect(normalizedConfig.audio?.input?.transcription).toEqual(
DEFAULT_OPENAI_REALTIME_SESSION_CONFIG.audio?.input?.transcription,
);
});

it('updateHistory accepts callback', () => {
const item = createMessage('1', 'hi');
session.updateHistory([item]);
Expand Down