端到端測試智能體(API)
反覆優化 AI 智能體,意味著反覆優化其提示、工具, 以及處理邊緣個案的方式。模擬 API 會根據你提供的情境提示, 對智能體進行真實通話。以智能體為目標會建立智能體對智能體運行; 以電話號碼為目標則會建立 SIP 迴路運行。每次運行均會產生附有 逐字稿、評分及收費資料的真實通話記錄,讓你清楚了解智能體的 實際表現及成本。
適用於:
- 每次修改提示後進行部署前冒煙測試
- 整合至 CI 的回歸測試套件(連接
test-call.completedwebhook → 如分數下降則令建置失敗) - 壓力測試並發限制
單次執行:單一運行
curl -X POST https://api.thunderphone.com/v1/simulations \
-H "Authorization: Bearer sk_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"target_type": "agent",
"target_id": 12,
"direction": "outbound",
"scenario_prompt": "You are a polite caller asking about refund policy for order 12345.",
"consent_to_charge": true
}'
欄位:
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
target_type | 字串 | 是 | agent 或 phone_number |
target_id | 整數 | 是 | 智能體 ID(或電話號碼 ID) |
direction | 字串 | 否 | outbound(預設;測試來電者撥出)或 inbound(測試來電者接聽) |
scenario_prompt | 字串 | 否 | 控制測試機械人所說的內容 |
language / primary_language | 字串 | 否 | 測試來電者使用的語言;不支援的代碼將被拒絕 |
simulator_product | 字串 | 否 | testing(預設)或 spark,可模擬更接近真人的來電者,例如暖轉接諮詢測試 |
consent_to_charge | 布林值 | 是 | 必須為 true。預估費用會同時向所選智能體及模擬來電者收費,另加任何電話線路費用 |
target_number | 字串 | 否 | 遠端一方的 E.164 覆寫值;否則使用平台測試號碼 |
mode 為唯讀,並由 target_type 衍生:agent 會產生
mode="bot",而 phone_number 會產生 mode="sip"。
回應會傳回一個處於 status="queued" 的模擬運行物件。
持續輪詢,直至 status 變為 completed 或
failed;設定 call_id 後,可透過
GET /v1/calls/{call_id}/transcript 載入逐字稿。
批次:平行情境
同時執行 N 個情境——適合讓回歸測試套件平行處理每個已知邊緣個案:
curl -X POST https://api.thunderphone.com/v1/simulations/batches \
-H "Authorization: Bearer sk_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"target_type": "agent",
"target_id": 12,
"direction": "outbound",
"run_count": 5,
"stagger_seconds": 2,
"scenario_prompts": [
"Ask about refund policy.",
"Ask for hours of operation.",
"Complain about a delayed shipment.",
"Ask to speak with a human.",
"Ask an unrelated trivia question."
],
"consent_to_charge": true
}'
回應包含子運行 ID 的 run_ids 清單。取得批次
狀態:
curl https://api.thunderphone.com/v1/simulations/batches/{batch_id} \
-H "Authorization: Bearer sk_live_YOUR_API_KEY"
run_count 上限為 20;stagger_seconds 會將啟動時間錯開,
避免對智能體造成過高負載(0–60 秒)。
接入 CI
在 模擬測試 頁面
(/dashboard/simulations)建立發佈閘門測試套件——選擇智能體、手動新增情境,
或按一下 使用 AI 產生情境,根據智能體的提示詞草擬情境
(可選擇加入邊緣案例檢查),然後將情境歸入套件。
套件會固定其情境和智能體,並設定最低通過率及可選的零嚴重失敗規則。通過的執行結果會成為已接受的基準;其後由通過→失敗的轉變會列為回歸問題。
在 CI 中使用組織 API 金鑰。
此指令碼會觸發套件、持續輪詢至評分及比較完成,除非判定結果為 pass,否則會以非零狀態碼結束:
#!/usr/bin/env bash
set -euo pipefail
: "${THUNDERPHONE_API_KEY:?Set THUNDERPHONE_API_KEY}"
: "${THUNDERPHONE_ORG_ID:?Set THUNDERPHONE_ORG_ID}"
: "${THUNDERPHONE_SUITE_ID:?Set THUNDERPHONE_SUITE_ID}"
base="https://api.thunderphone.com/v1/orgs/${THUNDERPHONE_ORG_ID}/suites/${THUNDERPHONE_SUITE_ID}"
auth="Authorization: Bearer ${THUNDERPHONE_API_KEY}"
run_id="$(curl --fail --silent --show-error -X POST "${base}/run" \
-H "$auth" -H "Content-Type: application/json" -d '{}' | jq -r '.id')"
deadline=$((SECONDS + 1800))
while (( SECONDS < deadline )); do
result="$(curl --fail --silent --show-error \
"${base}/runs/${run_id}" -H "$auth")"
status="$(jq -r '.status' <<<"$result")"
if [[ "$status" == "completed" ]]; then
jq . <<<"$result"
[[ "$(jq -r '.verdict' <<<"$result")" == "pass" ]]
exit
fi
sleep 10
done
echo "ThunderPhone suite timed out" >&2
exit 1
POST /v1/orgs/{org_id}/suites/{suite_id}/run 會傳回包含執行 ID 的 202。GET /v1/orgs/{org_id}/suites/{suite_id}/runs/{run_id} 會傳回
status、verdict、pass_rate、critical_failure_count 及基準
regressions 清單。兩個端點均會將 URL 中的組織綁定至 API 金鑰所屬的組織。
模式
每個提示詞的回歸測試語料庫
維護一個包含 {name, scenario_prompt, expected_outcome}
元組的 JSON 檔案。每次提示詞變更時,將完整集合以批次方式執行;比較逐字稿及評分與上一次執行結果的差異。
每次發佈的冒煙測試
每次部署後執行一個包含五個正常流程情境的單一批次。此測試對延遲敏感,因此請保持 stagger_seconds: 0。
延遲基準測試
針對不同產品級別(spark、
bolt、storm-base)執行相同情境。比較每個產生的通話記錄中的 call.graded 分數及
duration_seconds。