本文是《Build an Agent Using Agentforce DX - 使用 Agentforce DX 构建代理》的练习操作步骤。阅读原文请见:Build an Agent Using Agentforce DX - 使用 Agentforce DX 构建代理。
1. Sign Up for a Developer Edition Org
- Sign up for a free [Developer Edition org with Agentforce](https://trailhead.salesforce.com/promo/orgs/agentforce-for-trailhead).
- Click Sign me up, open the activation email, and click Verify Account.
- Connect the org to Trailhead: click the hands-on org, Connect Org, sign in, Allow, then Yes! Save it.
2. Activate Agentforce in Your Org
- Log in and click the Setup gear icon, then Setup.
- Enter
Einstein Setupin Quick Find, select Einstein Setup, and ensure the Turn on Einstein toggle is On. - Enter
Einstein Botsin Quick Find, select Einstein Bots, and toggle to On. - Enter
Salesforce Goin Quick Find, select Salesforce Go. - In Search features, enter
Agentforceand select Agentforce (Default). - Click Get Started, Turn On, then Confirm.
3. Set Up Your Development Environment
- Install [VS Code](https://code.visualstudio.com/).
- Install the [Salesforce Extension Pack](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode) (includes Agentforce DX and Agentforce Vibes).
- Install [Salesforce CLI](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli.htm).
- Install [Node.js](https://nodejs.org/en/download) globally.
4. Clone the Sample Repo
- In VS Code, open View | Command Palette and choose Git: Clone.
- Enter
https://github.com/forcedotcom/afdx-pro-code-testdrive. - Select a destination directory, then click Open.
5. Authorize Your Developer Edition Org
- In VS Code, open View | Command Palette and choose SFDX: Authorize an Org.
- Click Production.
- Enter
agentforcefor the org alias. - Sign in with your Developer Edition credentials, click Allow, and confirm Authentication Successful.
6. Run the Setup Script
- From the VS Code integrated terminal, run the setup script:
./setup(macOS/Linux) orsetup.cmd(Windows). - Save the unique username the script creates (needed in the next unit).
7. Preview the Agent (Simulation)
- In VS Code, right-click the
Local_Info_Agent.agentfile and select AFDX: Preview This Agent. - From the Select agent… dropdown, select Local_Info_Agent.
- Select Simulation, then click Start Simulation.
- In the chat box, enter
What can you help me with?, thenWhat's the weather like?(note the pirate persona).
8. Code the Agent Script File
- Find the line that starts Finally, ALWAYS give answers (around line 114) and remove it.
- Save the file.
- Right-click the Agent Script file and choose AFDX: Validate this Agent.
- Click Restart Options, then Compile & Restart.
- Enter
What's the weather like?again and confirm a professional reply. - Click Stop Simulation.
9. Preview in Live Mode
- In
Local_Info_Agent.agent, locate thedefault_agent_userproperty and set it to the generated username (e.g.,afdx-agent@testdrive.org98eca4a312-3456xyz). - Validate the agent.
- Right-click and select AFDX: Preview This Agent, select Live Test, then Start Live Test.
- Ask
What's the weather like?and confirm the temperature is between 65.3F and 81.1F.
10. Change the Agent in Agentforce Builder
- Deploy the updated bundle:
sf project deploy start --metadata aiAuthoringBundle:Local_Info_Agent. - Open in Builder:
sf org open agent --authoring-bundle Local_Info_Agent. - In Script view, add the clown instruction after the sentence ALWAYS Provide forecasts that include a temperature range.
- Click Save, then optionally Preview.
- Retrieve the updated bundle:
sf project retrieve start --metadata AiAuthoringBundle:Local_Info_Agent.
11. Publish the Authoring Bundle
- Right-click
Local_Info_Agent.agentand choose AFDX: Publish This Agent. - Check the Output tab (filter for Agentforce DX) for the publishing steps.
- Refresh Agentforce Builder in your org and confirm Version 1 (Committed).
12. Activate Your Agent
- In VS Code Explorer, navigate to
force-app/main/default/bots/Local_Info_Agent. - Right-click
Local_Info_Agent.bot-meta.xmland choose AFDX: Activate Agent. - Select Version 1 in the dropdown.
- Refresh Agentforce Builder and confirm Version 1 (Active).