Sub topic 1
How Agentforce limits what an agent can do
An Agentforce agent can read records, call actions, and write replies. Each of those abilities is limited by a separate control. This chapter maps those controls and shows which ones the platform enforces and which ones only guide the model. The remaining chapters cover each control in detail.
Prerequisites
This chapter assumes you have:
- Basic Salesforce administration skills: users, profiles, and permission sets.
- Familiarity with objects, fields, and record sharing.
- Awareness of what an Agentforce agent is, and what topics and actions are.
- Some ability to read Flow or Apex. This helps in the action sections but is not required here.
The core idea: an agent is a set of limits, not a free actor
An agent is not a super-user. It acts through a user identity, sees topics you define, and calls only actions you attach. Every request passes through several layers, and each layer removes some options.
The layers fall into two groups:
- Hard limits are enforced by the platform. The model cannot talk its way around them. Examples are object permissions, field-level security, sharing, and Apex user mode.
- Soft limits shape what the model chooses to do. Examples are topic descriptions and instructions. They work well in most cases, but a model can misread or ignore them, so they must never be your only defense.
A good design puts anything that must never happen behind a hard limit. It uses soft limits to make normal behavior predictable and helpful.
The layers at a glance
| Layer | What it controls | Hard or soft | Covered in |
|---|---|---|---|
| Run-as identity | Which user's access the agent inherits | Hard | Chapters on agent types and the agent user |
| Permission sets and least privilege | Which objects, fields, and features that user can use | Hard | Chapters on least privilege and permission sets |
| Sharing and field-level security | Which records and fields are visible | Hard | Chapter on record access |
| Topics | Which kinds of requests the agent handles | Soft | Chapter on topics |
| Instructions | How the agent behaves inside a topic | Soft | Chapter on instructions |
| Actions | What the agent can do, and with what inputs | Hard if built correctly | Chapters on action design and Apex user mode |
| Einstein Trust Layer | How prompts and responses are protected | Hard, platform-managed | Chapter on the Trust Layer |
| Escalation | When a human takes over | Mixed | Chapter on escalation |
| Testing and review | Whether the limits hold in practice | Verification | Chapter on testing |
The "hard if built correctly" label on actions matters. An action is only as safe as the code or flow behind it. An Apex action that runs in system mode can return data the agent user has no right to see, even when the permission sets are perfect.
How a request moves through the layers
Follow one customer message through a service agent.
- The message arrives and the agent picks a topic that matches it. If nothing matches, the agent should decline or escalate.
- Inside the topic, instructions guide the agent's reasoning and wording.
- The agent decides to call an action, such as "Get Order Status".
- The action runs as the agent's run-as user. Object permissions, field-level security, and sharing apply to any data it touches.
- The result returns to the model, and the Trust Layer processes the prompts and responses around the model call.
- The agent replies, or hands the conversation to a human.
Step 4 is the one that matters most for security. The topic and instructions decide whether the agent tries to look something up. The permission model decides whether the lookup succeeds.
Who the agent runs as
The first design decision is the identity the agent uses. There are two patterns.
- A dedicated agent user. Customer-facing service agents typically run as a specific user that you create and configure for the agent. Every customer who chats with the agent gets the same data access, which is the agent user's access. You control that access with permission sets.
- The logged-in user. Agents built to help employees inside Salesforce run in the context of the person using them. Two employees with different permissions can get different results from the same agent.
The two patterns carry different risks:
- With a dedicated agent user, a customer is not a Salesforce user. The agent user's access is the ceiling for everything the customer can reach through the agent. If you grant too much, any customer might see it by asking the right question.
- With the logged-in user, the agent cannot exceed what that person could already do. The risk shifts to actions and instructions. They should not let a person do through the agent what they could not do in the normal interface.
The next two chapters cover this in detail, including how to create and assign the agent user.
Least privilege as the default
Least privilege means the agent user gets only the access its job needs, and nothing else. For an agent that answers order-status questions, that means read access to orders and the status field. It does not mean edit rights, delete rights, or "View All Data".
Here is a permission set that does this. It gives the agent user read-only access to the Order object and its Status field.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Agent Order Read</label>
<description>Read-only access to orders for the service agent user</description>
<hasActivationRequired>false</hasActivationRequired>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Order</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Order.Status</field>
<readable>true</readable>
</fieldPermissions>
</PermissionSet>Three details are worth noting:
- Every create, edit, delete, and view-all flag is explicitly
false. Writing them out makes a review easier, because a reader can see that each was a deliberate choice. - Only
Order.Statusis readable. Fields not listed are not readable through this permission set. A field the agent needs but you forgot to list is a common cause of "the agent says it cannot find the order". - The permission set is the ceiling. Even if an instruction says "show the customer's billing address", the agent cannot return a field its user cannot read.
Soft limits: topics and instructions
Topics divide the agent's job into areas. Each topic has a description that helps the agent decide when it applies, a set of instructions, and the actions available in it. A topic that does not include an action makes that action unavailable in that context, which is a useful way to narrow the agent.
Instructions are short natural-language rules. Specific rules work better than vague ones. For example:
Only answer questions about the status of the customer's own orders.
Never share information about other customers.
Never offer refunds, price changes, or account changes. If the customer asks for one, tell them you are transferring them to a human agent.
If you cannot find the order, say so and ask the customer to confirm the order number.These rules say what is in scope, what is forbidden, and what to do at the edge. They are guidance for a language model, not code. Treat them as a way to produce good behavior, and rely on the permission model to prevent bad outcomes.
Actions: where the agent touches data
Actions are the only way an agent reads or changes Salesforce data. That makes them the most important place to apply hard limits. A narrow action, such as "Get Order Status" with a single input, is safer than a general one, such as "Run a query" or "Update any record".
Actions built with Apex or Flow need extra care, because code can read data in ways the user's permissions would not allow. The with sharing keyword and WITH USER_MODE in SOQL make the query respect the running user's object permissions, field-level security, and sharing:
public with sharing class OrderStatusAction {
public class Request {
@InvocableVariable(required=true label='Order Number')
public String orderNumber;
}
public class Result {
@InvocableVariable(label='Order Status')
public String status;
}
@InvocableMethod(label='Get Order Status' description='Returns the status of an order the running user can access')
public static List<Result> getStatus(List<Request> requests) {
Set<String> numbers = new Set<String>();
for (Request r : requests) {
numbers.add(r.orderNumber);
}
Map<String, String> statusByNumber = new Map<String, String>();
for (Order o : [
SELECT OrderNumber, Status
FROM Order
WHERE OrderNumber IN :numbers
WITH USER_MODE
]) {
statusByNumber.put(o.OrderNumber, o.Status);
}
List<Result> results = new List<Result>();
for (Request r : requests) {
Result res = new Result();
res.status = statusByNumber.get(r.orderNumber);
results.add(res);
}
return results;
}
}When the agent user cannot see an order, the map has no entry and status comes back empty. The instruction "If you cannot find the order, say so" then gives the agent a safe thing to do with that empty result. This pairing of a hard limit in the query with a soft limit in the instructions is the pattern to repeat throughout your design.
Trust Layer, escalation, and testing
Three further controls complete the picture:
- The Einstein Trust Layer is a set of platform protections around calls to the language model. It covers things like masking sensitive data in prompts and screening for harmful content. You do not build it, but you need to know what it covers and what it does not. It does not replace permission sets.
- Escalation hands the conversation to a human when the agent should not or cannot continue. It is the safe exit for refunds, account changes, and anything outside the topics.
- Testing and review is how you confirm the other layers work. You test with requests designed to break the limits, such as asking for another customer's order, and you review what the agent actually did afterward.
Common errors at the design stage
- Relying on instructions alone. "Never share other customers' data" in a prompt is not a control if the agent user can read all orders.
- Over-permissive agent users. Starting with a broad profile and trying to restrict through prompts reverses the correct order. Start narrow and add.
- System-mode actions. An Apex action without
with sharingand user-mode queries can return anything the code can reach. - Broad, generic actions. An action that accepts a free-form query or object name gives the model more power than any task needs.
- No exit path. An agent with no escalation route will improvise when it meets a request outside its scope.
- Testing only the happy path. If you never try forbidden requests, you do not know whether the limits hold.
Exercise
A service agent has the instruction "Never share information about other customers." Its agent user has the "View All Data" permission, and its Apex action queries orders without WITH USER_MODE. Which of these controls is a hard limit, and what would you change first?
Show answer
The instruction is a soft limit, because it only guides the model. Nothing in this setup is a hard limit against reading other customers' data. Change the agent user first: remove "View All Data" and grant a permission set with only the needed read access, such as read on Order and the Status field. Then update the Apex action to use with sharing and WITH USER_MODE, so the query respects the agent user's permissions and sharing. Keep the instruction as a helpful extra layer.
Exercise
Why does the run-as choice (dedicated agent user versus logged-in user) change where the main risk sits?
Show answer
With a dedicated agent user, every customer gets that one user's access, so excess permissions on that user are exposed to every customer. With the logged-in user, the agent cannot exceed that person's access, so the risk moves to actions and instructions that might let them do through the agent what the normal interface would block.