SimulationEvals¶
SimulationEvals runs AI-driven end-to-end conversation simulations against your CXAS agent. Instead of scripting exact utterances, you describe goals and success criteria — and a Gemini model figures out what to say at each turn to try to achieve them. This is a great way to test how your agent handles realistic, messy, unpredictable conversations.
Here are the key concepts:
Step(Pydantic model) — a single goal within a simulation, with agoal,success_criteria, optionalresponse_guide, and amax_turnslimit. Steps can also include astatic_utterancefor when you want a fixed first message, andinject_variablesfor seeding session state.StepStatusenum — tracks whether each step isNOT_STARTED,IN_PROGRESS, orCOMPLETED.simulate_conversation()— drives the full multi-turn loop, returning anLLMUserConversationobject that contains the transcript, step progress, and expectation results.generate_report()— produces aSimulationReportwith two DataFrames: goal progress and expectation results. It renders as styled HTML in a Jupyter notebook.
Quick Example¶
from cxas_scrapi import SimulationEvals
from cxas_scrapi.utils.rate_limiter import RateLimiter
app_name = "projects/my-project/locations/us/apps/my-app-id"
# Optional: configure a rate limiter to pace simulation turns and prevent quota exhaustion
limiter = RateLimiter(requests_per_minute=30.0)
sim = SimulationEvals(app_name=app_name, rate_limiter=limiter)
test_case = {
"steps": [
{
"goal": "User wants to check their account balance",
"success_criteria": "Agent provides a numeric balance and account status",
"max_turns": 5,
},
{
"goal": "User asks to dispute a charge",
"success_criteria": "Agent acknowledges the dispute and provides a reference number",
"max_turns": 8,
},
],
"expectations": [
"The agent should never ask for the full credit card number",
"The agent should offer to escalate if it cannot resolve the dispute",
],
}
# Run the simulation
conversation = sim.simulate_conversation(
test_case=test_case,
console_logging=True,
)
# View the report
report = conversation.generate_report()
print(report) # Colorized in terminal, styled HTML in Jupyter
Naturalness Metric (optional)¶
SimulationEvals can also grade how human the agent sounds. The metric is opt-in: a test case that does not declare a naturalness_metric block behaves exactly as before, with no extra Gemini call and no extra keys in the results. See the Local Simulations guide for the YAML schema and worked examples.
NaturalnessConfig(Pydantic model) — the per-test-case configuration: which model grades, which qualities are scored, the label bands, the turn/conversation blend weight, the perceived-latency bands and weight, and an optionalpass_threshold. Unknown keys are tolerated, so newer YAML still loads.NaturalnessResult— the aggregate result for one simulation:overall_score,overall_label, per-turn gradings, conversation-level factors,factor_averages,label_counts,latency_ms_by_turn,failure_reasons, andpassed. Exposed asconversation.naturalness_result.TurnNaturalness— the grading for a single agent turn: its label, 1–5 score, justification, and the factors behind it.NaturalnessFactor— one scored quality (e.g.pacing) with its 1–5 score, an optional shortvaluedescriptor, and the evidence-citingreason.NaturalnessLabelenum —Bot-like,Transitional, orHuman-like.evaluate_naturalness()— grades a simulation trace directly, optionally against the agent's recorded audio and the platform's per-turn perceived latency. ReturnsNone(after logging) when there is nothing to grade or the grading call fails, so the metric can never break a run.
In audio modality the agent's recordings are attached to the grading call automatically, so pacing and emotion are judged from what the caller heard. perceivedLatency is measured from the conversation trace rather than judged, and a turn past latency_failure_threshold_ms fails the simulation outright.
Audio Analysis (optional)¶
SimulationEvals can run comprehensive perceptual and acoustic voice evaluations by setting audio_analysis=True (off by default):
- Perceptual Audio Checks: Runs 5 Gemini checks (voice consistency, pauses, looping, cutoff, agent trouble).
- Acoustic Consistency: Measures ITU-R BS.1770 LUFS loudness, articulation rate, and F0 pitch stability.
- Voice Drift Detection: Identifies cross-turn timbre and pitch seams, audio truncation, and loudness steps.
- Multi-Voice Caller Pool (
sim_user_voices): Passsim_user_voices=["en-US-Journey-D", "es-US-Journey-F", ...]toSimulationEvalsorrun_simulations()to deterministically assign locale-matched (en-US/es-US) TTS voices across scenarios via CRC32 hashing. - Zero-Caller-Turn Inconclusive Retry: Sessions where
expected_caller_turns(tc) > 0butactual_caller_turns(row) == 0are automatically classified as inconclusive ("caller turns never reached agent (0 turns)") and retried duringinfra_retrieswaves.
Platform Milestone Evaluations (CXAS 2.0)¶
SimulationEvals also supports converting simulation test cases into CXAS 2.0 scenario.milestones evaluations and executing them directly on the CX Agent Studio platform:
to_milestone_yaml(test_cases)— sanitizes and converts one or more simulation test cases into CXAS 2.0 Milestone YAML (evals:format compatible with CESMilestoneYamlTranslator).push_to_platform(test_cases, conflict_strategy="OVERWRITE")— converts and imports simulation test cases onto the platform as Milestone evaluations via:importEvaluations.run_simulations_on_platform(test_cases, runs=1, timeout_seconds=600, use_tool_fakes=None)— imports, triggersRunEvaluation(withEvaluationConfig.tool_call_behaviourset toFAKEwhenuse_tool_fakes=True), waits for completion, and returns results formatted as standard simulation result dictionaries.requires_local_execution(test_case)— checks whether a test case uses local-only features (modality: "audio",audio_expectations,audio_analysis,voice_config,naturalness_metric, orbarge_in_after_ms). Tool fakes (use_tool_fakes) are supported directly on the platform.run_simulations(..., run_on_platform=True, platform_timeout=600, use_tool_fakes=None)— automatically partitionstest_casesinto platform-compatible cases (executed viarun_simulations_on_platform, forwardinguse_tool_fakes) and local-only cases (executed locally viasimulate_conversation). Run-level audio settings (audio_analysis,capture_agent_audio,background_noise_file,burst_noise_files) automatically force local execution.
Reference¶
SimulationEvals ¶
SimulationEvals(app_name, rate_limiter=None, expectations_only=False, deployment_id=None, vertex_location='global', naturalness=None, audio_analysis=False, sim_user_voices=None, **kwargs)
Bases: Apps
Wrapper class to simulate entire multi-turn conversations with a CXAS Agent.
Source code in src/cxas_scrapi/evals/simulation_evals.py
requires_local_execution staticmethod ¶
Checks if a test case requires local execution (cannot be run as a platform Milestone eval).
Returns:
| Type | Description |
|---|---|
tuple[bool, str] | (requires_local: bool, reason: str) |
Source code in src/cxas_scrapi/evals/simulation_evals.py
to_milestone_yaml ¶
Converts simulation test case(s) into CES Platform Milestone YAML.
Source code in src/cxas_scrapi/evals/simulation_evals.py
push_to_platform ¶
Pushes simulation test case(s) to CES as Milestone evaluations.
Source code in src/cxas_scrapi/evals/simulation_evals.py
run_simulations_on_platform ¶
Pushes and runs simulations on the CES platform via RunEvaluation, returning results formatted as simulation result dictionaries.
Source code in src/cxas_scrapi/evals/simulation_evals.py
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 | |
simulate_conversation ¶
simulate_conversation(test_case, sim_user_model=_DEFAULT_SIM_USER_MODEL, eval_model=_DEFAULT_EVAL_MODEL, session_id=None, console_logging=True, modality='text', capture_agent_audio=False, background_noise_file=None, bg_noise_snr=None, burst_noise_files=None, burst_noise_snr=None, use_tool_fakes=False, voice_config=None, initial_utterance=_FIRST_UTTERANCE, skip_playback_wait=False, single_bidi_stream=False, max_turns=None, naturalness=None, audio_analysis=None, **kwargs)
Runs the simulated conversation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_case | dict[str, Any] | The test case dictionary defining evaluation steps. | required |
sim_user_model | str | None | The Gemini model used for the simulated user. | _DEFAULT_SIM_USER_MODEL |
eval_model | str | None | The Gemini model used for evaluating expectations. | _DEFAULT_EVAL_MODEL |
console_logging | bool | Whether to print interaction transcript to the console. | True |
single_bidi_stream | bool | For audio modality, keep one persistent bidi WebSocket open for the whole conversation instead of opening a new connection per turn (the default). | False |
max_turns | int | None | Maximum number of conversation turns. Defaults to the test_case's max_turns setting, or 30 if unspecified. | None |
naturalness | bool | dict[str, Any] | None | Overrides the test case's | None |
audio_analysis | bool | None | Run multimodal audio checks, acoustic metrics, and voice drift analysis. Defaults to instance setting. | None |
Source code in src/cxas_scrapi/evals/simulation_evals.py
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 | |
run_simulations ¶
run_simulations(test_cases, runs=1, parallel=1, sim_user_model=_DEFAULT_SIM_USER_MODEL, eval_model=_DEFAULT_EVAL_MODEL, modality='text', verbose=False, capture_agent_audio=False, background_noise_file=None, bg_noise_snr=None, burst_noise_files=None, burst_noise_snr=None, use_tool_fakes=False, expectations_only=None, skip_playback_wait=False, single_bidi_stream=False, progress_callback=None, naturalness=None, audio_analysis=None, infra_retries=2, retry_parallel=None, retry_cooldown=60.0, run_on_platform=False, platform_timeout=600, sim_user_voices=None)
Runs multiple simulations, optionally in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_cases | list[dict[str, Any]] | List of test case dictionaries. | required |
runs | int | Number of runs per test case. | 1 |
parallel | int | Number of parallel workers (capped at 25). | 1 |
sim_user_model | str | None | Gemini model to use for simulated user. | _DEFAULT_SIM_USER_MODEL |
eval_model | str | None | Gemini model to use for evaluating expectations. | _DEFAULT_EVAL_MODEL |
modality | str | 'text' or 'audio'. | 'text' |
verbose | bool | Whether to log to console (only active if parallel=1). | False |
use_tool_fakes | bool | Use fake tools for the session if available. | False |
capture_agent_audio | bool | If True, capture real-time agent audio WAVs. | False |
naturalness | bool | dict[str, Any] | None | Run-level override for the optional Naturalness Metric. Leave as None to honour each test case's own | None |
audio_analysis | bool | None | Run multimodal audio checks, acoustic metrics, and voice drift analysis. Defaults to instance setting. | None |
run_on_platform | bool | If True, executes platform-compatible cases via CES Milestone evals. | False |
platform_timeout | int | Max seconds to wait for platform evaluation run. | 600 |
Source code in src/cxas_scrapi/evals/simulation_evals.py
2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 | |
export_results_to_golden ¶
Exports simulation results to a Golden Evaluation YAML file.
Fetches the full conversation trace for each simulation from the platform to ensure accuracy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results | list[dict[str, Any]] | The list of results returned by run_simulations. | required |
output_path | str | None | Optional local path to save the generated YAML. | None |
Returns:
| Type | Description |
|---|---|
str | The generated YAML string. |
Source code in src/cxas_scrapi/evals/simulation_evals.py
Step ¶
Bases: BaseModel
StepStatus ¶
Bases: str, Enum
SimulationReport ¶
A report containing both Goals and Expectations DataFrames.
Source code in src/cxas_scrapi/evals/simulation_evals.py
NaturalnessConfig ¶
Bases: BaseModel
Per-test-case configuration for the Naturalness Metric.
Unknown keys are preserved rather than rejected so that a YAML file written against a newer version of the library still loads here.
NaturalnessResult ¶
Bases: BaseModel
Aggregated Naturalness Metric result for a whole simulation.
TurnNaturalness ¶
Bases: BaseModel
Naturalness grading for one agent turn.
NaturalnessFactor ¶
Bases: BaseModel
A single scored conversational quality, e.g. pacing or grammarStyle.
NaturalnessLabel ¶
Bases: str, Enum
Graded label assigned to an agent turn and to the whole call.
evaluate_naturalness ¶
evaluate_naturalness(gemini_client, model_name, trace, config, audio_paths=None, latency_ms_by_turn=None)
Grades the naturalness of every agent turn in a simulation trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gemini_client | Any | A | required |
model_name | str | Fallback model, used when the config does not pin one. | required |
trace | list[str] | The simulation's | required |
config | NaturalnessConfig | Resolved metric configuration. | required |
audio_paths | dict[int, str] | None | Optional map of turn index to the agent's recorded audio, as either a | None |
latency_ms_by_turn | dict[int, float] | None | Optional map of turn index to the platform's reported perceived latency in ms. When supplied, each turn gains a computed | None |
Returns:
| Name | Type | Description |
|---|---|---|
A | NaturalnessResult | None | class: |
NaturalnessResult | None | grade or the grading call failed. Failures are logged rather than | |
NaturalnessResult | None | raised so the metric can never break a simulation run. |
Source code in src/cxas_scrapi/evals/naturalness.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | |