Reveal tools mid-session in realtime sessions on models that take tool updates, via `RealtimeModelProfile.supports_tool_updates` and `UpdateTools`

Merged
DO
9d ago
+13150-149
  • Closes #7288
  • Refs #7191 (stays open to track Eleven Realtime and Gemini Live)

A realtime session sent the model its tools once, when it opened. So an agent with a defer_loading=True capability that contributes tools, or a defer_loading=True tool, couldn't open a session at all: loading the capability or searching for the tool mid-call would have revealed tools the model never got.

On a model that takes new tools mid-session, the session now sends it the tools a call reveals, ahead of that call's result. This rebuilds Aditya Vardhan's #7570 on current main (after #11930), following his approach: the UpdateTools codec input, sent in the same send as the tool result and ahead of it, the supports_tool_updates profile flag, recording the reveal in history, and rewriting the captured config for reconnects. The commits credit him with Co-authored-by.

[!WARNING]
Compatibility impact: RealtimeInput, the union a RealtimeConnection.send accepts, gains UpdateTools. A session sends it only to a connection whose model's profile sets supports_tool_updates, which defaults to False, so an existing connection never receives it, but code that matches RealtimeInput exhaustively (assert_never) stops type-checking. DEFAULT_REALTIME_PROFILE gains supports_tool_updates: False.

Why this can ship in a minor release: the version policy allows adding new types to unions and new optional profile fields, and no existing connection's behavior changes. The API compatibility check is waived for both in .github/api-compatibility-waivers/.

Migration: in an exhaustive match over RealtimeInput, handle UpdateTools (or raise for it, as the built-in connections without the flag do).

