Skip to navigation

Text Testing

Text testing runs RubricHQ’s AI-simulated caller against your agent over text instead of voice. It’s ~10× faster and far cheaper than voice testing — ideal for workflow validation, regression suites, and CI.

Configure it under Agent → Channels → Text Channel and pick a Connection type:

Connection typeUse it whenYou get
WebSocket (X-RUBRIC protocol)You can add a small WebSocket bridge to your botSecret handshake, run identification headers, end-of-chat signals both ways, agent-first greetings, and function-call visibility in the transcript
REST — OpenAI-compatibleYour bot already exposes a chat-completions style HTTP endpointZero bridge code: RubricHQ POSTs the conversation each turn, with end-of-chat signals both ways

RubricHQ is the client in both cases — it connects out to your agent; your agent never connects to RubricHQ. When the conversation ends, RubricHQ records the transcript, who ended it and why, and evaluates your metrics automatically.

Chat-only bots don’t need a phone number. If the Text channel is the only channel you enable, the phone number field becomes optional. Add a phone number or web channel later and the same agent can be tested over voice too — see Testing a voice agent over text.


Custom WebSocket

What you set in RubricHQ (Agent → Channels → Text Channel)

These are values you enter once in the RubricHQ dashboard for the agent:

FieldDescription
WebSocket URLwss://your-agent.com/ws (must start with wss:// in production)
SecretA shared secret you choose. Store the same value in your server. RubricHQ sends it on every connection as the X-RUBRIC-SECRET header so your server can verify the caller is really RubricHQ.
Per-turn timeout (s)How long RubricHQ waits for a reply to each message before failing the run. Default 120.
Max session duration (s)Hard cap on the whole conversation. Default 600.

What RubricHQ sends to your server on connect

RubricHQ includes all of these HTTP headers on every connection (the X-… row is the only conditional one — it appears only when the scenario has matching metadata). You must validate X-RUBRIC-SECRET; the others identify the agent / scenario / run so you can route and correlate.

HeaderAlways sentWhat it’s for
X-RUBRIC-SECRETYesAuthenticate the connection — compare to your stored secret; reject with WS close 1008 if it doesn’t match.
X-RUBRIC-AGENT-IDYesWhich RubricHQ agent this conversation is for. Use it to route when one endpoint serves multiple bots.
X-RUBRIC-SCENARIO-IDYesThe scenario being tested.
X-RUBRIC-RUN-IDYesThis test run’s id.
X-RUBRIC-BATCH-IDYesThe batch id (groups runs).
X-RUBRIC-CHANNELYesAlways text here. Lets one URL serve both voice and text for the same agent — see Testing a voice agent over text.
X-…When setAny scenario metadata field whose name starts with X-, forwarded verbatim — your own custom routing/context.

Messages — RubricHQ → your agent

Standard user turn:

{ "content": "I'd like to set up a payment plan" }

End signal (RubricHQ ended the conversation — the simulated customer was done, or the scenario hit its turn limit). metadata.end_reason says why:

{ "content": "", "type": "end_call", "metadata": { "end_reason": "objective_met" } }

After sending it, RubricHQ closes the connection. Treat it like the customer closing the chat window.

Messages — your agent → RubricHQ

Standard agent reply:

{ "content": "Sure — what monthly amount works for you?" }

Reply with metadata (merged into the run, last-write-wins; not a turn on its own):

{ "content": "One moment…", "metadata": { "customer_id": "cust_123" } }

Metadata-only frame (recorded, not treated as a turn):

{ "metadata": { "internal_call_id": "abc-123" } }

Function call + result (recorded in the transcript as function_call / function_call_result, not treated as a turn — keep streaming until you send the actual reply):

{ "role": "Function Call", "data": { "id": "call_1", "name": "lookup_account", "arguments": "{\"id\":\"123\"}" } }
{ "role": "Function Call Result", "data": { "id": "call_1", "result": "{\"balance\":420.00}" } }

End the conversation — send your closing line with type: "end_call", optionally with a reason (recorded on the run as bot_ended:<reason>):

{ "content": "Glad I could help — have a great day!", "type": "end_call", "metadata": { "end_reason": "resolved" } }

…or simply close the socket — RubricHQ records that as bot_disconnected. Sending end_call is better: your closing line lands in the transcript and the reason is kept.

Agents that speak first

