At a Glance
- Python
- TypeScript
- Create a WebRTC code (
grtc-...). - Attach your agent to that code using
agent.listen_webrtc("grtc-..."). - Start a call from the browser using
new Call({ webrtcCode: "grtc-..." }).start().
Create a WebRTC code
A WebRTC code (grtc-...) is like a phone number, but for WebRTC calls. It’s used to route calls from a browser client to your agent. Create one with the Guava CLI.
Attach your agent to the code
- Python
- TypeScript
Call
listen_webrtc with your code. Like listen_phone, it blocks and handles incoming calls until the process exits.agent.py
Install the WebRTC SDK
The WebRTC client is included in the TypeScript SDK and runs in the browser.- Using a Bundler (Recommended)
- Using a CDN
Install the SDK with your preferred package manager.Then import from
@guava-ai/guava-sdk/webrtc.Start a call
Create aCall with your WebRTC code and call start(). The browser asks for microphone permission, then connects to your agent.
onStateChange to update your UI, and hangup() to end the call.
Passing Through Metadata to the Agent
UsecustomPayload to send metadata from the browser to your agent, such as the signed-in user or the current page.
custom_payload on the incoming call’s info.
- Python
- TypeScript
agent.py
Sending and Receiving Messages
During a call, the browser and your agent can exchange JSON messages, for example to react to what the user does on the page or to update your UI from the agent. In the browser, usesendMessage to send a message to the agent, and onMessage to receive messages from it.
- Python
- TypeScript
Your agent receives browser messages in
on_webrtc_message, and sends messages to the browser with call.send_webrtc_message.agent.py