What a session does now

  • Reveals. Three things reveal tools, as in a standard run: load_capability (its capability's tools), search_tools (the defer_loading=True tools it finds), and a tool returning ToolReturn.tools. The session resolves a revealed tool as it resolves the tools it opens with, and sends every tool the model can call as one UpdateTools, narrowed by tool_choice. That goes out in the same send as the result and ahead of it, so the model never hears about a tool it can't call yet.
  • History. A ToolReturn.tools reveal is recorded as a ToolAvailabilityDeltaPart after the return, where the graph records it (a search result records its own matches). A load_capability call is now recorded as a LoadCapabilityCallPart, so the session's own history marks the capability loaded. Before each model turn, the session reads loaded_capability_ids and discovered_tool_names off history, as the graph does before each request. So the model can call a revealed tool, and a standard run continuing the history has the same tools. This is tested.
  • Reconnect. The OpenAI-protocol connections (OpenAI, Azure GA and Voice Live, xAI, WebRTC sideband) write the new tools into the captured session.update that a redial replays. GPT-Live writes them into the captured delegation.responses config, as #11930 does for instructions.
  • Opening. History that already loaded a capability or revealed a tool sends those tools at connect, on every model. Otherwise the two open-time UserErrors (a deferred capability that contributes tools, a defer_loading=True tool) now apply only to models without supports_tool_updates. A deferred capability that contributes native tools still raises everywhere, because no provider turns a native tool on mid-session.
  • A reveal a model can't take. On a model without the flag, a reveal the open-time checks couldn't foresee (a tool that appears only after the session opened, through a dynamically built toolset) is recorded in history, and the session warns once that the model can't call it, following #11066's warn-don't-raise style for guarantees a provider can't keep.
  • Unchanged. Per-turn differences from a dynamic toolset or prepare_tools stay local, as before (#7251). Custom connections default to unsupported, since the profile default is False.

Public API

  • RealtimeModelProfile.supports_tool_updates (default False).
  • pydantic_ai.realtime.codec.UpdateTools, added to RealtimeInput.

OpenAIRealtimeConnection, XaiRealtimeConnection and ElevenLabsRealtimeConnection take a new optional session_config keyword argument, the configuration a redial replays, which their models pass. GPT-Live's connection already took backend=.

Live probes

Providersupports_tool_updatesEvidence
OpenAI gpt-realtime, gpt-realtime-2.1Trueparity cassettes
Gateway OpenAITrueparity cassette
xAI grok-voice-latest, grok-voice-think-fast-1.0Trueparity cassettes
GPT-Live (delegation.responses.tools)Truetest_deferred_capability_tools_go_to_the_backend cassette. The update keeps the backend's native web search
Azure AI Voice LiveTruetest_deferred_capability_tools_are_revealed_mid_session cassette, recorded with the Voice Live key. The fixture now passes AZURE_VOICELIVE_* through when recording
Azure GATrue (via the OpenAI profile)not re-probed: our Azure OpenAI key returns 401, so the parity row is skipped like the other recent scenarios
Eleven RealtimeFalseElevenLabs accepts the update and the model calls the new tool. But its replies after a session.update no longer echo the response.metadata the session uses to tell its replies apart, so the session never finished the turn. Kept off, and noted on the provider page
Gemini Live, ElevenLabs AgentsFalsetools are fixed at setup or configured on the agent

Tests

  • tests/realtime/test_tool_reveals.py, scripted-connection session tests:
    • a capability load reveals its tools ahead of the result, and the revealed tool is called;
    • a standard run continues the session's history with the tools revealed;
    • seeded history advertises at connect on a model without updates;
    • a second load is refused;
    • tool search reveals a defer_loading=True tool;
    • a ToolReturn.tools reveal is recorded once;
    • the update is narrowed by tool_choice;
    • an unloaded capability's tool is refused;
    • the warn-once path;
    • an instruction-only load sends no update;
    • unrevealed tools are refused at open.
  • test_capability_tool_reveal_parity in tests/realtime/test_parity_ws.py, recorded live for OpenAI Ɨ2, xAI Ɨ2 and gateway OpenAI. Azure is skipped (401). Every row's profile flag is asserted in test_text_tool_round_parity.
  • GPT-Live and Azure Voice Live cassettes, and a reconnect test checking that the redialed session.update carries the revealed tools.

Notes for review

  • To keep complexity down, OpenAIRealtimeConnection.send is now a match over the input type, with one method per multi-statement branch. GPT-Live's instruction-change branch and its new tools branch share _update_backend.
  • A developer-error reveal (an ordinary tool returning ToolReturn.tools naming a still-unloaded capability's tool) raises the same UserError as a standard run, which ends the session. The question #7570 raised is still open.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code


Summary by cubic

Realtime sessions now reveal tools mid-session on models that take tool updates, so loading a deferred capability, a tool-search match, and ToolReturn.tools work as they do in standard runs. Previously the session fixed its tools at connect, so opening with a hidden tool raised UserError. Closes #7288.

How it works

  • New RealtimeModelProfile.supports_tool_updates (default False) and the UpdateTools codec input; the OpenAI, xAI, and ElevenLabs connections take an optional session_config.
  • A reveal sends one UpdateTools, narrowed by tool_choice, ahead of the revealing result in the same send, and records the reveal in history as a ToolAvailabilityDeltaPart. Loading an already-active capability is a no-op, as in standard runs.
  • OpenAI-protocol connections and GPT-Live keep the updated tools in the config a reconnect replays; a GPT-Live sideband update preserves the backend's native web search.
  • Verified on OpenAI gpt-realtime, GPT-Live, Azure (GA and Voice Live), and xAI Grok Voice. Gemini Live, Eleven Realtime, and ElevenLabs Agents keep the tools they opened with, so the open-time UserErrors remain there (#7191).
  • On models without the flag, a reveal not caught at open time is recorded in history and the session warns once that the model can't call it.
  • RealtimeInput gains UpdateTools alongside main's independent AppendVoiceInstructions input (#14191), sharing the union and DEFAULT_REALTIME_PROFILE. API-compatibility waivers at v2.75.0 cover the combined change: both new inputs and both new profile flags, each defaulting to False.

Migration

  • In an exhaustive match over RealtimeInput, handle UpdateTools, or raise for it as the built-in connections without the flag do.