If your agent greets the customer as soon as the connection opens (as most voice agents do), just send the greeting — RubricHQ waits about 3 seconds after connecting, records your greeting as the first turn, and the simulated customer replies to it. If nothing arrives, the simulated customer opens the chat instead.

Lifecycle & timeouts

  • Either side may end via {"type": "end_call"}, or your server can close the socket. See How a conversation ends.
  • Turn limit — each scenario has a maximum number of turns. If neither side has ended the chat by then, RubricHQ ends it and sends end_call with end_reason: max_turns_reached.
  • Per-turn idle timeout — if your agent doesn’t reply within Per-turn timeout, the run ends failed (ended_reason: agent_timeout) with the partial transcript saved.
  • Max session duration — the whole conversation is capped; exceeding it ends the run failed (max_duration).
  • A failed connection ends the run connection_failed; a mid-conversation drop ends it connection_lost.

A quick conversation (WebSocket)

A full session looks like this — each line is one frame; the label shows who sent it:

RubricHQ connects (header X-RUBRIC-SECRET: shh)
your agent → {"content": "Hi, thanks for contacting Acme. How can I help?"}
RubricHQ → {"content": "I'd like to set up a payment plan"}
your agent → {"content": "Sure — what monthly amount works for you?"}
RubricHQ → {"content": "About $150 a month"}
your agent → {"content": "Got it. Can you tell me a little more?"}
RubricHQ → {"content": "Actually that's all, thanks!"}
your agent → {"content": "You're welcome — goodbye!", "type": "end_call", "metadata": {"end_reason": "resolved"}}
conversation ends (ended_by: real_agent, ended_reason: bot_ended:resolved)
→ RubricHQ records the transcript and runs your metrics

A run with a function call looks the same, but the agent streams the call/result frames before its spoken reply (they’re recorded in the transcript but don’t count as a turn):

RubricHQ → {"content": "What's my balance?"}
your agent → {"role": "Function Call", "data": {"id": "c1", "name": "lookup_account", "arguments": "{}"}}
your agent → {"role": "Function Call Result", "data": {"id": "c1", "result": "{\"balance\":420.00}"}}
your agent → {"content": "Your balance is $420.00."}

Local development: expose your local server with a tunnel (e.g. ngrok) and use the wss:// URL in the WebSocket URL field.

Your reply comes from your agent

Your agent’s reply is produced by your real agent — an LLM, a Pipecat pipeline, a LangChain chain, your own model and tools. The WebSocket handler is only a thin bridge:

receive {"content": user_text} → your agent (LLM + your context / tools / state) → send {"content": reply}

So making an existing agent “WebSocket-ready” is just adding that bridge around your real brain. If your agent is built on Pipecat, you already have an LLM context and pipeline — feed the incoming text into your context, run the pipeline (text in → text out), and send the assistant’s text back. A full Pipecat reference ships in the voice-pipecat project, custom_ws_pipecat_agent.py: a real OpenAILLMContext + OpenAILLMService pipeline bridged to this protocol (vs. custom_ws_agent.py, the minimal hand-rolled version).

Example: a Pipecat agent

If your agent is a Pipecat pipeline, the bridge is small — push each incoming content into your LLM context, run the pipeline, and send the assistant’s text back:

