AiTestingDefinition Metadata API Reference

To define tests that run on the /einstein/ai-testing Connect API resources, use the AiTestingDefinition Metadata API type.

AiTestingDefinition is the successor to AiEvaluationDefinition. If you have tests that use the legacy type, see the legacy Metadata API reference.

Note

AiTestingDefinition 

Represents a test suite: the agent or prompt template being tested, the test cases to run, and the scorers that grade each test case.

In Metadata API, you create test definitions, including inputs and scorers, and deploy them to different orgs. In Connect API, you run the tests, poll for status, and retrieve results.

This type extends the Metadata metadata type and inherits its fullName field.

File Suffix and Directory Location 

AiTestingDefinition components have the suffix .aiTestingDefinition and are stored in the aiTestingDefinitions folder.

Version 

AiTestingDefinition components are available in API version 66.0 and later. Deploying with an earlier version in package.xml fails.

Fields 

Field NameTypeDescription
descriptionstringThe purpose of the test suite.
namestringRequired. The API name of the test suite. Must be unique in your org, begin with a letter, and not end with an underscore or contain consecutive underscores. Can contain only alphanumeric characters and underscores.
subjectNamestringRequired. The API name of the agent or prompt template being tested. For an agent, find the API name on the agent details page in Setup.
subjectTypestringRequired. The type of subject being tested. Valid values are AGENT and PROMPT. The type determines the shape of each test case’s inputs and which scorers you can use.
subjectVersionstringThe version of the subject to test. If not provided, the latest active version is used. For agents, you can find the version in the BotVersion metadata type.
testCaseAiTestCase[] or AiPromptTestCase[]A list of test cases. Use AiTestCase when subjectType is AGENT. Use AiPromptTestCase when subjectType is PROMPT.

AiTestCase 

Represents a test case for an agent.

Field NameTypeDescription
inputsAiTestCaseInputRequired. The input sent to the agent.
numberintThe number that identifies the test case, unique within the test suite. If not provided, the value is automatically calculated.
scorerAiTestCaseScorer[]Required. The scorers that grade the agent’s response to this test case.
AiTestCaseInput

Represents the input for an agent test case.

Field NameTypeDescription
utterancestringRequired. The request sent to the agent.
contextVariableAiTestCaseContextVariable[]The context variables sent to the agent. Repeat the element for each variable. Use the variable names defined for your agent.
conversationHistoryAiTestCaseConversationTurn[]The earlier messages in the conversation, sent to the agent before utterance. Repeat the element for each message.
AiTestCaseContextVariable

Represents a context variable sent to the agent.

Field NameTypeDescription
variableNamestringRequired. The name of the context variable.
variableValuestringRequired. The value of the context variable.
AiTestCaseConversationTurn

Represents one message in the conversation history sent to the agent.

Field NameTypeDescription
rolestringThe role associated with the message. Valid values are user and agent. A conversation must begin with a message from the user.
messagestringThe text from the user or agent.
topicstringRequired when role is agent. The API name of the subagent the agent used to generate the response.
indexintA zero-based index for this conversation message.

AiPromptTestCase 

Represents a test case for a prompt template.

Field NameTypeDescription
inputsAiPromptTestCaseInputRequired. The values sent to the prompt template.
numberintThe number that identifies the test case, unique within the test suite. If not provided, the value is automatically calculated.
scorerAiTestCaseScorer[]Required. The scorers that grade the prompt template’s response to this test case.
AiPromptTestCaseInput

Represents the input for a prompt template test case.

Field NameTypeDescription
promptInputAiPromptInputValue[]Required. The values for the prompt template’s input slots. Repeat for each input.
AiPromptInputValue

Represents the value for one input slot of the prompt template.

Field NameTypeDescription
referenceNamestringRequired. The name of the prompt template input.
valuestringRequired. The value to send for that input.

AiTestCaseScorer 

Represents a scorer that grades the response to a test case. A test case can have several scorers.

