Commit b1fc173
committed
Fix guardrails failing when interrupt_response=True
When turn_detection.interrupt_response is set to True and a guardrail triggers
an interrupt, the SDK was only sending response.interrupt but not response.cancel.
This caused the API to think the response was still active, leading to
"Conversation already has an active response" errors on subsequent requests.
Root cause:
- Guardrail interrupts are SDK-side logic, but the API doesn't know about them
- interrupt_response=True tells the API to auto-cancel on USER VOICE interrupts
- When a guardrail triggered, the SDK would skip sending response.cancel if
interrupt_response=True, assuming the API would handle it (incorrect)
Solution:
- Add force_cancel parameter to RealtimeModelSendInterrupt
- Set force_cancel=True for guardrail interrupts
- Always send response.cancel when force_cancel=True, regardless of
interrupt_response setting
- User voice interrupts continue to respect interrupt_response setting
Changes:
- src/agents/realtime/model_inputs.py: Add force_cancel parameter
- src/agents/realtime/session.py: Pass force_cancel=True for guardrails
- src/agents/realtime/openai_realtime.py: Check force_cancel in _send_interrupt
Fixes #19071 parent 748ac80 commit b1fc173
3 files changed
Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
97 | 107 | | |
98 | 108 | | |
99 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
436 | | - | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
437 | 440 | | |
438 | 441 | | |
439 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
704 | 704 | | |
705 | 705 | | |
706 | 706 | | |
707 | | - | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
708 | 710 | | |
709 | 711 | | |
710 | 712 | | |
| |||
0 commit comments