Skip to content

feat: daily warm transfer bridge — PSTN agent leg bridged into Daily …#751

Open
amreetkhuntia wants to merge 1 commit into
juspay:releasefrom
amreetkhuntia:feat/daily-warm-transfer-bridge
Open

feat: daily warm transfer bridge — PSTN agent leg bridged into Daily …#751
amreetkhuntia wants to merge 1 commit into
juspay:releasefrom
amreetkhuntia:feat/daily-warm-transfer-bridge

Conversation

@amreetkhuntia
Copy link
Copy Markdown
Contributor

…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:

  • utils/bridge_flag.py: Redis state machine for the bridge leg (dialing → joined → disconnected/failed), keyed by agent call_sid
  • handlers/internal/daily_warm_transfer.py: new handler; validates config, mints a fresh Daily owner token, dials agent via the lead's telephony provider, polls bridge flag, ends AI conversation on success
  • handlers/internal/warm_transfer.py: branch on DAILY execution modes and delegate to daily_warm_transfer handler
  • services/daily/transfer_bridge.py: run_bridge() builds FastAPIWebsocketTransport + DailyTransport pipelines with _AudioForwarder; marks flag joined before runner starts
  • api/routers/breeze_buddy/telephony/bridge.py: /{provider}/bridge/v2 WebSocket endpoint; validates bridge flag, calls run_bridge()
  • api/routers/breeze_buddy/telephony/init.py: mounts bridge router
  • api/routers/breeze_buddy/telephony/answer/handlers.py: checks bridge flag at answer time and returns bridge WS URL instead of AI bot path
  • agent/init.py + template/context.py: expose room_url on bot and TemplateContext so the handler can mint a token for the right room
  • .githooks/pre-commit: make uv sync non-fatal + set UV_NO_SYNC=1 so subsequent uv run calls skip re-sync on incompatible platforms
  • pyproject.toml: add pre-existing pipecat-stub-noise paths to pyrefly project-excludes (llm/stt/tts wrappers, mcp, language/tts utils)
  • docs/breeze_buddy/daily_warm_transfer.md: design doc

Copilot AI review requested due to automatic review settings May 7, 2026 10:01
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack

Warning

Rate limit exceeded

@amreetkhuntia has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 59 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3513d5c7-23f3-4ffa-b281-7b028ba1a5b0

📥 Commits

Reviewing files that changed from the base of the PR and between a40123c and 062d165.

📒 Files selected for processing (11)
  • .gitignore
  • app/ai/voice/agents/breeze_buddy/agent/__init__.py
  • app/ai/voice/agents/breeze_buddy/handlers/internal/daily_warm_transfer.py
  • app/ai/voice/agents/breeze_buddy/handlers/internal/warm_transfer.py
  • app/ai/voice/agents/breeze_buddy/services/daily/transfer_bridge.py
  • app/ai/voice/agents/breeze_buddy/template/context.py
  • app/ai/voice/agents/breeze_buddy/utils/bridge_flag.py
  • app/api/routers/breeze_buddy/telephony/__init__.py
  • app/api/routers/breeze_buddy/telephony/answer/handlers.py
  • app/api/routers/breeze_buddy/telephony/bridge.py
  • docs/breeze_buddy/daily_warm_transfer.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…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.
@amreetkhuntia amreetkhuntia force-pushed the feat/daily-warm-transfer-bridge branch from 6b1fe90 to 062d165 Compare May 7, 2026 10:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +159 to +164

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()
Comment on lines +85 to +87
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.
Comment on lines +159 to +163
# 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)
Comment on lines +179 to +183
# 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,
)
Comment on lines +540 to +544
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(
Comment on lines +37 to +41
## 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
Comment on lines +171 to +175
except Exception as e:
logger.error(
f"[BridgeRun] Bridge runtime exception for call {call_id}: {e}",
exc_info=True,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants