feat(realtime): allow tools to opt out of automatic response.create after completion#3033
Closed
jawwad-ali wants to merge 1 commit intoopenai:mainfrom
Closed
feat(realtime): allow tools to opt out of automatic response.create after completion#3033jawwad-ali wants to merge 1 commit intoopenai:mainfrom
jawwad-ali wants to merge 1 commit intoopenai:mainfrom
Conversation
…fter completion Realtime sessions hard-coded `start_response=True` when sending tool outputs back to the model, so every tool unconditionally triggered a follow-up `response.create`. Side-effect tools (analytics, background-job schedulers, telemetry) had no way to stay silent after completion. This adds a `start_response: bool = True` kw-only field to `FunctionTool` and threads it through the `@function_tool(...)` decorator. The realtime session then honors the field when emitting `RealtimeModelSendToolOutput` for both successful tool execution and approval rejections; the handoff path still triggers `response.create` because the next agent must speak. The default stays `True`, so existing tools keep their current behavior. Refs openai#2971
Member
|
Thanks for the suggestion. I think having this flag on the function_tool decorator side may not be optimal in terms of the SDK design. Having a universal option only per realtime agent session may make sense, but I am not confident enough that adding such an option is really helpful for some use cases. We don't plan to add this option at least for now, so let us close this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Realtime sessions hard-coded `start_response=True` when sending tool outputs back to the model, so every tool unconditionally triggered a follow-up `response.create`. Side-effect tools (analytics, background-job schedulers, telemetry) had no way to stay silent after completion — exactly the gap @aligokalppeker raised in #2971 (comment):
This PR exposes that toggle on `FunctionTool` and the `@function_tool(...)` decorator. The transport layer (`OpenAIRealtimeWebSocketModel._send_tool_output`) already honors `RealtimeModelSendToolOutput.start_response`; this change just lets tool authors reach it.
What changes
Default remains `True`, so every existing tool keeps current behavior.
Scope note (re: #2971's race report)
Per @seratch's response in the same thread, `v0.14.2` already routes `response.create` through `_ResponseCreateSequencer` and the active-response race is gated until a concrete repro exists. This PR does not touch the sequencer or add any tracking counters. It only addresses the per-tool ergonomics raised in @aligokalppeker's follow-up, which is independent of the race-detection path.
Test plan
Verified locally on Windows (Python 3.13):
New tests (6 total):
Issue number
Refs #2971
Checks