# pip install websockets pipecat-ai openai
import asyncio, json, os, websockets
from pipecat.frames.frames import LLMTextFrame, LLMFullResponseEndFrame
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineTask
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext, OpenAILLMContextFrame
from pipecat.processors.frame_processor import FrameProcessor
from pipecat.services.openai.llm import OpenAILLMService
SECRET = os.environ["AGENT_SECRET"]
SYSTEM = "You are a helpful billing agent for Acme Corp. Be brief and professional."
class ResponseCapture(FrameProcessor):
"""Collect the assistant's streamed text; resolve one future per turn."""
def __init__(self):
super().__init__(); self._buf = ""; self._fut = None
def expect(self):
self._buf = ""; self._fut = asyncio.get_event_loop().create_future(); return self._fut
async def process_frame(self, frame, direction):
await super().process_frame(frame, direction)
if isinstance(frame, LLMTextFrame):
self._buf += frame.text or ""
elif isinstance(frame, LLMFullResponseEndFrame) and self._fut and not self._fut.done():
self._fut.set_result(self._buf.strip())
await self.push_frame(frame, direction)
async def handler(ws):
if ws.request.headers.get("X-RUBRIC-SECRET") != SECRET:
await ws.close(1008, "Unauthorized"); return
# Your existing Pipecat "brain": context + LLM + aggregator.
context = OpenAILLMContext(messages=[{"role": "system", "content": SYSTEM}])
llm = OpenAILLMService(api_key=os.environ["OPENAI_API_KEY"], model="gpt-4o-mini")
agg = llm.create_context_aggregator(context) # appends assistant replies to context
capture = ResponseCapture()
task = PipelineTask(Pipeline([llm, capture, agg.assistant()]))
runner_task = asyncio.create_task(PipelineRunner(handle_sigint=False).run(task))
async def ask(text): # one user turn -> assistant reply
context.add_message({"role": "user", "content": text})
fut = capture.expect()
await task.queue_frame(OpenAILLMContextFrame(context))
return await asyncio.wait_for(fut, timeout=30)
try:
await ws.send(json.dumps({"content": "Hi, thanks for contacting Acme. How can I help?"}))
async for raw in ws:
msg = json.loads(raw)
if msg.get("type") == "end_call":
break
await ws.send(json.dumps({"content": await ask(msg.get("content", ""))}))
finally:
runner_task.cancel()
async def main():
async with websockets.serve(handler, "0.0.0.0", 8080):
await asyncio.Future()
asyncio.run(main())

That’s the heart of the full reference custom_ws_pipecat_agent.py, which additionally routes on X-RUBRIC-AGENT-ID and parses inline <dtmf/> tags. Any other framework (LangChain, your own model) follows the same shape: content in → your agent → content out.


REST — OpenAI-compatible

If your bot already speaks the OpenAI Chat Completions format, point RubricHQ at it — no bridge code needed.

What you set in RubricHQ (Agent → Channels → Text Channel → REST)

FieldDescription
Endpoint URLYour base URL, e.g. https://bot.example.com/v1. RubricHQ appends /chat/completions unless the URL already ends with it.
API keySent on every request both as Authorization: Bearer <key> (what OpenAI-style servers expect) and as X-RUBRIC-SECRET: <key> — validate whichever you prefer; one X-RUBRIC-SECRET check then covers your WebSocket and REST endpoints alike.
API formatOpenAI Chat Completions (recommended) or Anthropic Messages.
Per-turn timeout (s) / Max session duration (s)Same as WebSocket: a request that gets no response within the per-turn timeout ends the run as agent_timeout.

What RubricHQ sends each turn

One POST per customer message, carrying the whole conversation so far (user = the simulated customer, assistant = your bot’s earlier replies):

POST /v1/chat/completions
Authorization: Bearer <your key>
X-RUBRIC-SECRET: <your key>
X-RUBRIC-CHANNEL: text
X-RUBRIC-AGENT-ID: 46
X-RUBRIC-SCENARIO-ID: 512
X-RUBRIC-RUN-ID: 9031
X-RUBRIC-BATCH-ID: 544
Content-Type: application/json
{ "messages": [
{ "role": "user", "content": "hi, where's my order?" },
{ "role": "assistant", "content": "Happy to help! What's your email?" },
{ "role": "user", "content": "priya@example.com" } ] }

RubricHQ sends only messages — your server picks the model. Reply with a normal chat completion:

{ "choices": [ { "message": { "role": "assistant", "content": "Thanks! Your order ships tomorrow." }, "finish_reason": "stop" } ] }

Keep state per conversation, not per request. If your bot’s tools change things (cancel an order, issue a refund), key that state on X-RUBRIC-RUN-ID — it’s the same for every turn of one test conversation.

Ending the chat over REST

HTTP has no socket to close, so both sides say it explicitly.

Your bot ends the chat — include any one of these in the response; the reply text is recorded as your closing line:

{ "choices": [ { "message": { "role": "assistant", "content": "All sorted — goodbye!" }, "finish_reason": "end_call" } ],
"end_call": true,
"end_reason": "resolved" }
Signal (any one is enough)Where
"finish_reason": "end_call" (or "end_conversation")choices[0]
"end_call": true, "end_conversation": true or "type": "end_call"top level
A tool call named end_call, end_chat or end_conversationchoices[0].message.tool_calls — its reason argument is used as the reason

