Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Elevenlabs Elevenlabs python UnitTestCommonModel

From Leeroopedia
Attribute Value
Page Type Implementation
Package elevenlabs
Module elevenlabs.types.unit_test_common_model
Class UnitTestCommonModel
Base Class UncheckedBaseModel
Source File src/elevenlabs/types/unit_test_common_model.py
Auto-Generated Yes (Fern API Definition)

Overview

Description

UnitTestCommonModel is a Pydantic-based data model representing a test case for evaluating an agent's response to a specific chat scenario. It defines the core structure shared by all unit test types, including the chat history, success/failure evaluation criteria, tool call evaluation parameters, dynamic variables, and optional metadata about the conversation the test originated from. This serves as the base definition that other unit test models extend.

Usage

This model is used as the common input structure when creating or updating unit tests for conversational AI agents. It encapsulates all the evaluation criteria needed to determine whether an agent's response to a given chat scenario meets expectations. The model supports flexible evaluation modes including prompt-based success conditions, example-based evaluation, and tool call parameter verification.

Code Reference

Source Location

src/elevenlabs/types/unit_test_common_model.py

Class Signature

class UnitTestCommonModel(UncheckedBaseModel):
    """
    A test case for evaluating the agent's response to a specific chat scenario.
    """
    ...

Import Statement

from elevenlabs.types.unit_test_common_model import UnitTestCommonModel

I/O Contract

Field Name Type Required Default Description
chat_history List[ConversationHistoryTranscriptCommonModelOutput] Yes N/A The chat history transcript that sets up the test scenario
success_condition str Yes N/A A prompt that evaluates whether the agent's response is successful. Should return True or False
success_examples List[AgentSuccessfulResponseExample] Yes N/A Non-empty list of example responses that should be considered successful
failure_examples List[AgentFailureResponseExample] Yes N/A Non-empty list of example responses that should be considered failures
tool_call_parameters Optional[UnitTestToolCallEvaluationModelOutput] No None How to evaluate the agent's tool call (if any). If empty, the tool call is not evaluated
check_any_tool_matches Optional[bool] No None If True, the test passes if any tool call matches the criteria. Otherwise fails if more than one tool is returned
dynamic_variables Optional[Dict[str, Optional[UnitTestCommonModelDynamicVariablesValue]]] No None Dynamic variables to replace in the agent config during testing
type Optional[UnitTestCommonModelType] No None The type classification of the unit test
from_conversation_metadata Optional[TestFromConversationMetadataOutput] No None Metadata of a conversation this test was created from (if applicable)

Usage Examples

Creating a Unit Test Definition

from elevenlabs.types.unit_test_common_model import UnitTestCommonModel

test = UnitTestCommonModel(
    chat_history=[
        {"role": "user", "message": "What are your business hours?"},
    ],
    success_condition="The agent provides accurate business hours information",
    success_examples=[
        {"response": "We are open Monday through Friday, 9 AM to 5 PM."},
    ],
    failure_examples=[
        {"response": "I don't know the answer to that."},
    ],
)

print(f"Success condition: {test.success_condition}")
print(f"Chat history entries: {len(test.chat_history)}")

Configuring Tool Call Evaluation

test_with_tool = UnitTestCommonModel(
    chat_history=[
        {"role": "user", "message": "Book a meeting for tomorrow at 2 PM"},
    ],
    success_condition="The agent correctly calls the booking tool",
    success_examples=[
        {"response": "I've booked your meeting for tomorrow at 2 PM."},
    ],
    failure_examples=[
        {"response": "I can't help with that."},
    ],
    tool_call_parameters=tool_eval_config,
    check_any_tool_matches=True,
    dynamic_variables={"current_date": "2025-01-15"},
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment