Sub topic 2
Agent types and who the agent runs as
An Agentforce agent never acts as "the AI". Every query it runs and every record it changes happens as some Salesforce user. This chapter covers how the agent type determines that user, and what follows from it for data access, auditing, and risk.
This chapter assumes you can do the following:
- Read a user's permissions in Setup (profile, permission sets, sharing).
- Describe what an Agentforce topic and an action are.
- Read a short SOQL query.
Later chapters cover building the permission set and the sharing model in detail. Here you only need to learn which identity is in play.
Why "who does it run as" is the first question
Salesforce enforces access through users. Object permissions, field-level security, and record sharing all attach to a user. The platform has no separate "agent permission model" for those checks. An agent can read an Order only if the user it runs as can read that Order.
This gives you one rule that the rest of the tutorial builds on:
An agent's data access is the data access of its run-as user. Guardrails like topics and instructions narrow what the agent tries to do. They do not widen what it is allowed to do.
So before you write a single instruction, find out who your agent runs as.
The two run-as models
Agentforce agents use one of two identity models.
| Model | Typical agent type | Who the agent runs as | Typical audience |
|---|---|---|---|
| Dedicated agent user | Service agent | A specific user record you select for the agent | Customers, prospects, and other external or unauthenticated people |
| Logged-in user | Employee agent | The employee who is chatting with the agent | Internal staff working in Salesforce, Slack, or similar |
Agent type names and the exact Setup labels change between releases. Check the agent type options in Agentforce Builder in your org. The identity model is the stable idea: some agents carry their own identity, and others borrow the identity of the person using them.
Dedicated agent user (service agents)
A service agent talks to people who usually are not Salesforce users. A customer on your website chat has no Salesforce login. The agent still has to query orders and cases, so it needs an identity.
You give it one. When you set up a service agent, you pick an agent user. Salesforce provides a user license and a profile built for this purpose, typically named "Einstein Agent User". The agent runs every action as that user, no matter who is on the other end of the conversation.
Consequences:
- One identity for all conversations. Customer A and Customer B both talk to an agent with the same permissions. The platform does not narrow access per customer. If the agent user can see all orders, the agent can query all orders. Keeping the agent from returning Customer B's order to Customer A is the job of your action design and instructions, covered in later chapters.
- You control the ceiling. The agent user's permission sets are the maximum the agent can do. You can make them as small as you like.
- Audit trails point to one user. Records the agent creates or edits show the agent user as creator or last modifier. This is useful for reporting: you can filter on that user to see what the agent changed.
- Access is decoupled from your customers. You do not manage Salesforce licenses for each customer who chats with the agent.
Logged-in user (employee agents)
An employee agent works inside your company for people who already have Salesforce users. It runs as whoever opened it.
Consequences:
- Access follows the person. A sales rep sees the opportunities the rep can see. A manager with a wider role in the hierarchy sees more. The same agent gives different answers to different users, because sharing and field-level security are evaluated per person.
- No separate agent user to maintain. You do not create or configure a dedicated identity for the agent.
- Over-sharing risk moves. If an employee has more access than they need, the agent exposes that access in a convenient chat form. The agent makes existing over-permissioning easier to use.
- Audit trails point to the person. Changes the agent makes appear as changes by that employee.
Comparing the two models side by side
placeholderThe diagram below is the real one. Read it from the top: the agent type decides which identity runs the actions, and the identity decides what the data layer allows.
Finding which user an agent runs as
For a service agent, open the agent in Agentforce Builder and look at its settings for the selected agent user. Note the username, then open that user in Setup. Look at three things:
- The profile and license.
- The assigned permission sets and permission set groups.
- Any other assignments that grant access indirectly, such as public group or queue membership, which can affect sharing.
You can also list the users that use the agent profile with a query:
SELECT Id, Name, Username, Profile.Name, IsActive
FROM User
WHERE Profile.Name = 'Einstein Agent User'This helps in an org that has several agents. Each agent user should have a clear name, such as "Order Service Agent", so an auditor can tell which agent it represents.
Choosing between the models
You rarely choose freely. The audience usually decides it:
- If people outside your company, or people without Salesforce logins, talk to the agent, you need a dedicated agent user.
- If your own employees talk to the agent and should see only what they normally see, run it as the logged-in user.
Where you do have a choice, weigh these points:
| Question | Dedicated agent user | Logged-in user |
|---|---|---|
| Can you set a tight, uniform ceiling? | Yes, through the agent user's permission sets | No, ceiling varies by employee |
| Does per-person record sharing apply? | No, sharing is evaluated for the agent user | Yes |
| Is an extra user to review and maintain? | Yes | No |
| Does one over-broad permission affect everyone? | Yes, every conversation | Only users who hold it |
Common mistakes
Cloning an admin or an existing user as the agent user. It is quick, and it hands the agent every permission that user holds. Start from the agent profile and add only what the agent's actions need.
Granting "View All Data" or "Modify All Data" to make a failing test pass. If an action fails with an access error, that is the model working. Work out which specific object or field the action needs and grant exactly that.
Assuming sharing narrows access per customer. A service agent user has one set of access for every conversation. If an action looks up an order by number, the agent user's access decides which orders can be found. Nothing in the run-as model checks that the order belongs to the person chatting. Your action must check that, for example by requiring a verified identifier.
Treating instructions as a permission boundary. An instruction that says "never share other customers' data" is guidance to a language model. A permission set is enforced by the platform. Use both, and rely on the second for anything that matters.
Forgetting that Apex actions can ignore the run-as user. An invocable Apex class that runs in system mode, for example because it uses without sharing or an unrestricted query, can read data the run-as user could not. Chapter 10 covers this.
Not updating the agent user when actions change. When you add an action that reads a new object, the agent user needs access to it. When you remove the action, remove the access. Leftover permissions are unused attack surface.
What this means for the rest of the design
Everything later in this tutorial layers on top of the identity decision:
- The agent user's permission sets set the hard ceiling of access.
- Sharing and field-level security further limit what that user sees.
- Topics, instructions, and actions limit what the agent attempts.
- The Einstein Trust Layer protects the data sent to and from the language model.
The first layer decides how much the rest has to compensate for. A tightly scoped agent user means a mistake in an instruction costs little. A broad one means every other layer carries the full weight.
Exercise
A company launches a website chat agent for customers, and an internal agent that helps sales reps summarize their opportunities. For each agent, say which run-as model fits, and explain why a rep's view of opportunities would differ from a customer's view of orders in how access is enforced.
Show answer
The website agent should be a service agent that runs as a dedicated agent user, because customers have no Salesforce logins. Its access is the same for every conversation, so the ceiling is set by the agent user's permission sets, and checking that an order belongs to the chatting customer must be done by the action design. The internal agent should be an employee agent that runs as the logged-in user. Each rep's sharing and field-level security are evaluated, so each rep sees only the opportunities that rep could already see.
Exercise
A service agent action fails because the agent user cannot read the Shipment object. A teammate proposes assigning the agent user a profile with Modify All Data. What should you do instead, and why?
Show answer
Add a permission set that grants read access to the Shipment object and only the fields the action needs, then assign it to the agent user. Modify All Data bypasses object permissions, field-level security, and sharing for every conversation and for every action, which removes the ceiling that the agent user is supposed to provide.