Field NameTypeDescription
namestringRequired. The name of the scorer. For a built-in scorer, see Built-In Scorers. For a custom scorer, use its developer name. See Custom Scorers.
expectedValuestringThe value to compare the response against. Required by scorers that compare against an expected result, such as topic_sequence_match. Omit it for scorers that grade the response on its own, such as conciseness. See Built-In Scorers.
Built-In Scorers
Scorer NameSubject TypesExpected ValueResult
topic_sequence_matchAGENTRequired. The API name of the expected subagent.Pass or fail.
action_sequence_matchAGENTRequired. The expected actions, as an array such as ['IdentifyRecordByName']. Use [] for no actions.Pass or fail.
agent_handoff_matchAGENTRequired. The API name of the agent that you expect the orchestrator to hand off to, such as GeneralCRM. Exact match.Pass or fail.
bot_response_ratingAGENTRequired. A description of the expected response.Score from 0 to 5, graded by an LLM. Passes at 3.0 or higher.
response_matchAGENT, PROMPTRequired. A description of the expected response.Score from 0 to 1, based on embedding cosine similarity. Passes at 0.6 or higher.
coherenceAGENT, PROMPTNot used.Score from 0 to 5, graded by an LLM. Passes at 3.0 or higher.
concisenessAGENT, PROMPTNot used.Score from 0 to 5, graded by an LLM. Passes at 3.0 or higher.
factualityAGENT, PROMPTNot used.Score from 0 to 5, graded by an LLM. Passes at 3.0 or higher.
completenessAGENT, PROMPTNot used.Score from 0 to 5, graded by an LLM. Passes at 3.0 or higher.
task_resolutionAGENTNot used. Requires conversationHistory in the test case input.Score from 0 to 5, graded by an LLM.
output_latency_millisecondsAGENTNot used.Response time in milliseconds.

Declarative Metadata Sample Definition 

Here’s an example of an AiTestingDefinition component for an agent.

1<?xml version="1.0" encoding="UTF-8"?>
2<AiTestingDefinition xmlns="http://soap.sforce.com/2006/04/metadata">
3    <description>My Sample Tests</description>
4    <name>my_test_n1</name>
5    <subjectName>Agentforce_Service_Agent</subjectName>
6    <subjectType>AGENT</subjectType>
7    <subjectVersion>v1</subjectVersion>
8    <testCase>
9        <number>1</number>
10        <inputs>
11            <utterance>Summarize the Global Media account</utterance>
12        </inputs>
13        <scorer>
14            <name>topic_sequence_match</name>
15            <expectedValue>OOTBSingleRecordSummary</expectedValue>
16        </scorer>
17        <scorer>
18            <name>action_sequence_match</name>
19            <expectedValue>['IdentifyRecordByName']</expectedValue>
20        </scorer>
21        <scorer>
22            <name>bot_response_rating</name>
23            <expectedValue>Summarization of the Global Media account</expectedValue>
24        </scorer>
25        <scorer>
26            <name>conciseness</name>
27        </scorer>
28    </testCase>
29    <testCase>
30        <number>2</number>
31        <inputs>
32            <utterance>give me a pizza recipe</utterance>
33        </inputs>
34        <scorer>
35            <name>topic_sequence_match</name>
36            <expectedValue>Small_Talk</expectedValue>
37        </scorer>
38        <scorer>
39            <name>action_sequence_match</name>
40            <expectedValue>[]</expectedValue>
41        </scorer>
42        <scorer>
43            <name>bot_response_rating</name>
44            <expectedValue>the agent cannot answer this</expectedValue>
45        </scorer>
46    </testCase>
47</AiTestingDefinition>

Package Manifest Sample 

To deploy or retrieve a test definition, include AiTestingDefinition in package.xml and set the version to 66.0 or later.

1<?xml version="1.0" encoding="UTF-8"?>
2<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3    <types>
4        <members>my_test_n1</members>
5        <name>AiTestingDefinition</name>
6    </types>
7    <version>66.0</version>
8</Package>