Salesfroce AgentScript
AgentScript is to think of it as a combination of:
Prompt Engineering
+
Flow Decision Logic
+
Invocable Apex Actions
+
Variables and State Management
Let's learn it by building a simple agent.
Basic Structure of AgentScript
An AgentScript file typically contains:
system
variables
actions
agent definition
reasoning instructions1. System Instructions
This defines who the agent is.
system:
instructions: >
You are a customer support assistant.
Be polite and concise.Equivalent to:
"You are ChatGPT..."in prompt engineering.
2. Variables
Variables maintain state during the conversation.
variables:
customer_verified: mutable boolean = false
case_number: mutable string = ""
customer_type: mutable string = ""Think of this as:
Boolean customerVerified = false;
String caseNumber;
3. Actions
Actions are Salesforce operations.
Example:
actions:
verifyCustomer
getOpenCases
createCaseThese actions can map to:
Flow
Invocable Apex
External Services
Prompt Templates
4. Define the Agent
Example:
start_agent support_agent:This is like:
public class SupportAgent
5. Reasoning Block
This tells the LLM how to behave.
reasoning:
instructions: >
Help customers resolve issues.
Verify identity before exposing data.
Example 1: Leave Request Agent
Imagine HR wants an AI assistant.
system:
instructions: >
You are an HR assistant.
variables:
employee_verified: mutable boolean = false
actions:
verifyEmployee
getLeaveBalance
submitLeaveRequest
start_agent leave_assistant:
reasoning:
instructions: >
First verify the employee.
If verified:
Show leave balance.
Offer leave submission.
Otherwise:
Ask for employee ID.
Example Conversation
User:
I want to apply leave.
Agent:
Please provide Employee ID.
User:
12345
Agent:
Calling verifyEmployee()
Employee verified.
You have 12 leave days remaining.
Would you like to submit a leave request?
Example 2: Salesforce Case Agent
Suppose Service Cloud wants an AI assistant.
system:
instructions: >
Help customers manage support cases.
variables:
authenticated: mutable boolean = false
actions:
authenticateCustomer
fetchCases
createCase
start_agent case_agent:
reasoning:
instructions: >
Always authenticate first.
After authentication:
If customer asks for existing cases:
Run fetchCases.
If customer reports a problem:
Run createCase.
Example 3: Sitetracker Scenario (for you)
Since you work on Sitetracker projects:
system:
instructions: >
Assist users with certification compliance.
variables:
certification_valid: mutable boolean = false
actions:
checkCertification
uploadCertification
generateComplianceReport
start_agent certification_agent:
reasoning:
instructions: >
Check whether certification exists.
If expired:
Ask user to upload a new document.
Otherwise:
Generate compliance summary.
How Actions Work
Suppose you have Apex:
public class LeaveService {
@InvocableMethod
public static List<Result> getBalance(
List<Request> requests
) {
// logic
return results;
}
}Agentforce exposes it as an action.
AgentScript can invoke:
@getBalancewithout worrying about Apex details.
AgentScript vs Apex
Apex AgentScript Variables Variables Methods Actions if/else Reasoning instructions Trigger context Conversation context Invocable Methods Agent Actions
Mental Model
Think of AgentScript as:
Agent =
System Prompt
+
Conversation Memory
+
Salesforce Actions
+
Reasoning Rules
How to Learn AgentScript
Day 1
Write simple agents:
Hello Agent
FAQ Agent
HR Agent
Day 2
Add variables:
Verification Status
Customer Tier
Case Number
Day 3
Connect Salesforce actions:
Flow
Invocable Apex
External Services
Day 4
Build real scenarios:
Case Management Agent
Leave Management Agent
Sitetracker Certification Agent
What an Architect Should Focus On
As an aspiring Salesforce Architect, you don't need to memorize syntax immediately.
Instead, understand:
When should the agent call Apex?
When should it call Flow?
What data can it access?
How do we secure it?
How do we prevent hallucinations?
How do we audit decisions?Those design decisions are what organizations will pay for.
A complete beginner AgentScript example
system:
instructions: >
You are a helpful support assistant.
variables:
verified: mutable boolean = false
actions:
verifyCustomer
createCase
start_agent support_agent:
reasoning:
instructions: >
Verify the customer first.
If verified:
Help them create a case.
Otherwise:
Ask for verification details.
Comments
Post a Comment