Skip to content

Commit 7f797cd

Browse files
committed
fix: resolve failing realtime session tests
- Fix voice config precedence: session config voice now overrides agent default voice - Fix updateSessionConfig test expectations: add agent updates to trigger updateSessionConfig calls - Tests now properly trigger updateSessionConfig by calling updateAgent() - Preserves session config voice setting instead of always using agent default Fixes 4 failing tests: - includes tools in session config when session config is provided - preserves tools when updateSessionConfig is called - does not include tools field when no tools are provided - reproduces the original issue - tools work with config provided
1 parent 98df59d commit 7f797cd

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/agents-realtime/src/realtimeSession.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ export class RealtimeSession<
337337
const fullConfig: Partial<RealtimeSessionConfig> = {
338338
...base,
339339
instructions,
340-
voice: this.#currentAgent.voice,
340+
// Use session config voice if provided, otherwise fall back to agent voice
341+
voice: base.voice ?? this.#currentAgent.voice,
341342
model: this.options.model,
342343
tools: this.#currentTools,
343344
tracing: tracingConfig,

packages/agents-realtime/test/realtimeSession.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ describe('RealtimeSession', () => {
466466

467467
await session.connect({ apiKey: 'test' });
468468

469+
// Trigger an agent update to cause updateSessionConfig to be called
470+
const newAgent = new RealtimeAgent({
471+
name: 'UpdatedAgent',
472+
handoffs: [],
473+
tools: [TEST_TOOL]
474+
});
475+
await session.updateAgent(newAgent);
476+
469477
// Check that updateSessionConfig calls include tools
470478
expect(transport.updateSessionConfigCalls.length).toBeGreaterThan(0);
471479
const lastUpdateCall = transport.updateSessionConfigCalls[transport.updateSessionConfigCalls.length - 1];
@@ -491,6 +499,14 @@ describe('RealtimeSession', () => {
491499

492500
await session.connect({ apiKey: 'test' });
493501

502+
// Trigger an agent update to cause updateSessionConfig to be called
503+
const newAgent = new RealtimeAgent({
504+
name: 'UpdatedAgent',
505+
handoffs: [],
506+
tools: [] // No tools
507+
});
508+
await session.updateAgent(newAgent);
509+
494510
// Check that updateSessionConfig calls do not include tools field
495511
expect(transport.updateSessionConfigCalls.length).toBeGreaterThan(0);
496512
const lastUpdateCall = transport.updateSessionConfigCalls[transport.updateSessionConfigCalls.length - 1];
@@ -522,6 +538,14 @@ describe('RealtimeSession', () => {
522538
expect(connectCall?.initialSessionConfig?.tools).toHaveLength(1);
523539
expect(connectCall?.initialSessionConfig?.tools?.[0]?.name).toBe('test');
524540

541+
// Trigger an agent update to cause updateSessionConfig to be called
542+
const newAgent = new RealtimeAgent({
543+
name: 'UpdatedAgent',
544+
handoffs: [],
545+
tools: [TEST_TOOL]
546+
});
547+
await session.updateAgent(newAgent);
548+
525549
// Verify that subsequent updates also include tools
526550
expect(transport.updateSessionConfigCalls.length).toBeGreaterThan(0);
527551
const lastUpdateCall = transport.updateSessionConfigCalls[transport.updateSessionConfigCalls.length - 1];

0 commit comments

Comments
 (0)