end_reason (top level) is optional and recorded on the run as bot_ended:<reason>.

RubricHQ ends the chat — when the simulated customer is done or the turn limit is hit, RubricHQ sends one last POST to the same URL. Recognise it by the X-RUBRIC-EVENT: end_call header (or "type": "end_call" in the body), close the conversation on your side, and return any 2xx — the response body is ignored and your model doesn’t need to run:

POST /v1/chat/completions
X-RUBRIC-EVENT: end_call
X-RUBRIC-RUN-ID: 9031
{ "messages": [ ... ], "type": "end_call", "end_call": true, "end_reason": "objective_met" }

RubricHQ’s REST transcripts contain the messages only. If you want tool calls to appear in the transcript (and be available to your metrics), use the WebSocket connection, which streams Function Call frames.


How a conversation ends

When does it close?

A test conversation stops at the first of these:

LimitWebSocketREST
Either side sends an end signal{"type": "end_call"} frame, then RubricHQ closes the socketend flag in your response / RubricHQ’s final X-RUBRIC-EVENT: end_call POST
Turn limit — set per scenario (Max turns, default 20; one turn = one customer message + your reply)RubricHQ sends end_call with max_turns_reachedRubricHQ sends the final end_call POST with max_turns_reached
Per-turn timeout — set on the agent (default 120 s)no reply frame in time → run fails agent_timeoutno HTTP response in time → run fails agent_timeout
Max session duration — set on the agent (default 600 s)whole conversation over the cap → run fails max_durationsame
Your bot closes the socketbot_disconnected— (no socket)

There is no other hidden cap: a WebSocket stays open between turns until one of the above happens, and over REST nothing is held open between requests.

Who ended it

Every text run ends with a named ender, stored on the run as ended_by and ended_reason. Exactly one side always ends it: your bot, or RubricHQ’s simulated customer (which also enforces the turn limit).

What happenedended_byended_reason
The simulated customer finished (goal met, gave up, dead end…)test_agenttest_agent_end_conversation:<reason> — e.g. objective_met, natural_conclusion, user_frustration, dead_end
The scenario’s turn limit was reachedtest_agentmax_turns_reached
Your bot sent an end signalreal_agentbot_ended:<reason> (or bot_ended with no reason)
Your bot closed the WebSocketreal_agentbot_disconnected
Your bot returned an empty replyreal_agentbot_empty_response
Your bot didn’t reply in time / the connection failed or dropped / the session cap was hitsystemagent_timeout, connection_failed, connection_lost, max_duration

Runs in the system rows are marked failed; the others complete and are evaluated normally. Use ended_by to spot bots that never close a conversation (always test_agent) or that hang up too early (real_agent before the goal was met).


Testing a voice agent over text

