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
Reference¶
SimulationEvals ¶
Bases: Apps
Wrapper class to simulate entire multi-turn conversations with a CXAS Agent.
Source code in src/cxas_scrapi/evals/simulation_evals.py
simulate_conversation ¶
simulate_conversation(test_case, sim_user_model=_DEFAULT_GEMINI_MODEL, eval_model=_DEFAULT_GEMINI_MODEL, session_id=None, console_logging=True, modality='text', capture_agent_audio=False, background_noise_file=None, burst_noise_files=None, use_tool_fakes=False, voice_config=None, initial_utterance=_FIRST_UTTERANCE, skip_playback_wait=False, single_bidi_stream=False, **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_GEMINI_MODEL |
eval_model | str | None | The Gemini model used for evaluating expectations. | _DEFAULT_GEMINI_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 |
Source code in src/cxas_scrapi/evals/simulation_evals.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 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 740 741 742 743 744 745 | |
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