
In this Blog Post, we are going to see how to test Agentforce Agents from VS Code.
Prerequisites:
To effectively develop and test Agentforce Agents, we have to set up our development environment.
- First, install the VS Code from the VS Code website. .
- The next essential step is to install the Salesforce Extension Pack within VS Code. Install the Salesforce Extension Pack directly from the VS Code Marketplace.
- The Agentforce DX VS Code Extension should be installed for developing and testing Agentforce agents. It can be installed via the VS Code Marketplace for standard users or the Open VSX Registry for Code Builder users.
- Install the Salesforce CLI.
- Install and set up VS Code for Salesforce.
- Create a Project and Authorize the Salesforce Development Org.
Steps:
1. Generate a Test Spec File
Agentforce Agents should be exported in your VS Code Salesforce Project Folder. So, use the following package.xml to extract the Agentforce Agents from your Salesforce Org.
package.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>Bot</name>
</types>
<types>
<members>*</members>
<name>GenAiPlanner</name>
</types>
<version>63.0</version>
</Package>
Use the following command to generate the test specification.
sf agent generate test-spec
The command asks for the following information for each test case, prompting you to create one or more test cases:
- Utterance
- Expected topic
- Expected actions
- Expected outcome
2. Customize the generated YAML test spec file
We can customize the auto generated test specification YAML file. We can also set the Context Variables in it.
3. Create the agent test in your development org
To see how the new agent test will appear once deployed to your organization, generate a local AiEvaluationDefinition metadata XML file. This will allow you to preview it before updating your development organization.
Use the following command to preview the agent test. This command generates a XML file.
sf agent test create --preview
Review the generated XML file.
After reviewing the generated XML file for preview, use the following command to create the Agent Test.
sf agent test create
4. Run the agent tests in your development org
Use the following command to run the Agent Test.
sf agent test run --api-name <API Name of the Agent Test>
Replace “<API Name of the Agent Test>” with aiEvaluationDefinitions file name. It should be the API Name of the Agent Test.
5. Check the Agent Test Results
Use the following command to check the Agent Test job status.
sf agent test resume --job-id <Job Id>
Replace <Job Id> with the Id of the Agent Test job.
References: