feat(realtime): add input guardrails for RealtimeAgent and RealtimeRunConfig#3721
feat(realtime): add input guardrails for RealtimeAgent and RealtimeRunConfig#3721Skyline-9 wants to merge 11 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b2c6fc6b1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
1b2c6fc to
bedd7a9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bedd7a9c37
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
bedd7a9 to
7e2676a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e2676af1d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e2676af1d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
7e2676a to
058565e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 058565e6fd
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb71f7ba7f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
eb71f7b to
fa7fcdf
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa7fcdf92e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db7063f776
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Snapshot the active agent and its input guardrails when the transcription event is handled so a concurrent update_agent()/handoff cannot run a different agent's guardrails, and run the input guardrails concurrently so a slow guardrail cannot delay the forced response cancel.
Address Codex review: replace asyncio.gather (which waits for every guardrail before inspecting results) with asyncio.as_completed so the forced response cancel fires as soon as the first tripwire is available, then cancel the remaining guardrail tasks. Mirrors the streamed input-guardrail path so a slow guardrail can no longer delay the interrupt.
db1236c to
03bc59a
Compare
|
Hi team, I have updated the PR to address the recent Codex review comments, rebased it on top of the latest Key Updates:
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 03bc59aa42
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Summary
Adds input guardrails to the realtime API, bringing it closer to parity with the non-realtime
Agent/Runner, which already supportsinput_guardrails. Realtime today only supports output guardrails (RealtimeAgent.output_guardrails/RealtimeRunConfig["output_guardrails"]); there is no first-class way to screen the user's transcribed input.What changed:
RealtimeAgent.input_guardrails(appended at the end of the dataclass,default_factory=list) andRealtimeRunConfig["input_guardrails"](NotRequiredTypedDict key).RealtimeInputGuardrailTrippedsession event (appended at the end of theRealtimeSessionEventunion), mirroringRealtimeGuardrailTrippedfield-for-field but typed toInputGuardrailResult.RealtimeSessionruns the combined agent + run-config input guardrails on the completed user transcript (input_audio_transcription_completed), de-duped byid(). It reuses the existing output-guardrail machinery (shared_guardrail_tasksset,_on_guardrail_task_done,_cleanup_guardrail_tasks), soclose()cancels in-flight tasks. On a trip it emitsinput_guardrail_tripped, forcesresponse.cancel, and sends a follow-up user message naming the guardrail.agents.realtime.__init__(__all__) with an import regression test.docs/ref/realtime/events.mdrenders the new event;docs/realtime/guide.mddocuments the feature and disambiguates it from the existing tool-level "input guardrails on function-tool calls".The design deliberately mirrors
_run_output_guardrails(argument order verified againstInputGuardrail.run(self, agent, input, context)) so the behavior and lifecycle are consistent with what maintainers already review.Known limitation (documented, not hidden)
The forced cancel reliably interrupts a response that is already in flight. If a guardrail resolves in the narrow window before any response has been created for the tripped turn, the cancel is a no-op and that response may proceed. Eliminating this window cleanly requires response<->user-item correlation at the model layer (for example a
response_idon turn-started / response-created) so the session can cancel only the tripped turn's response without also cancelling the intentional guardrail-notification response. This limitation is documented in theRealtimeInputGuardrailTrippeddocstring,RealtimeAgent.input_guardrails, and the guide rather than papered over with a heuristic that would cancel the wrong response. Scope is also documented: input guardrails run on transcribed audio only; text sent viasend_messageis not screened. Happy to pursue the model-layer correlation as a follow-up if maintainers prefer.Test plan
tests/realtime/test_session.py::TestInputGuardrailFunctionality, including edge cases:make format,make lint,make typecheck— passmake tests(full) — pass (4797 passed, 2 skipped; serial 27 passed, 5 skipped)make build-docs— pass (newRealtimeInputGuardrailTrippedreference resolves clean)Issue number
Realtime parity with the non-realtime input-guardrail support. Happy to link the relevant tracking issue.
Checks
.agents/skills/code-change-verification/scripts/run.shmake format,make lint,make typecheck,make tests, andmake build-docs)/reviewbefore submitting this PRCompatibility notes
Additive. New fields are appended at the end of
RealtimeAgent(preserving positional compatibility) and are aNotRequiredconfig key; the new event is appended at the end of theRealtimeSessionEventunion. Sessions with no input guardrails configured create no extra tasks per utterance.