-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Describe the feature
I’m using the openai-agents-python SDK with a RealtimeRunner for a voice-to-voice Realtime Agent (audio input + audio output) with output guardrails.
When a guardrail is tripped, the SDK emits a guardrail_tripped event, but it doesn’t automatically handle it like the Node.js SDK ( openai-agents-js ) does.
In the Node.js version, output guardrails are handled internally before the model speaks. so it never says the blocked content (e.g., mentioning a competitor if that’s disallowed).
In the Python SDK, however, the model still speaks the blocked response, and I have to manually cancel it and try to send another safe message (like “Sorry, I can’t help with that request”). But this manual handling doesn’t work correctly, the model doesn’t speak the safe message.
Manual Implementation We are doing when guardrail triggered. We also tried different ways b y sending events but didn't work out.
RealtimeAgent(
name=agent_data.name,
instructions=prompt,
tools=agents_sdk_tools,
output_guardrails=[
OutputGuardrail(
guardrail_function=moderation_output_guardrail(agent_data.guardrails_instructions)
)
],
)
# Guardrail handling
if event.type == "guardrail_tripped":
feedback_message = "Sorry, I can’t help with that request."
await self.session.interrupt()
await asyncio.sleep(0.1)
await self.session.send_message(feedback_message)
References
Node.js implementation:
realtimeSession.ts (L555–L596)
Python implementation:
Question
Will the Python Realtime SDK support automatic output guardrail handling like the Node.js SDK, i.e., canceling blocked content before it’s spoken and generating a safe fallback message automatically for realtime agents?