Skip to content

fix(realtime-session): preserve audio format and config fields on agent update - #318

Merged
seratch merged 3 commits into
openai:mainfrom
myaroshefsky:fix/session-config-preserve-audio-formats
Aug 11, 2025
Merged

seratch merged 3 commits into
openai:mainfrom
myaroshefsky:fix/session-config-preserve-audio-formats

Conversation

@myaroshefsky

Copy link
Copy Markdown
Contributor

Summary

This pull request fixes a critical bug where updating the agent in a RealtimeSession would cause important session config fields (such as inputAudioFormat and outputAudioFormat) to revert to defaults, breaking integrations like Twilio that require specific audio formats.

Related Issue

Fixes #317

Problem

When calling updateAgent()on a RealtimeSession, the session config was rebuilt from a minimal set of fields, omitting values like inputAudioFormat, outputAudioFormat, modalities, speed, etc.

This caused the server to fall back to defaults (e.g., pcm16), resulting in loud static or broken audio for Twilio and other integrations that require a specific format.

Steps to Reproduce

Create a RealtimeSession with a custom inputAudioFormat (e.g., g711_ulaw).

Call updateAgent() to switch to a new agent.

Observe that the session config sent to the server reverts to pcm16 and Twilio calls break.

Solution

Added a #lastSessionConfig cache to RealtimeSession to store the last full session config sent to the server.
Updated #getSessionConfig to merge the last config, user options, and per-call overrides, always refreshing dynamic fields (instructions, voice, tools, tracing). This ensures all config fields (including audio formats) are preserved across agent updates.

Added a regression test to ensure this behavior is maintained.

Testing

Ran pnpm build && pnpm test && pnpm lint — all checks pass.
Added a test that verifies inputAudioFormat and outputAudioFormat persist after updateAgent().

Checklist

  • Branch is up to date with main
  • All tests pass (pnpm build && pnpm test && pnpm lint)
  • Changeset generated
  • No secrets committed (Trufflehog run)
  • Follows Conventional Commits

Notes

If you have any feedback or need further changes, let me know!

…nt update

Fixes openai#317

- Caches and merges last session config to ensure fields like inputAudioFormat/outputAudioFormat are preserved across agent updates
- Adds regression test for Twilio scenario
- Adds changeset for release tracking
@changeset-bot

changeset-bot Bot commented Aug 9, 2025 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6f2abed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@openai/agents-realtime Patch
@openai/agents Patch
@openai/agents-extensions Patch

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

Comment thread .changeset/preserve-audio-formats-on-agent-update.md Outdated
@seratch seratch added the bug label Aug 11, 2025
@seratch
seratch enabled auto-merge (squash) August 11, 2025 05:16
@seratch
seratch merged commit a0b1f3b into openai:main Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RealtimeSession.updateAgent reverts audio input/output format to pcm16

2 participants