A text run doesn’t care how your agent is normally reached. If you already test an agent over phone or web, you can test the same agent over text — same instructions, same tools — to iterate on its logic much faster:

  1. Expose a text endpoint for it (WebSocket or REST, as above). Most voice agents greet first; over WebSocket just send the greeting on connect. Tip — one URL for both channels. Every text connection carries X-RUBRIC-CHANNEL: text, so you can keep the agent’s existing voice WebSocket URL (e.g. wss://bot.example.com/ws?agent_id=nora) and branch on that header: no header → run your voice pipeline, text → run the same agent in text mode. Same URL, same agent name, same X-RUBRIC-SECRET.
  2. In RubricHQ, open the agent and enable the Text channel alongside its voice channels.
  3. Mark the scenarios you want to reuse as testing type Text or Both.
  4. Start a batch with testing mode Text.

Transcript metrics (policy, compliance, resolution, custom judges) run the same way on both channels, so you can compare a scenario’s text and voice results side by side. Audio metrics are skipped on the text runs.


DTMF (keypad input)

When a scenario enables the send_dtmf tool, the simulated caller can “press keypad digits” during a text conversation. Rather than a separate frame, it sends the digits as an inline tag embedded in a normal text message:

{ "content": "Sure, entering it now. <dtmf digits=\"1234#\"/>" }

Your agent should parse <dtmf digits=\"...\"/> out of the message content, treat the matched digits as the caller’s keypad entry, and strip the tag before handling the text. Valid characters are 0-9, *, and #. A simple regex works:

import re
m = re.search(r'<dtmf\s+digits="([^"]*)"\s*/>', content)
digits = m.group(1) if m else None

The full message (tag included) is recorded in the transcript, so DTMF entries are visible in the run results.


Testing multiple agents on one endpoint

In RubricHQ you create one agent per bot you want to test. If those bots share a single endpoint, your server still needs to know which bot a given request/connection is for. RubricHQ tells you in two ways — pick whichever fits:

Option A — Read the X-RUBRIC-AGENT-ID header. Every WebSocket connection (and every REST request) carries X-RUBRIC-AGENT-ID, the RubricHQ agent id. Map each agent id to your bot once (the id is stable per agent), then dispatch on the header:

agent_id = headers.get("X-RUBRIC-AGENT-ID") # e.g. "7"
bot = MY_BOTS[agent_id] # your mapping

Option B — Put the bot in the URL. Give each RubricHQ agent a distinct path or query as its WebSocket URL — works on the same host and port:

wss://host/ws/billing (or wss://host/ws?bot=billing)

RubricHQ connects to exactly the URL configured for that agent, so your router reads the path/query and dispatches.

You can also attach your own identifier: any scenario metadata field whose name starts with X- is forwarded verbatim as a header, so e.g. a scenario field X-Bot-Id = billing arrives as the X-Bot-Id header. (Use this for per-scenario routing; use X-RUBRIC-AGENT-ID or the URL for per-agent routing.)

Validate X-RUBRIC-SECRET first, then route on X-RUBRIC-AGENT-ID (or the URL). The other headers (X-RUBRIC-SCENARIO-ID, X-RUBRIC-RUN-ID, X-RUBRIC-BATCH-ID) identify the specific scenario / run / batch within that agent.

Test your endpoint before going live

You don’t need to launch a full RubricHQ run to validate your endpoint. Three levels of dev testing:

1. Probe it yourself (no RubricHQ needed). This small script mimics exactly what RubricHQ sends — it connects with the X-RUBRIC-* headers, sends a few user turns, and prints every frame your agent returns. Point it at your wss:// URL (local or staging):

# rubric_ws_probe.py — pip install websockets
# python rubric_ws_probe.py wss://localhost:8080/ws your-secret
import asyncio, json, sys, websockets
async def main(url, secret):
headers = {
"X-RUBRIC-SECRET": secret,
"X-RUBRIC-AGENT-ID": "probe",
"X-RUBRIC-SCENARIO-ID": "1",
"X-RUBRIC-RUN-ID": "1",
"X-RUBRIC-BATCH-ID": "1",
}
async with websockets.connect(url, additional_headers=headers) as ws:
print("connected:", url)
for turn in ["Hi, I'd like to check my balance", "My account is 12345", "No, that's all — thanks"]:
await ws.send(json.dumps({"content": turn})); print("→", turn)
while True: # your agent may send fn-call / metadata before its reply
msg = json.loads(await asyncio.wait_for(ws.recv(), timeout=30)); print("← ", msg)
if msg.get("type") == "end_call": return
if "content" in msg: break
await ws.send(json.dumps({"content": "", "type": "end_call"})); print("→ end_call")
asyncio.run(main(sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else ""))

2. Dry-run one scenario in the app. Use Live Simulations to run a single scenario against your endpoint and watch the transcript and metrics live, instead of launching a full batch — ideal for the first real round-trip.

3. Local development. Expose your local server with a tunnel (e.g. ngrok http 8080) so RubricHQ — or the probe above — can reach wss://… while you iterate.

Once the probe and a single Live Simulation pass, you’re ready to run full batches in production.

Metrics on text runs

  • Transcript / LLM metrics (compliance, resolution, custom LLM judges, etc.) run on text exactly as on voice.
  • Audio metrics (latency, interruptions, WPM, voice clarity…) are automatically skipped for text — there’s no audio.
  • When creating a custom metric, Applies to lets you choose Text and Voice conversations (default) or Text Conversation only. A text-only metric won’t run on voice; anything that runs on voice also runs on text.

Results

After a run completes you’ll see the transcript (including any function-call frames), the metric evaluations, and who ended the conversation and why (ended_by / ended_reason, see How a conversation ends). Text runs show no recording section.

A scenario’s pass/fail (call success) is based on its critical metrics. A critical metric the judge marks not applicable to that conversation — e.g. “verified identity before account access” on a chat that never touched an account — doesn’t count against the run.