本文是《Programmatic Instructions in Agentforce | 用变量、条件逻辑与动作过滤打造确定性 Agent》的练习操作步骤。阅读原文请见:Programmatic Instructions in Agentforce | 用变量、条件逻辑与动作过滤打造确定性 Agent。
1. Update the Get Customer Details Flow
- From Setup, search for and select Flows, then open the Get Customer Details flow.
- Click Deactivate to enable editing.
- Double-click the Get Contact by Email and Member Number element.
- Click Add Field and select Lifetime_Value__c.
- Click Save as New Version, Save, then Activate.
2. Grant the Agent User Permissions to Lifetime_Value__c
- From Setup, search for and select Users, then click EinsteinServiceAgent User.
- Select Permission Set Assignments, then Service Agent Permissions → Object Settings.
- Select Contacts, click Edit, grant read access to Lifetime_Value__c, then Save.
3. Create the LifetimeValue Variable
- Open the App Launcher and select Agentforce Studio, then CC Service Agent.
- Click New Version.
- Expand Variables, click New, then Create Custom Variable.
- Name/API Name:
LifetimeValue; Data Type Number; DescriptionThe value of Lifetime_Value__c from the Contact record.; Default value0. - Click Create.
4. Populate the Variable
- Select the Experience Management subagent and switch to Script view.
- Find
Get_Customer_Details: @actions.Get_Customer_Details. - After the
memberNumber = ...line, paste:set @variables.LifetimeValue = @outputs.contact.data.Lifetime_Value__c(matching indentation). - Click Save and switch back to Canvas view.
5. Help the Agent Find the Right Subagent
- Select the Agent Router subagent and switch to Script view.
- After the "Select the best tool to call..." line, paste:
If the customer is providing their email and membership number, run {!@actions.go_to_Experience_Management}.
- Switch back to Canvas view.
6. Conditionally Define the Prompt
- In Canvas view, select Experience Management.
- Place the cursor after
before running any other actionsand press Enter. - Type
/, select If/Else (Conditional). - Select variable LifetimeValue, greater than or equal to, value
50000. - Add instruction
Thank the customer for being a Platinum member!. - Repeat for
LifetimeValue < 50000 and >= 25000withThank the customer for being a Gold member!. - Click Save.
7. Test Your Conditional Logic
- Click Preview and enter
Can you let me know more about the full moon beach party experience? - Enter
I am sofiarodriguez@example.com and my membership number is 10008155.(Platinum). - Reset and try
ilsagalgey@example.com/10002212andterianncreer@example.com/10003172. - Click the Variables tab to see the LifetimeValue value.
8. Create the IssueResortCredit Action
- In the Explorer panel, click the + next to Experience Management, then + New Action.
- Name
IssueResortCredit; DescriptionIssue resort credit using the ContactId and provided amount.; Create and Open. - Reference Action Type Flow, Reference Action Issue Resort Credit.
- amount and contactId inputs: Require Input; creditID output: Show in conversation; Save.
9. Grant Permissions to Credit__c
- From Setup, search for and select Users, then EinsteinServiceAgent User → Permission Set Assignments.
- Select Service Agent Permissions → Object Settings, select Credits, click Edit.
- Enable Read and Create object permissions; grant edit access to Amount and Contact fields; Save.
10. Issue Loyalty-Specific Credit Amounts
- In Agentforce Builder, open Experience Management and expand If LifetimeValue >= 50000.
- After
Thank the customer for being a Platinum member!, add:If the action+@→ IssueResortCredit +is available, issue the customer a $500 resort credit. Tell them about the resort credit! - Repeat for Gold members ($250 credit), then Save.
11. Test Your Resort Credit Action
- In Preview, enter the beach party prompt and
sofiarodriguez@example.com/10008155. - Confirm the Platinum $500 credit message.
- Open Contacts → Sofia Rodriguez → Related tab → Credits to verify the $500 credit.
12. Create the isCreditIssued Variable
- Click Variables, then New → Create Custom Variable.
- Name/API Name
isCreditIssued; Data Type Boolean; DescriptionWhether the customer has already been issued a resort credit this session.; Default False; Create.
13. Add Action Filtering
- In Experience Management, expand the IssueResortCredit action and click Add filter.
- Set Available when isCreditIssued == False.
- Click And, then add
LifetimeValue >= 25000. - Add a Follow-up action → Set a variable → isCreditIssued = True.
- Click Save.