Skip to content

fix(realtime): prevent ambiguous multi-agent tool dispatch#3441

Merged
seratch merged 8 commits into
openai:mainfrom
mavrickdeveloper:fix/realtime-multi-agent-tool-dispatch
Jun 22, 2026
Merged

fix(realtime): prevent ambiguous multi-agent tool dispatch#3441
seratch merged 8 commits into
openai:mainfrom
mavrickdeveloper:fix/realtime-multi-agent-tool-dispatch

Conversation

@mavrickdeveloper

Copy link
Copy Markdown
Contributor

Summary

This pull request fixes ambiguous Realtime tool dispatch by rejecting duplicate model-visible names across Realtime function tools and handoffs.

Motivation

This came up while working with a multi-agent Realtime setup where tools and handoffs were composed together from different agent modules. In that kind of system, function tools and handoffs share the same callable namespace from the model's point of view, so duplicate names can become ambiguous without being obvious at setup time.

For example, a triage agent may end up with both:

function tool: transfer_to_billing
handoff tool: transfer_to_billing

or two handoffs may both be exposed as:

transfer_to_support

Before this change, Realtime could accept that configuration and later build SDK-side lookup maps keyed only by name. That means one entry could silently overwrite another, making it unclear whether a model call should run a Python function or transfer to another agent.

Changes

  • Adds Realtime-specific duplicate-name validation for model-visible function tool and handoff names.
  • Validates before Realtime session tools are serialized and sent to the model.
  • Validates again before local tool-call dispatch, so ambiguous runtime state fails clearly.
  • Raises a UserError that includes the duplicated name and where it came from, for example function tool vs handoff.
  • Only checks the tools and handoffs that are actually enabled for the session, so disabled handoffs do not cause false conflicts.

Tests

  • UV_FROZEN=1 bash .agents/skills/code-change-verification/scripts/run.sh

@mavrickdeveloper mavrickdeveloper marked this pull request as ready for review May 17, 2026 12:19
@mavrickdeveloper mavrickdeveloper force-pushed the fix/realtime-multi-agent-tool-dispatch branch from f428121 to b378594 Compare May 19, 2026 07:39
@mavrickdeveloper mavrickdeveloper force-pushed the fix/realtime-multi-agent-tool-dispatch branch from b378594 to a6b8769 Compare May 19, 2026 07:53
@seratch seratch added this to the 0.17.x milestone Jun 22, 2026

@seratch seratch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good overall. One change before merging: please resolve and validate the initial model settings before registering the session as a model listener. Currently, validation failure during __aenter__ leaves the listener registered because __aexit__ is never called. Please also remove the listener if connect() fails, and add a regression test covering this cleanup behavior.

@mavrickdeveloper

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c0280850c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/realtime/session.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9abf70b5c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/realtime/session.py
@seratch

seratch commented Jun 22, 2026

Copy link
Copy Markdown
Member

Thanks for the updates. initial_model_settings["handoffs"] is validated after the settings override is applied, but those handoffs are not passed through the same is_enabled filtering used for agent handoffs. That means a disabled override handoff can now cause session startup to fail with a duplicate-name UserError, even though the PR states disabled handoffs should not participate in the model-visible namespace.

Please either filter/evaluate override handoffs before duplicate-name validation, or add a test and clarify that initial_model_settings["handoffs"] is already expected to be a final enabled list.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e95ca35a5c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/realtime/session.py Outdated
@mavrickdeveloper

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Note

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e7a4af377c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/realtime/openai_realtime.py Outdated
@seratch seratch enabled auto-merge (squash) June 22, 2026 22:33
@seratch seratch merged commit a9b7b7e into openai:main Jun 22, 2026
9 checks passed
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.

2 participants