feat: daily warm transfer bridge — PSTN agent leg bridged into Daily …#751
feat: daily warm transfer bridge — PSTN agent leg bridged into Daily …#751amreetkhuntia wants to merge 1 commit into
Conversation
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9ba9ca6 to
6b1fe90
Compare
…room
Adds in-process WebSocket audio bridge so that when an LLM in a Daily
call invokes connect_to_live_agent, the human agent is dialled on PSTN
and their voice is forwarded bidirectionally into the Daily room via a
Pipecat dual-transport pipeline (no subprocess). The AI bot then leaves.
6b1fe90 to
062d165
Compare
There was a problem hiding this comment.
Pull request overview
Adds a Daily-mode warm transfer path for Breeze Buddy where a dialed PSTN human agent leg is bridged bidirectionally into an existing Daily room via an in-process WebSocket + Pipecat dual-transport pipeline, allowing the AI bot to exit once the bridge is live.
Changes:
- Introduces Redis “bridge flag” state (
dialing/joined/failed/disconnected) keyed by the agent leg call SID and new Daily warm-transfer handler logic. - Adds a new telephony WebSocket endpoint to run the in-process audio bridge, plus answer-time routing to that endpoint when a bridge flag exists.
- Updates bot/context to expose Daily
room_url, plus minor tooling/config/doc updates.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Expands Pyrefly excludes to avoid known stub-mismatch paths. |
| docs/breeze_buddy/daily_warm_transfer.md | Adds design doc for Daily→PSTN warm transfer bridge. |
| app/api/routers/breeze_buddy/telephony/bridge.py | New WS endpoint that validates bridge flag and runs the bridge pipeline. |
| app/api/routers/breeze_buddy/telephony/answer/handlers.py | Routes provider answer flow to the bridge WS when a bridge flag exists. |
| app/api/routers/breeze_buddy/telephony/init.py | Mounts the new bridge router. |
| app/ai/voice/agents/breeze_buddy/utils/bridge_flag.py | New Redis helpers/state for bridge lifecycle. |
| app/ai/voice/agents/breeze_buddy/template/context.py | Exposes room_url on TemplateContext. |
| app/ai/voice/agents/breeze_buddy/services/daily/transfer_bridge.py | Implements the in-process Pipecat dual pipeline for audio forwarding. |
| app/ai/voice/agents/breeze_buddy/handlers/internal/warm_transfer.py | Delegates connect_to_live_agent to Daily-specific handler for Daily execution modes. |
| app/ai/voice/agents/breeze_buddy/handlers/internal/daily_warm_transfer.py | New Daily warm-transfer handler that dials agent + waits for bridge join. |
| app/ai/voice/agents/breeze_buddy/agent/init.py | Persists Daily room_url on the bot for downstream token minting. |
| .gitignore | Ignores temp/. |
| .githooks/pre-commit | Makes uv sync non-fatal and disables auto-sync for subsequent uv run. |
|
|
||
| aiohttp_session = context.aiohttp_session or create_aiohttp_session() | ||
|
|
||
| # Mint a Daily owner token for the bridge to use when joining the room. | ||
| daily_token = await _mint_bridge_daily_token(context.room_url, aiohttp_session) | ||
| if not daily_token: |
|
|
||
| ## Status | ||
|
|
||
| Design — not yet implemented. |
| } | ||
|
|
||
| provider_enum = outbound_number_record.provider | ||
| provider_name = provider_enum.value.lower() |
| Read-modify-write — race tolerable because only the bridge handler and | ||
| failure paths write status, and they don't run concurrently for the same | ||
| call_sid. |
| # Mark the bridge as joined immediately *before* the pipelines start | ||
| # running. The AI bot is polling for this status and can begin tearing | ||
| # down the moment the bridge is ready to relay audio. If the runner then | ||
| # fails, we'll flip the flag to disconnected/failed below. | ||
| await update_bridge_status(call_id, STATUS_JOINED) |
| # Either side closing trips the runner. Mark as disconnected so any | ||
| # waiters know it's over, then clear the flag. | ||
| await update_bridge_status(call_id, STATUS_DISCONNECTED) | ||
| await clear_bridge_flag(call_id) | ||
| logger.info(f"[BridgeRun] Bridge ended for call {call_id}") |
| logger.error( | ||
| f"[Bridge WS] Bridge run failed for call {call_id}: {e}", | ||
| exc_info=True, | ||
| ) |
| bridge_flag = await get_bridge_flag(call_id) | ||
| if bridge_flag: | ||
| ws_base = APP_BASE_URL.replace("https://", "wss://").replace("http://", "ws://") | ||
| bridge_ws_url = f"{ws_base}/agent/voice/breeze-buddy/{provider}/bridge/v2" | ||
| logger.info( |
| ## Architecture | ||
|
|
||
| The bridge runs inside the FastAPI server as a WebSocket handler. When the dialed agent picks up, the telephony provider opens a WS to `/agent/voice/breeze-buddy/{provider}/bridge/ws?call_sid=…`. That handler reads the Redis bridge flag, joins the existing Daily room as a Pipecat client, and runs a forwarding pipeline: telephony WS frames → resample/encode → Daily; Daily frames → resample/encode → telephony WS. Two stateful frame processors hold the `audioop.ratecv` state per direction. | ||
|
|
||
| ## Sequence |
| except Exception as e: | ||
| logger.error( | ||
| f"[BridgeRun] Bridge runtime exception for call {call_id}: {e}", | ||
| exc_info=True, | ||
| ) |
…room
Adds in-process WebSocket audio bridge so that when an LLM in a Daily call invokes connect_to_live_agent, the human agent is dialled on PSTN and their voice is forwarded bidirectionally into the Daily room via a Pipecat dual-transport pipeline (no subprocess). The AI bot then leaves.
Changes: