Programmatic Instructions in Agentforce | 用变量、条件逻辑与动作过滤打造确定性 Agent(练习操作步骤)

《Programmatic Instructions in Agentforce | 用变量、条件逻辑与动作过滤打造确定性 Agent》的分步练习操作指南。...

📅 2026/10/2 ✍️ ponybai 🏷️ agentforce, salesforce, ai

本文是《Programmatic Instructions in Agentforce | 用变量、条件逻辑与动作过滤打造确定性 Agent》的练习操作步骤。阅读原文请见:Programmatic Instructions in Agentforce | 用变量、条件逻辑与动作过滤打造确定性 Agent。

1. Update the Get Customer Details Flow

  1. From Setup, search for and select Flows, then open the Get Customer Details flow.
  2. Click Deactivate to enable editing.
  3. Double-click the Get Contact by Email and Member Number element.
  4. Click Add Field and select Lifetime_Value__c.
  5. Click Save as New Version, Save, then Activate.

2. Grant the Agent User Permissions to Lifetime_Value__c

  1. From Setup, search for and select Users, then click EinsteinServiceAgent User.
  2. Select Permission Set Assignments, then Service Agent Permissions → Object Settings.
  3. Select Contacts, click Edit, grant read access to Lifetime_Value__c, then Save.

3. Create the LifetimeValue Variable

  1. Open the App Launcher and select Agentforce Studio, then CC Service Agent.
  2. Click New Version.
  3. Expand Variables, click New, then Create Custom Variable.
  4. Name/API Name: LifetimeValue; Data Type Number; Description The value of Lifetime_Value__c from the Contact record.; Default value 0.
  5. Click Create.

4. Populate the Variable

  1. Select the Experience Management subagent and switch to Script view.
  2. Find Get_Customer_Details: @actions.Get_Customer_Details.
  3. After the memberNumber = ... line, paste: set @variables.LifetimeValue = @outputs.contact.data.Lifetime_Value__c (matching indentation).
  4. Click Save and switch back to Canvas view.

5. Help the Agent Find the Right Subagent

  1. Select the Agent Router subagent and switch to Script view.
  2. 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}.

  1. Switch back to Canvas view.

6. Conditionally Define the Prompt

  1. In Canvas view, select Experience Management.
  2. Place the cursor after before running any other actions and press Enter.
  3. Type /, select If/Else (Conditional).
  4. Select variable LifetimeValue, greater than or equal to, value 50000.
  5. Add instruction Thank the customer for being a Platinum member!.
  6. Repeat for LifetimeValue < 50000 and >= 25000 with Thank the customer for being a Gold member!.
  7. Click Save.

7. Test Your Conditional Logic

  1. Click Preview and enter Can you let me know more about the full moon beach party experience?
  2. Enter I am sofiarodriguez@example.com and my membership number is 10008155. (Platinum).
  3. Reset and try ilsagalgey@example.com / 10002212 and terianncreer@example.com / 10003172.
  4. Click the Variables tab to see the LifetimeValue value.

8. Create the IssueResortCredit Action

  1. In the Explorer panel, click the + next to Experience Management, then + New Action.
  2. Name IssueResortCredit; Description Issue resort credit using the ContactId and provided amount.; Create and Open.
  3. Reference Action Type Flow, Reference Action Issue Resort Credit.
  4. amount and contactId inputs: Require Input; creditID output: Show in conversation; Save.

9. Grant Permissions to Credit__c

  1. From Setup, search for and select Users, then EinsteinServiceAgent User → Permission Set Assignments.
  2. Select Service Agent Permissions → Object Settings, select Credits, click Edit.
  3. Enable Read and Create object permissions; grant edit access to Amount and Contact fields; Save.

10. Issue Loyalty-Specific Credit Amounts

  1. In Agentforce Builder, open Experience Management and expand If LifetimeValue >= 50000.
  2. 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!
  3. Repeat for Gold members ($250 credit), then Save.

11. Test Your Resort Credit Action

  1. In Preview, enter the beach party prompt and sofiarodriguez@example.com / 10008155.
  2. Confirm the Platinum $500 credit message.
  3. Open Contacts → Sofia Rodriguez → Related tab → Credits to verify the $500 credit.

12. Create the isCreditIssued Variable

  1. Click Variables, then New → Create Custom Variable.
  2. Name/API Name isCreditIssued; Data Type Boolean; Description Whether the customer has already been issued a resort credit this session.; Default False; Create.

13. Add Action Filtering

  1. In Experience Management, expand the IssueResortCredit action and click Add filter.
  2. Set Available when isCreditIssued == False.
  3. Click And, then add LifetimeValue >= 25000.
  4. Add a Follow-up action → Set a variable → isCreditIssued = True.
  5. Click Save.