WebRTC for Voice Connections
Join your voice agent through LiveKit, Pipecat, or your own signaling URL, and link each call to its trace.
Overview
Use the WebRTC transport when your voice agent talks over WebRTC instead of a phone line. Confident AI joins your agent as a participant and talks to it over audio. Choose your Provider at the top of the WebRTC tab:
- LiveKit (default): your agent runs on LiveKit.
- Pipecat: your agent runs on Pipecat, on Pipecat Cloud or your own server.
- Custom signaling: your agent accepts an SDP offer at a URL you host.
WebRTC calls don't ring, so the Ring timeout call limit doesn't apply and the Test call console shows Connect instead of Dial.
Configuring Your Provider
Confident AI creates a room in your LiveKit project, dispatches your agent into it, and joins as the caller.
| Field | Description |
|---|---|
| LiveKit URL | Your LiveKit server URL. It must start with wss://, for example wss://your-project.livekit.cloud. |
| API key | The API key of the LiveKit project your agent runs in. Found under Settings → Keys in LiveKit Cloud. |
| API secret | The API secret paired with the key. Used to mint the token the simulated caller joins the room with. |
| Agent name (optional) | The agent to dispatch into the room. Leave it blank if your agent joins every new room automatically. |
| Dispatch metadata (optional) | Values sent to your agent as JSON when each call starts, as fixed key-value pairs or built by code from each call's golden. See Passing Data to Your Agent. |
Confident AI starts a session on your Pipecat agent, then joins it as the caller.
| Field | Description |
|---|---|
| Start URL | Where Confident AI starts a Pipecat session. It must start with https://, for example https://api.pipecat.daily.co/v1/public/my-agent/start. |
| Transport | The transport your Pipecat agent runs on: Daily or SmallWebRTC (default). |
| API key (optional) | Your Pipecat Cloud public API key, sent as a bearer token. |
| Signaling headers (optional) | Extra headers sent when starting the session, for example for authentication. |
| Request body (optional) | Values sent in the body of the start request when each call starts, as fixed key-value pairs or built by code from each call's golden. See Passing Data to Your Agent. |
With Daily, Confident AI asks the start URL to create a Daily room and joins it. With SmallWebRTC, it starts a session and sends its SDP offer to that session. If your agent runs the SmallWebRTC runner yourself, you can also enter its /api/offer URL directly as the start URL.
Enter your agent's Signaling URL. It must start with https:// or wss://:
https://: Confident AIPOSTs an SDP offer to the URL withContent-Type: application/sdp, and expects an SDP answer back, either as the raw body or as JSON with ansdpfield.wss://: Confident AI sends{"type": "offer", "sdp": "..."}over the socket, and expects{"type": "answer", "sdp": "..."}back. ICE candidates can be exchanged as{"type": "candidate", ...}messages.
Signaling headers (optional) are sent with the SDP offer, so this is where you'd put an API key or bearer token your agent expects. During simulations, Confident AI also sends an X-Confident-Test-Case-Id header you can use to link calls to traces.
Passing Data to Your Agent
Use Dispatch metadata (LiveKit) or Request body (Pipecat) to pass your agent any values it needs at the start of a call. Pick how the values are built with the tabs above the field:
- Key-value: fixed pairs, sent the same with every call on the connection. Use it for settings of the agent itself.
- Code: a Python function that builds the values from each simulated call's golden. Use it when the values depend on the test case, so one connection can cover goldens that need different values.
Building Values From the Golden
In Code mode, define generate_payload. It receives the conversational golden behind the simulated call and returns a dict, which is sent to your agent as is:
from deepeval import ConversationalGolden
def generate_payload(golden: ConversationalGolden) -> dict:
return {"your_key": golden.additional_metadata["your_key"]}The golden has every field it has in the dataset, such as scenario, expected_outcome, user_description, persona and additional_metadata. Type golden. in the editor to see them all.
- The code runs once for each simulated call. Test calls from the Test call console have no golden, so nothing is sent for them.
- Syntax errors are underlined as you type, and the connection can't be saved until they're fixed.
- If the code raises an error or doesn't return a dict, the simulated call fails with that error.
Reading the Values
The values arrive as a JSON string in the job's metadata:
import json
from livekit.agents import JobContext
async def entrypoint(ctx: JobContext):
metadata = json.loads(ctx.job.metadata or "{}")
value = metadata.get("your_key")Dispatch metadata is sent with the agent dispatch, so it needs an Agent name.
The values arrive as the start request's body, which your bot receives as runner_args.body:
from pipecat.runner.types import RunnerArguments
async def bot(runner_args: RunnerArguments):
value = (runner_args.body or {}).get("your_key")During simulations, the body also carries confident_test_case_id, which Confident AI uses to link calls to traces. If your start URL is your runner's /api/offer URL, no start request is made, so a request body can't be sent and the call fails until you use a start URL or remove the values.
Custom signaling has no equivalent; use Signaling headers to pass values to a custom agent.
Testing Your Connection
Click Connect in the Test call console. The console shows Connecting… while Confident AI joins your agent. See Testing Your Connection for what each result means.
Once your agent answers, a line under the result reads Waiting for trace with a View trace link. Your agent sends the trace after the call ends, so opening it early shows that it hasn't arrived yet and then the trace itself, a few seconds after the call ends. The line then reads Trace received, or No trace received if nothing arrived. Answered test calls under Recent calls are marked Traced once their trace arrives. See Linking Traces below.
Linking Traces
When your voice agent sends traces to Confident AI, each simulated call is linked to the trace your agent produced for it. The turns themselves stay as Confident AI transcribed them; linking adds the trace alongside them:
- Trace per test case — a View trace link on the test case opens the trace behind the call, with every tool call, retrieval, and LLM step your agent took.
- Span per turn — each turn gets a View span link that opens that turn's span, so you can see what your agent heard and did for that exact exchange. Both links appear with the turns, while the call is still going; opened before the trace arrives, they show that your agent hasn't sent it yet and then the trace or span once it lands.
- No separate setup — the tracing you already use in production is all that simulations need.
Voice Frameworks
If your agent is built on LiveKit Agents or Pipecat and is traced with confident-trace, there is nothing else to set up. Confident AI handles linking behind the scenes: just make sure your agent is traced.
from confident_trace import init
from livekit.agents import AgentServer
init()
server = AgentServer()from confident_trace import init
init()import { init } from "confident-trace";
init();Run your agent with the preload:
node --import confident-trace/register dist/agent.js devSee the LiveKit and Pipecat integrations for the full setup.
Custom Signaling
If you host your own WebRTC agent, Confident AI includes each call's test case ID as an X-Confident-Test-Case-Id header on the SDP offer. Read it where your agent accepts the call, and wrap the conversation in a trace_context / traceContext so every trace your agent produces is linked to that test case:
import asyncio
from aiohttp import web
from confident_trace import init, trace_context
init()
async def offer(request: web.Request) -> web.Response:
sdp = await request.text()
answer, run_conversation = await start_call(sdp)
test_case_id = request.headers.get("X-Confident-Test-Case-Id")
async def traced():
with trace_context(test_case_id=test_case_id):
await run_conversation()
asyncio.create_task(traced())
return web.Response(text=answer, content_type="application/sdp")import express from "express";
import { init, traceContext } from "confident-trace";
init();
const app = express();
app.use(express.text({ type: "application/sdp" }));
app.post("/offer", async (req, res) => {
const { answer, runConversation } = await startCall(req.body);
void traceContext(
{ testCaseId: req.get("X-Confident-Test-Case-Id") },
runConversation,
);
res.type("application/sdp").send(answer);
});How It Works
Every simulated call carries the ID of the test case it belongs to—in the LiveKit room name, in the Pipecat start request, or in the X-Confident-Test-Case-Id header. When your agent traces the call, that ID comes back on the trace, and Confident AI attaches the trace to the test case as soon as it arrives, whether the run is still going or has finished.
Turns are paired with the trace's turn spans by when they started: LiveKit records a span for each user turn and each agent turn, and Pipecat one turn span that covers both sides. A custom agent's traces are attached to the test case but not to individual turns.
Next Steps
Multi-Turn Evals
Run multi-turn evaluations against your voice connection.
LiveKit Integration
Trace your LiveKit voice agent in production.
Last updated on